Data Structures & AlgorithmsHardGATE CS · ICPC regional
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), C–E (9). 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 third edge that Kruskal ADDS?
- A. A–F (3)
- B. A–D (3)
- C. B–D (6)
- D. B–C (4)
Correct answer: D. B–C (4)
Kruskal accepts D–F (2), A–D (3), B–C (4), B–D (6), E–F (6) in that order, so the third accepted edge is B–C (4). Taking the 3-th lightest edge without the cycle test (A–F (3)) 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
- 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…
- Directed acyclic graph on letters A to G with edges (X→Y means X must precede Y): B→D, B→G, C→A, C→F, E→D, E→F, E→G, F→D. Kahn's algorithm…
- Directed acyclic graph on letters A to G with edges (X→Y means X must precede Y): C→A, D→E, E→C, F→C, G→A, G→B, G→C. Kahn's algorithm…
- Directed acyclic graph on letters A to G with edges (X→Y means X must precede Y): A→G, B→C, B→G, C→G, D→A, D→G, E→G, F→A, F→B, F→E, F→G…