DSA-Module 1-Lecture 1-24-25
DSA-Module 1-Lecture 1-24-25
ANALYSIS
What is Data?
What is Algorithm?
Data structure affects the design of both structural &
functional aspects of a program.
Program=algorithm + Data Structure
You know that a algorithm is a step by step procedure to solve
a particular function.
Introduction to Data Structure
The name "Data Structure" is a combination of two words: "Data" and
"Structure". Let's go over each word individually:
We need data structures because they provide efficient solutions to organizing and
manipulating data. They help to store and retrieve data in an organized manner, making it
easier to manage and analyze the information. Some specific reasons why data structures are
important include:
1. Improved Time Complexity: Using appropriate data structures can lead to better time
complexity, making it possible to solve problems more quickly. For example, searching
for an element in a sorted array is faster than searching for it in an unsorted array.
2. Better Space Complexity: Data structures can help to reduce the amount of memory
needed to store data. For example, using a linked list instead of an array can reduce the
amount of memory needed to store the same data.
3. Efficient Data Retrieval: Data structures make it easier to retrieve specific data
efficiently. For example, a hash table can retrieve data in constant time, while searching
through an unsorted array takes linear time.
4. Better Data Management: Data structures make it easier to manage and manipulate
data. For example, a stack can be used to implement an undo functionality in an
application.
5. Solving Complex Problems: Data structures can provide the foundation for efficient
algorithms, making it possible to solve complex problems in a reasonable amount of
time. For example, graph algorithms can be used to find the shortest path between two
points or to find the minimum spanning tree of a graph.
Characteristics of Data Structure
The following are some of the main advantages of using data structures:
PUSH POP
[STACK]
STACK
The stack can be implemented into two ways:
⚫ Using arrays (Static implementation)
⚫ Using pointer (Dynamic
implementation)
QUEUE
Queue are first in first out type of data structure (i.e. FIFO)
In a queue new elements are added to the queue from one end
called REAR end and the element are always removed from
other end called the FRONT end.
The people standing in a railway reservation row are an
example of queue.
QUEUE
Each new person comes and stands at the end of the row
and person getting their reservation confirmed get out of
the row from the front end.
The bellow show figure how the operations take place on
a stack:
10 20 30 40 50
front rear
QUEUE
The queue can be implemented into two ways:
⚫ Using arrays (Static implementation)
⚫ Using pointer (Dynamic
implementation)
TREES
A tree can be defined as finite set of data items (nodes).
Tree is non-linear type of data structure in which data
items are arranged or stored in a sorted sequence.
Tree represent the hierarchical relationship between
various elements.
TREES
In trees:
There is a special data item at the top of hierarchy called the
Root of the tree.
The remaining data items are partitioned into number of
mutually exclusive subset, each of which is itself, a tree
which is called the sub tree.
The tree always grows in length towards bottom in data
structures, unlike natural trees which grows upwards.
TREES
The tree structure organizes the data into branches,
which related the information.
A root
B C
D E F G
GRAPH
Graph is a mathematical non-linear data structure
capable of representing many kind of physical structures.
It has found application in Geography, Chemistry and
Engineering sciences.
Definition: A graph G(V,E) is a set of vertices V and a set
of edges E.
GRAPH
An edge connects a pair of vertices and many have
weight such as length, cost and another measuring
instrument for according the graph.
Vertices on the graph are shown as point or circles and
edges are drawn as arcs or line segment.
GRAPH
Example of graph:
6
v2 v5
v1 v3
10
v1 8 11
15
9 v2
v3 v4 v4