Data Structures and Algorithms Syllabus
Data Structures and Algorithms Syllabus
SYLLABUS
UNIT 1: Data Structures and Algorithms Basics (8 Hours)
Introduction: Basic terminologies, elementary data organizations, data structure operations;
abstract data types (ADT) and their characteristics.
Algorithms: Definition, characteristics, analysis of an algorithm, asymptotic notations, time
and space trade-offs.
Array ADT: Definition, operations and representations – row-major and column- major.
1
20-10-2024
Course Outcomes
2
20-10-2024
Degree = 3
10/20/2024 11 10/20/2024 12
3
20-10-2024
10/20/2024 13
2 A B C D E F
1 0 1 0 1 0
3 B
2 1 0 0 0 1 C A 0 1 0 1 0 0
1 A
3 0 0 0 0 1 B 1 0 1 0 0 0
F
4 4 1 0 0 0 1 C 0 1 0 1 1 0
5 D E
5 0 1 1 1 0 D 1 0 1 0 1 0
E 0 0 1 1 0 0
1 if [v, w] is in E
•Diagonal entries are zero. M(v, w) =
0 otherwise F 0 0 0 0 0 0
•Adjacency matrix of an undirected graph is symmetric.
Space = |V|2
A(i,j) = A(j,i) for all i and j. 10/20/2024 16
4
20-10-2024
Space = |V|2
10/20/2024 17 10/20/2024 18
1 [3] 5
2 aList[1] = (2,4) [4] 5 1
3
4 aList[5] 2 4 3
aList[2] = (1,5) 5
1
aList[3] = (5)
Array Length = n
4 aList[4] = (5,1) # of chain nodes = 2e (undirected graph)
5
aList[5] = (2,4,3) # of chain nodes = e (digraph)
5
20-10-2024
6
20-10-2024
v
(u, v)
v2 v3
u - v2, v3, v4, v2, v1 is a path v1
w - v2, v3, v4, v5 is a path, also it is
u and v are adjacent
v and w are not adjacent a simple path
v4 v5
2024/10/20 25 2024/10/20 26
v2 v5
- v2, v3, v4, v5 , v3, v2 is a cycle v1 v3 v4
- v2, v3, v4, v2 is a cycle, it is also
a simple cycle This is a connected graph because there exists path between every pair of nodes
v4 v5
2024/10/20 27 2024/10/20 28
7
20-10-2024
v4 v5
v6 v2 v7 v8
v9 v1 v3
2024/10/20 29 2024/10/20 30
Subgraph
Complete graph
• A subgraph of a graph G =(V, E) is a graph H = (U, F) such that
• A graph is complete if each pair of distinct nodes has an edge U V and F E.
v2 v2
v1 v3 v3
G H
2024/10/20 31 2024/10/20 32
8
20-10-2024
Hyderabad
Hyderabad
2024/10/20 33 2024/10/20 34
2024/10/20 35 2024/10/20 36
9
20-10-2024
10
20-10-2024
11
20-10-2024
v2 v2
v1 2 v3 v1 2 v3
5 5
4 3 4 3
4 4
8 v5 8 v5
v4 v4
v VS cost[v1] cost[v2] cost[v3] cost[v4] cost[v5] v VS cost[v1] cost[v2] cost[v3] cost[v4] cost[v5]
1 [v1] 0 5 ∞ ∞ ∞ 1 [v1] 0 5 ∞ ∞ ∞
2 v2 [v1, v2] 0 5 ∞ 9 ∞
2024/10/20 45 2024/10/20 46
v2 v2
v1 2 v3 v1 2 v3
5 5
4 3 4 3
4 4
8 v5 8 v5
v4 v4
v VS cost[v1] cost[v2] cost[v3] cost[v4] cost[v5] v VS cost[v1] cost[v2] cost[v3] cost[v4] cost[v5]
1 [v1] 0 5 ∞ ∞ ∞ 1 [v1] 0 5 ∞ ∞ ∞
2 v2 [v1, v2] 0 5 ∞ 9 ∞ 2 v2 [v1, v2] 0 5 ∞ 9 ∞
3 v4 [v1, v2, v4] 0 5 12 9 17 3 v4 [v1, v2, v4] 0 5 12 9 17
4 v3 [v1, v2, v4, v3] 0 5 12 9 16
5 v5 [v1, v2, v4, v3, v5] 0 5 12 9 16
2024/10/20 47 2024/10/20 48
12
20-10-2024
3 3 v5 [v1, v3, v5 ] 0 4 2 ∞ 3 12
4 4 v2 [v1, v3, v5, v2 ] 0 4 2 5 3 12
5 5 v4 [v1, v3, v5, v2, v4 ] 0 4 2 5 3 12
2024/10/20 6 49 2024/10/20 6 v6 [v1, v3, v5, v2, v4 ] 0 4 2 5 3 12 50
13
20-10-2024
14
20-10-2024
Step 3: Minimize the shortest paths between any 2 pairs in the previous operation.
Step 4: For any 2 vertices (i,j), one should actually minimize the distances between
this pair using the first K nodes, so the shortest path will be:
min (dist[i][k] + dist[k][j], dist[i][j]).
dist[i][k] represents the shortest path that only uses the first K vertices, dist[k][j]
represents the shortest path between the pair k,j. As the shortest path will be a
concatenation of the shortest path from i to k, then from k to j.
2024/10/20 57 2024/10/20 58
A 0 6 5 ∞
B 3 0 ∞ 2
C ∞ 4 0 ∞
D ∞ ∞ 7 0
2024/10/20 59 2024/10/20 60
15
20-10-2024
Selecting 1st row and 1st column Selecting 2nd row and 2nd column Selecting 3rd row and 3rd column and Selecting 4th row and 4th column and
and update the matrix and update the matrix update the matrix update the matrix
2024/10/20 61 2024/10/20 62
16
20-10-2024
2024/10/20 65 2024/10/20 66
Prims Algorithm
Kruskals Algorithm Central office
2024/10/20 67 2024/10/20 68
17
20-10-2024
Expensive!
Minimize the total length of wire connecting the customers
2024/10/20 69 2024/10/20 70
Kruskal’s Kruskal’s
Algorithm Algorithm
2024/10/20 71 2024/10/20 72
18
20-10-2024
74
2024/10/20 73 74
2024/10/20
2024/10/20 75 2024/10/20 76
19
20-10-2024
2024/10/20 77 2024/10/20 78
Summary Question?
• Graphs can be used to represent many real-life problems.
• There are numerous important graph algorithms. • A good question deserve a good grade…
• We have studied some basic concepts and algorithms.
• Graph Traversal
• Spanning Tree
• Minimum Spanning Tree
• Shortest Path
2024/10/20 79 2024/10/20 80
20
20-10-2024
81
21