Data Structures & AlgorithmsHardICPC regional · GATE CS top band
Undirected simple graph on vertices A, B, C, D, E, F, G with edges A–B (1), A–G (1), B–F (1), B–G (1), C–E (1), C–F (1), C–G (1), D–E (1), F–G (1) (weights ignored). What is the length, counted in edges, of the shortest cycle with an odd number of edges?
- A. 5
- B. 4
- C. 3
- D. 7
Correct answer: C. 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
- Directed weighted graph on vertices E, C, A, B, D (source E, target D) with edges: E→C (2); E→A (3); A→C (-3); C→D (3); A→D (3); E→D (18)…
- A trie keeps a counter at each node, and every word of the list W = ['acb', 'c', 'bcb', 'c', 'bc', 'a', 'aac'] is inserted once per…
- On an 6 × 6 chessboard with rows and columns numbered 0 to 5, a knight starts at (3, 5) and must reach (5, 0) (as (row, column)). A knight…
- Dictionary D = {bem, cle, gcc, icd, imb, lbg, lcp, lri, ois, opg, scc, scp} (all words have 3 letters). Starting from the word 'lcd', a…
- Directed weighted graph on vertices A, B, C, D, E with edges E→C (-3); A→D (-4); A→B (-2); D→B (0); B→C (-2); A→E (-1); E→D (0); B→E (-4)…
- Array A = [5, 6, 5, 4, 3, 8, 4, 6] (indices 0 to 7). Count the non-empty subsets of positions (each position used at most once, subsets…