Data Structures & AlgorithmsModerateTCS NQT · Accenture pattern
An undirected graph has 6 vertices with degrees 3, 3, 2, 2, 2 and x, and it has 8 edges. What is x?
- A. 2
- B. 6
- C. 3
- D. 4
Correct answer: D. 4
Handshake lemma: the degrees add up to 2E = 16. The known degrees sum to 12, so x = 4. Using E instead of 2E (8 − 12) gives a negative number, a sign that the factor 2 was forgotten.
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
- Dijkstra's algorithm runs from S on the directed graph S→A (7), S→B (2), B→A (3), B→C (8), A→C (1), A→D (6), C→D (2). In what order are…
- What is the maximum number of edges in a directed ACYCLIC graph with 6 vertices (no parallel edges)?
- What is the length of the longest common subsequence of PLACEMENT and COMPLETE?
- Keys 15, 10, 20, 8, 12, 25, 6, 11, 13, 9 are inserted into an empty BST. What is the height of the tree (edges on the longest root-to-leaf…
- Keys 10, 20, 30, 25, 28 are inserted into an empty AVL tree. Which rotations are performed, in order (named by imbalance case)?
- Floyd–Warshall on vertices 0–3 starts from the weight matrix below (∞ = no edge). After the iteration with k = 0 (paths allowed to go…