Data Structures & AlgorithmsEasyCognizant · Capgemini pattern
How many edges does a tree with n vertices have?
- A. n
- B. n(n − 1)/2
- C. n − 1
- D. n + 1
Correct answer: C. n − 1
A tree is connected and acyclic; it has exactly n − 1 edges. Adding one more edge creates a cycle, and n(n − 1)/2 is the edge count of a complete graph.
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
- In a min-heap, where is the smallest element always found?
- What is the space needed by the adjacency-matrix representation of a graph with V vertices and E edges?
- Depth-first search is naturally implemented with which of the following?
- A binary tree has root 1; 1's children are 2 (left) and 3 (right); 2's children are 4 (left) and 5 (right); 3 has only a right child, 6…
- Keys 50, 30, 70, 20, 40, 60, 80 are inserted in that order into an empty BST. How many leaves does the tree have, and what is its height…
- What is the maximum number of nodes in a binary tree of height 4, where a single-node tree has height 0?