Data Structures & AlgorithmsVery hardGATE CS · Advanced
A weighted undirected graph on A–H has the edges (weights): A–D (16), A–E (22), A–F (26), A–G (5), A–H (4), B–C (9), B–H (23), C–D (13), C–H (25), D–E (3), D–F (7), D–G (19), D–H (15), F–H (20). All weights are distinct. Let P be the weight of the 4th edge added by Prim's algorithm started at A, and K the weight of the 4th edge accepted by Kruskal's algorithm (edges examined in increasing order of weight). What is P - K?
- A. 4
- B. 3
- C. -2
- D. -4
Correct answer: D. -4
Prim's order of additions (4,5,15,3,7,13,9) depends on the growing tree, while Kruskal's accepted edges (3,4,5,7,9,13,15) follow the global sorted order; the 4th are 3 and 7.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- Keys 45, 25, 65, 15, 35, 55, 75, 30 are inserted in this order into an empty binary search tree. What is its postorder traversal?
- What is the maximum number of nodes in a binary tree of height 5, where the height is the number of edges on the longest root-to-leaf path?
- A complete binary tree stored level by level has exactly 40 nodes. How many of them are leaves?
- Keys 14, 8, 11, 5, 9, 3, 12 are inserted one at a time into an initially empty binary min-heap kept in an array. What does the array hold…
- An undirected graph has edges A-B, A-C, B-D, B-E, C-E, C-F, D-G, E-G, F-G. Neighbours are always visited in alphabetical order. What is…
- A binary tree has inorder traversal D B E A F C and postorder traversal D E B F C A. What is its preorder traversal?