Data Structures & AlgorithmsModerateGATE CS · ICPC regional
Undirected graph on vertices A, B, C, D, E, F with weighted edges A–B (5), A–C (6), A–D (4), A–F (3), B–D (8), B–E (5), B–F (6), C–F (6), D–F (4), E–F (3). Keep only the edges of weight at most 6 (discard the others). How many connected components does the remaining graph have?
- A. 5
- B. 6
- C. -3
- D. 1
Correct answer: D. 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 -3.
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
- Array A = [27, 21, 20, 5, 13, 9, 28] (all values below 32). What is the maximum of A[i] XOR A[j] over all index pairs with 0 ≤ i < j < 7?
- Coins of denominations [11, 10, 7, 2] are available in unlimited quantity. What is the minimum number of coins needed to pay exactly 20?…
- Weighted tree on vertices 0 to 7 with edges 0–1 (9), 0–2 (2), 1–3 (4), 0–4 (3), 2–5 (3), 5–6 (2), 6–7 (7). What is the largest possible…
- Undirected weighted graph on vertices A, B, C, D, E, F; its edges, in this listed order, are: A–D (2), A–C (3), A–F (6), B–C (5), D–E (5)…
- Complete undirected graph on vertices A to E with symmetric edge weights given row by row (row i, column j = weight of edge between…
- Strings a = "bcbbba" and b = "accc". The edit distance allows insert, delete and substitute, each costing 1 (the standard Levenshtein…