GATE Computer ScienceVery hardGATE CS (PYQ pattern)
Ten houses stand in a CIRCLE with values 6, 2, 9, 4, 3, 8, 1, 7, 5, 10 (the first and last houses are neighbours). No two neighbouring houses may both be chosen. What is the maximum total value?
- A. 40
- B. 30
- C. 34
- D. 36
Correct answer: C. 34
Because houses 1 and 10 are adjacent, solve the linear problem twice: on houses 2–10 and on houses 1–9, and take the larger. These give 34 (e.g. 9+8+7+10) and 30, so the answer is 34. The plain linear answer 40 (taking both 6 and 10, e.g. 6+9+8+7+10) is illegal on a circle.
More Algorithms questions
- Among all full parenthesisations of the product A₁A₂A₃A₄A₅A₆A₇, how many contain the product (A₃A₄) as one of their sub-products?
- X = ABCBDAB and Y = BDCABA have longest common subsequences of length 4. How many DIFFERENT strings are shortest common supersequences of…
- The fractional knapsack greedy algorithm (taking items by value/weight ratio, the last one fractionally) is run on capacity 26 and items…
- Dijkstra's algorithm (never re-inserting or re-opening a vertex once it has been extracted) is run from S on a directed graph with edges…
- Dijkstra's algorithm with a binary min-heap (lazy insertion is not used: a decrease-key is performed whenever an edge improves the label…
- In the undirected weighted graph with edges SA 1, SB 1, SC 2, AD 2, BD 2, CD 1, AE 3, BE 3, CE 2, DT 2, ET 1 and AB 1, how many distinct…