Data Structures & AlgorithmsModerateHCL · Tech Mahindra pattern
An undirected graph has 12 vertices and the sum of the degrees of all vertices is 40. How many edges does it have?
- A. 80
- B. 40
- C. 20
- D. 28
Correct answer: C. 20
Each edge adds 1 to the degree of both its endpoints, so the sum of degrees = 2E, giving E = 40/2 = 20.
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
- The preorder traversal of a BST is 8, 5, 1, 7, 10, 12. What is its postorder traversal?
- A binary tree has inorder 4 8 2 5 1 6 3 7 and preorder 1 2 4 8 5 3 6 7. What is its postorder?
- 10, 4, 7, 1, 3 are inserted in that order into an empty binary min-heap (array form, sift-up after each insert). What is the array at the…
- The bottom-up build-heap procedure (sift down from the last internal node back to the root) turns [3, 1, 6, 5, 2, 4] into a max-heap. What…
- The maximum is deleted from the max-heap [50, 30, 40, 10, 20, 35]: the last element replaces the root and is sifted down. What is the heap…
- An undirected graph has edges A–B, A–C, B–D, C–D, C–E, D–F, E–F, and neighbours are always taken in alphabetical order. What is the DFS…