Data Structures & AlgorithmsHardGATE CS · ICPC regional
Undirected simple graph on vertices A, B, C, D, E, F with edges A–C (1), A–D (1), A–F (1), B–D (1), B–E (1), D–E (1), E–F (1) (weights ignored). What is the length, counted in edges, of the shortest cycle with an odd number of edges?
- A. 5
- B. 3
- C. 6
- D. 4
Correct answer: B. 3
Enumerating simple cycles gives shortest odd length 3; the shortest even cycle is 4 and the parity condition is what separates them.
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
- Connected undirected weighted graph on vertices A, B, C, D, E with edges A–B (1), A–D (4), A–E (4), B–C (4), B–D (1), B–E (3), D–E (2)…
- Tree with vertices 0 to 9, root 0, edges 0–1, 0–2, 2–3, 1–4, 3–5, 4–6, 5–7, 4–8, 8–9 (parent–child). Vertex weights (vertex:weight) 0:18…
- Keys [19, 23, 15, 12, 48, 41] are inserted, in this order, into an empty AVL tree using the standard rebalancing (left, right, left–right…
- A binary tree with distinct letters has preorder FECBDGA and inorder CDGBEAF. What is its postorder traversal (left, right, root), written…
- Directed weighted graph on vertices A, B, C, D with edges D→C (-4); A→B (-1); D→B (6); C→B (2); A→D (-2); D→A (5); C→A (-2); B→A (6)…
- Undirected graph on vertices A, B, C, D, E, F, G with edges A–C (1), A–E (1), A–F (1), A–G (1), B–D (1), B–G (1), C–D (1), D–E (1), D–F…