DSA - Introduction To Data Structures
DSA - Introduction To Data Structures
01
Data Structures
Anum Tariq
Data Structures
Organizing Data
Any organization/arrangement for a collection of
records that can be searched, processed in any order, or
modified.
It is a logical way of storing data and it also define
mechanism to retrieve data.
The choice of data structure and algorithm can make
the difference between a program running in a few
seconds or many days.
Need for Data Structures
Data structures organize data more efficient
programs.
More powerful computers more complex
applications.
More complex applications demand more
calculations.
Efficiency
A solution is said to be efficient if it solves the
problem within its resource constraints.
– Space
– Time
8
Data Structures and Algorithms Fall 2017
Linear Data Structures:
9
Data Structures and Algorithms Fall 2017
Non Linear Data Structures:
10
Data Structures and Algorithms Fall 2017
Operations on Data Structures
• Traversing: Accessing each record exactly once so that certain item in
the record may be processed.
• Searching: finding the location of the record with a given key value .
11
Data Structures and Algorithms Fall 2017
1: Arrays
12
Data Structures and Algorithms Fall 2017
Operations performed on arrays
1.Traversing
2.Search
3.Insertion
4.Deletion
5.Sorting
6.Merging
13
Data Structures and Algorithms Fall 2017
Limitations of Arrays
14
Data Structures and Algorithms Fall 2017
2. Linked List
• A Linked list is a linear collection of data elements .It has two part one is
info and other is link part.info part gives information and link part is
address of next node
15
Data Structures and Algorithms Fall 2017
2. Linked List
• A Linked list is a linear collection of data elements .It has two part one is
info and other is link part.info part gives information and link part is
address of next node
16
Data Structures and Algorithms Fall 2017
Advantage of Linked List over Arrays
• Dynamic Size
• Ease of Insertion and Deletion
Drawbacks:
• Random access is not allowed
17
Data Structures and Algorithms Fall 2017
3. Stacks(LIFO)
18
Data Structures and Algorithms Fall 2017
Stack Representation
19
Data Structures and Algorithms Fall 2017
Stack Applications
21
Data Structures and Algorithms Fall 2017
4. Queues(FIFO) Applications
22
Data Structures and Algorithms Fall 2017
5. Trees
• Tree is a hierarchical data structure.
• The very top element of a tree is called the root of the tree.
• Except the root element every element in a tree has a parent
element, and zero or more children elements.
• All elements in the left sub-tree come before the root in sorting
order, and all those in the right sub-tree come after the root.
• Tree is the most useful data structure when you have hierarchical
information to store.
• For example, directory structure of a file system; there are many
variants of tree you will come across. Some of them are Red-black
tree, threaded binary tree, AVL tree, etc.
23
Data Structures and Algorithms Fall 2017
5. Tree’s Applications
• Genealogical tree
– pictures a person's descendants and ancestors
• Game trees
– shows configurations possible in a game such as the Towers of Hanoi
problem
• Parse trees
– used by compiler to check syntax and meaning of expressions such as
2*(3+4)
24
Data Structures and Algorithms Fall 2017
6. Graphs
• Graph is a networked data structure that connects a collection
of nodes called vertices, by connections, called edges.
• An edge can be seen as a path or communication link between
two nodes.
• These edges can be either directed or undirected.
• If a path is directed then you can move in one direction only,
while in an undirected path the movement is possible in both
directions.
25
Data Structures and Algorithms Fall 2017
Arrays
Elementary data structure that exists as built-in in
most programming languages.
y = &x[0];
y = x; // x can appear on the right
// y gets the address of the
// first cell of the x array
Dynamic Arrays
We must free the memory we got using the new
operator once we are done with the y array.
delete[ ] y;