Professional Documents
Culture Documents
• Implementation − Implementation provides the • Elementary Items − Data items that cannot be
internal representation of a data structure. divided are called as Elementary Items.
Implementation also provides the definition of the
• Attribute and Entity − An entity is that which
algorithms used in the operations of the data
contains certain attributes or properties, which may
structure.
be assigned values.
Characteristics of a Data Structure
• Entity Set − Entities of similar attributes form an
• Correctness − Data structure implementation entity set.
should implement its interface correctly.
• Field − Field is a single elementary unit of
• Time Complexity − Running time or the execution information representing an attribute of an entity.
time of operations of data structure must be as small
• Record − Record is a collection of field values of a
as possible.
given entity.
• Space Complexity − Memory usage of a data
• File − File is a collection of records of the entities in
structure operation should be as little as possible.
a given entity set.
Need For Data Structure
Algorithm
As applications are getting complex and data rich,
Algorithm is a step-by-step procedure, which defines a set of
there are three common problems that applications
instructions to be executed in a certain order to get the desired
face now-a-days.
output. Algorithms are generally created independent of
• Data Search − Consider an inventory of 1 underlying languages, i.e. an algorithm can be implemented
million(106) items of a store. If the application is to in more than one programming language.
search an item, it has to search an item in 1
From the data structure point of view, following are some
million(106) items every time slowing down the
important categories of algorithms −
search. As data grows, search will become slower.
• Search − Algorithm to search an item in a data
• Processor speed − Processor speed although
structure.
being very high, falls limited if the data grows to
billion records. • Sort − Algorithm to sort items in a certain order.
• Multiple requests − As thousands of users can • Insert − Algorithm to insert item in a data structure.
search data simultaneously on a web server, even
the fast server fails while searching the data. • Update − Algorithm to update an existing item in a
data structure.
To solve the above-mentioned problems, data structures
come to rescue. Data can be organized in a data structure in • Delete − Algorithm to delete an existing item from a
such a way that all items may not be required to be searched, data structure.
and the required data can be searched almost instantly
Characteristics of an Algorithm
Execution Time Cases
Not all procedures can be called an algorithm. An algorithm
There are three cases which are usually used to compare should have the following characteristics −
various data structure's execution time in a relative manner.
• Unambiguous − Algorithm should be clear and
• Worst Case − This is the scenario where a particular unambiguous. Each of its steps (or phases), and
data structure operation takes maximum time it can their inputs/outputs should be clear and must lead to
take. If an operation's worst case time is ƒ(n) then only one meaning.
this operation will not take more than ƒ(n) time where
• Input − An algorithm should have 0 or more well-
ƒ(n) represents function of n.
defined inputs.
• Average Case − This is the scenario depicting the
• Output − An algorithm should have 1 or more well-
average execution time of an operation of a data
defined outputs, and should match the desired
structure. If an operation takes ƒ(n) time in execution,
output.
then m operations will take mƒ(n) time.
• Finiteness − Algorithms must terminate after a finite
• Best Case − This is the scenario depicting the least
number of steps.
possible execution time of an operation of a data
• Feasibility − Should be feasible with the available • insertion and removal from a queue
resources. • returning a value from a function
Algorithm Analysis
• A Posterior Analysis − This is an empirical analysis O(n) means that the run time increases at the same pace as
of an algorithm. The selected algorithm is the input.
implemented using programming language. This is
then executed on target computer machine. In this
analysis, actual statistics like running time and space
required, are collected.
Big-O
• math operations
• accessing an array via the index
• accessing a hash via the key
• pushing and popping on a stack
Algorithm Complexity
Example algorithm in programming: Is time complexity the actual time required to execute the
code?
• Binary Search
NO!
Space Complexity
#include <iostream>
int main() {
maxElement = arr[i];
return 0;
}
Pointers: Fundamentals in Data Structures
Pointers
Pointers enable efficient manipulation of data structures like Static Memory allocation
linked lists, trees, and dynamic arrays.
• Allocation of memory at compile-time.
They allow for direct memory access and modification, • Static memory allocation reserves memory for
enhancing performance. variables before the program runs.
Memory Address Ex: declaring and array
Each byte in memory has a unique address. Pointers store Static memory allocation
and manipulate these memory addresses.
Int staticArray[5];
Review:
Node Structure:
Summary
• Linked lists provide a powerful tool for managing data Creating a Node in C++ (singly Linked List)
in dynamic scenarios.
• Understanding their basics is essential for building
more complex data structures and algorithm.
• Singly linked lists store elements using nodes. • Traversal: Traverse the list both forward and
• Nodes contain data and a next pointer. backward.
• Basic operations include traversal, insertion, • Insertion: Add a new node at various positions.
deletion, and searching. • Deletion: Remove a node from the list.
• Trade-offs: Efficient insertions, no random access. • Searching: Find a node with a specific value.
Key Characteristics
Summary
Conclusion