Data Structures & AlgorithmsVery hardGATE CS · ICPC regional
Undirected weighted graph on vertices A to F with edges listed as: D–E (9), A–C (5), A–F (6), C–F (7), C–E (3), B–C (8), E–F (1), A–E (5), B–F (5). Kruskal's algorithm sorts the edges by increasing weight, breaking ties in listed order, and ADDS each edge that does not close a cycle. Which edge is the fourth edge that Kruskal ADDS?
- A. B–F (5)
- B. A–E (5)
- C. A–C (5)
- D. D–E (9)
Correct answer: A. B–F (5)
Kruskal accepts E–F (1), C–E (3), A–C (5), B–F (5), D–E (9) in that order, so the fourth accepted edge is B–F (5). Taking the 4-th lightest edge without the cycle test (A–E (5)) is the slip.
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
- Undirected weighted graph on vertices A to F with edges listed as: B–D (5), C–E (8), A–D (1), B–E (9), B–F (9), C–F (5), D–F (7), A–B (3)…
- Undirected weighted graph on vertices A to G with edges listed as: D–G (8), A–F (6), F–G (3), C–D (3), E–G (2), A–E (1), B–C (3), D–E (9)…
- Undirected weighted graph on vertices A to F with edges listed as: A–D (3), D–F (2), B–D (6), B–C (4), A–F (3), C–D (6), C–F (9), E–F (6)…
- Directed acyclic graph on letters A to G with edges (X→Y means X must precede Y): A→E, B→E, C→E, C→F, D→A, D→C, G→E, G→F. Kahn's algorithm…
- Directed acyclic graph on letters A to G with edges (X→Y means X must precede Y): A→C, A→E, B→C, D→C, E→C, F→B. Kahn's algorithm starts a…
- Directed acyclic graph on letters A to F with edges (X→Y means X must precede Y): C→A, C→E, D→A, E→A, E→D. Kahn's algorithm starts a FIFO…