Professional Documents
Culture Documents
Written Exercise - B-Tree, Graphs
Written Exercise - B-Tree, Graphs
Each node has at most 4 pointers and 3 keys, and at least 2 pointers and 1 key.
Insert: 5, 3, 21, 9, 1, 13, 2, 7, 10, 12, 4, 8
Insert values to be
2 inserted in an ascending
fashion
3 5 9 21
3 9 21
if < 5 if > 5
1 3 9 21
5 5
1 3 9 13 21
6 5
1 2 3 9 13 21
7 5
1 2 3 7 9 13 21
split!
8 5 9
if < 5 if > 9
1 2 3 7 13 21
8 5 9
1 2 3 7 10 13 21
8 5 9
1 2 3 7 10 12 13 21
split!
8 5 9 12
if < 5 if > 12
1 2 3 7 10 13 21
8 5 9 12
1 2 3 4 7 10 13 21
split!
8 2 5 9 12
split!
1 3 4 7 10 13 21
8 5
if < 5 if > 5
2 9 12
1 3 4 7 10 13 21
8 5
2 9 12
1 3 4 7 8 10 13 21
8 B-tree Complete 5
2 9 12
1 3 4 7 8 10 13 21
Graphs
1. Construct the following Graph Representation from given Directed Graph above.
Adjacency Matrix
Adjacency List
2. Show the Depth-first and Breadth-first traversal
3. Identify all valid path sequence. Find the shortest path sequence through sum of the weights (costs) of the edges involved in the path.
n=6 0 1 2 3 4 5 Given: B
0 0 10 5 15 0 0 10 10 30
1 0 0 0 0 0 30 0 A 15 D 20 F 5
3
2 0 0 0 10 3 0 5 10 15
3 0 10 0 0 0 20 C 3 E
2 4
4 0 0 0 0 0 15
5 0 0 0 0 0 0
0 A 1 B 10 2 C 5 3 D 15 null
1 B 5 F 30 null
2 C 3 D 10 4 E 3 null
3 D 1 B 10 5 F 20 null
4 E 5 F 15 null
5 F null
2.a Depth-First Traversal
B
1 2
A D F B F
D D D
A C C C C E
Popped: A B F D C E
4
C E
DFS: A B F D C E
Dequeued:
B
4 A
1
A B D C
2
B D C F
A D F
D C F E
C F E
3
F E
C E
E
5
BFS: A B D C F E
3 Paths
B a A → B →F 10 + 30 = 40
10 10 30 b A→D→B→F 15 + 10 + 30 = 55
c A→D→F 15 + 20 = 35
A 15 D 20 F
d A→C→D→B→F 5 + 10 + 10 + 30 = 55
5 10 15
e A→C→D→F 5 + 10 + 20 = 35
C 3 E f A→C→E→F 5 + 3 + 15 = 23