We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
A tree with n nodes will have n-1 edges. This is because a tree is a connected graph with no cycles, and each node (except the root) is connected to exactly one other node by a single edge.
For example:
A tree with 1 node has 0 edges.
A tree with 2 nodes has 1 edge.
A tree with 3 nodes has 2 edges.
A tree with 4 nodes has 3 edges, and so on.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Data Structures MCQ 1
You are viewing a single comment's thread. Return to all comments →
A tree with n nodes will have n-1 edges. This is because a tree is a connected graph with no cycles, and each node (except the root) is connected to exactly one other node by a single edge. For example: A tree with 1 node has 0 edges. A tree with 2 nodes has 1 edge. A tree with 3 nodes has 2 edges. A tree with 4 nodes has 3 edges, and so on.