DATA STRUCTURE
What isData Structure?
A data structure is a way of organizing, managing, and storing data,
either in linear or non-linear arrangements.
Examples
Linear: Array, Linked-List, Stack, Queue
Non-Linear: Trees, Graphs, Hash Tables
3.
ALGORITHM
What is anAlgorithm?
An algorithm is a set of detailed instructions designed to perform a task or solve a
problem, often utilizing data structures to manage and manipulate data efficiently.
Examples
1. Sorting a list of elements (e.g., QuickSort, MergeSort)
2. Searching for a specific element (e.g., Binary Search, Linear Search)
3. Finding the shortest path in a graph (e.g., Dijkstra’s Algorithm)
4. Merging two sorted lists (e.g., Merge Algorithm)
5. Detecting cycles in a graph (e.g., Floyd’s Cycle Detection)
6. Matrix multiplication
7. Finding the greatest common divisor (GCD) of two numbers (e.g., Euclidean Algorithm)
8. Balancing a binary search tree (e.g., AVL Tree Rotation)
9. Compressing data (e.g., Huffman Coding)
10. Dynamic programming algorithms for optimization problems (e.g., Knapsack problem)
11. Topological Sorting
4.
CLASSIFICATION OF DATASTRUCTURE
DATA STRUCTURE
PRIMITIVE NON-PRIMITIVE
INT, FLOAT, STRING
LINEAR NON-LINEAR
STATIC DYNAMIC
ARRAY LINKED-LIST
STACK
QUEUE
TREES
GRAPH
HASH TABLE
5.
ARRAY
What is anArray?
An array is a collection of elements, all of the same data type, stored in a
continuous block of memory. Each element in an array can be accessed directly
using an index.
42 51 84 96 72 22 44 54
0 1 2 3 4 5 6 7
6.
TYPES OF ARRAY
One-DimensionalArray:
A simple list of elements, accessed with a single index.
42 51 84 96 72 22 44 54
0 1 2 3 4 5 6 7
7.
TYPES OF ARRAY
Two-DimensionalArray:
An array of arrays, often visualized as a matrix or table with rows and
columns, accessed with two indices.
1 2 4 5
0 1 2 3
6 9 8 3
8 10 7 11
0
1
2
[1][2]
8.
TYPES OF ARRAY
Multi-DimensionalArray:
An array with more than two dimensions, used to represent more complex
data structures like 3D grids.
1 2 4 5
0 1 2 3
6 9 8 3
8 10 7 11
0
1
2
11 12 14 15
16 19 18 13
18 100 17 111
0
1
2
0 1 2 3
0 1
[0][1][2]
9.
LINKED-LIST
What is alinked-list
A linked-list is a way to organize data in a sequence.
Linked list consists of nodes, where each node contains a piece of data and a reference (or
pointer) to the next node in the sequence.
This allows for dynamic memory allocation, meaning you can easily add or remove elements
without needing to resize an array.
Nodes: Each element in a linked list is called a node.
It typically has two parts: the data and a pointer to the next node.
Head: The first node is called the head.
Tail: The last node points to null, indicating the end of the list.
Dynamic Size: You can easily grow or shrink the list as needed.
10.
TYPES OF LINKED-LIST
SINGLYLINKED-LIST:
An array with more than two dimensions, used to represent more complex
data structures like 3D grids.
7 5800 11 1200
4800
head
4800 5800
18 null
1200
Memory address
Memory address Memory address Memory address
11.
TYPES OF LINKED-LIST
DOUBLYLINKED-LIST:
A doubly linked list is a type of linked list in which each node contains three components:
Data: The value or information stored in the node.
Pointer to the Next Node: A reference to the next node in the sequence.
Pointer to the Previous Node: A reference to the previous node in the sequence.
prev 7 next
null
prev 2 next prev 2 next
head
null
12.
TYPES OF LINKED-LIST
CIRCULARLINKED-LIST:
In Circular Singly Linked List, each node has just one pointer
called the “next” pointer. The next pointer of last node points
back to the first node and this results in forming a circle.
head
7 5800 11 1200 18 null
13.
TYPES OF LINKED-LIST
CIRCULARDOUBLY LINKED-LIST:
In circular doubly linked list, each node has two
pointers prev and next, similar to doubly linked list. The prev pointer
points to the previous node and the next points to the next node.
head
prev 7 next prev 2 next prev 2 next
14.
STACK
What is aStack?
A stack is a data structure that follows the Last In, First Out
(LIFO) principle, meaning the last element added to the stack is
the first one to be removed.
11
20
43
50
Peek
Operations:
1. Push
2. Pop
3. isEmpty
15.
QUEUE
What is aQUEUE?
A queue is a data structure that follows the First In, First Out
(FIFO) principle, meaning the first element added to the queue is
the first one to be removed.
Operations:
1.Enque
2. Dequeue
3 4 5 7
Front
Rear
16.
TREES
What is aTREE?
A tree is a hierarchical data structure that consists of nodes
connected by edges. It is used to represent relationships and
hierarchies, where each node can have zero or more child nodes.
17.
A
B C
D E
F
GH
J K
L
Node: Each element in the tree. A node contains
data and may have child nodes.
Root: The topmost node in the tree. It is the
starting point of the tree.
Parent: A node that has one or more child nodes.
Child: A node that is a descendant of another
node.
Leaf: A node that has no children (the end nodes
of the tree).
Edge: The connection between two nodes
(parent-child relationship).
Subtree: A tree that is part of a larger tree, starting
from a given node downwards.
Height: The length of the longest path from the
root to a leaf.
18.
A
B W
Z E
F
GH
T K
L
BINARY TREE
TRAVERSALS
1. PRE-ORDER
(ROOT->LEFT->RIGHT)
BFS – BREADTH FIRST SEARCH
DFS – DEPTH FIRST SEARCH
2. INORDER
(LEFT->ROOT->RIGHT)
3. POST-ORDER
(LEFT->RIGHT->ROOT)
process of visiting each node in a tree data structure in a specific
order.
19.
GRAPH
Data structure thatconsists of a set of vertices (also called nodes) and a set
of edges (also called arcs) that connect pairs of vertices.
V – VERTICES / NODESE – EDGES / ARCS
A B
C D
E
A B
C D
E
DIRECTED UNDIRECTED