Data Structures & AlgorithmsModerateICPC regional · GATE CS top band
Undirected graph on vertices A, B, C, D, E, F, G with weighted edges A–B (6), A–G (9), B–C (6), B–G (8), C–D (6), C–F (1), D–G (8), E–F (1), E–G (2), F–G (1). Keep only the edges of weight at most 6 (discard the others). How many connected components does the remaining graph have?
- A. 4
- B. 7
- C. 1
- D. 0
Correct answer: C. 1
Only edges of weight ≤ 6 survive; the result has 1 components. Subtracting the number of kept edges from n ignores the edges that close cycles and gives 0.
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 simple graph on vertices A, B, C, D, E, F, G with edges A–D (1), A–G (1), B–E (1), C–D (1), C–F (1), C–G (1), D–E (1), D–F (1)…
- Undirected weighted graph on vertices A, B, C, D, E with edges A–B (1), A–C (1), A–D (1), A–E (1), B–C (1), B–E (2), D–E (3). An edge is…
- Directed weighted graph on vertices A, B, C, D, E with edges listed in this exact order: B→E (7); E→A (6); B→D (3); B→C (3); B→A (4); A→B…
- Array A = [5, 20, 23, 4, 3, 30, 2, 24]. How many index pairs i < j satisfy (A[i] XOR A[j]) < 19? (A trie with subtree counts answers this…
- Distinct words ['ccc', 'aaa', 'cb', 'bbbc', 'ba', 'ca', 'bb'] are inserted into an empty trie (one node per character, shared prefixes…
- Array [2, 14, 21, 11, 1, 17] is turned into a min-heap in place with bottom-up heapify: for i from ⌊n/2⌋−1 down to 0, sift the element at…