Kit Library / Computer Science / Data Structures

⚡ Topic Learning Kit

Non-Linear Data Structures: Trees

English 17 leveled MCQs 31 flashcards 9 games Free

Shared by a Veda learner · Generated with Veda AI

Veda Bites

The whole idea, one bite at a time

Veda Bites are swipeable micro-lessons — each one teaches exactly one idea. The bites below come from this kit — swipe through them in the app.

💡 Key Idea

Trees: Hierarchical, Not Linear

Data doesn't have to be a straight line.

A tree is a non-linear data structure where elements (nodes) are arranged in a hierarchy — one root, branching into children, forming levels.

↳ Trees trade linear simplicity for hierarchical speed — that's why databases and file systems rely on them.

📖 Definition

Tree Vocabulary You Must Know

Speak tree language fluently.

↳ Precise vocabulary is half the exam — root, leaf, depth, and height appear in almost every tree question.

⚖️ Comparison

Linear vs Non-Linear: Why Trees Exist

Arrays walk; trees branch.

↳ Trees win when data has natural hierarchy or when fast search matters.

⭐ Important Fact

A Tree with n Nodes Has Exactly n−1 Edges

One less edge than nodes — always.

Every tree with $n$ nodes has exactly $n-1$ edges. This is the quickest way to verify whether a given graph is actually a tree.

↳ If edges ≠ nodes − 1, it's not a tree — it's either disconnected or has a cycle.

⚙️ Process

The Three Core Tree Traversals

Visit every node — three different orders.

Traversal means visiting every node exactly once. The order depends on when you process the root relative to its subtrees.

↳ Inorder on a BST gives sorted data — that's the single most tested traversal fact.

💻 Code Example

Inorder Traversal in Code

Three lines that sort a BST.

↳ Recursion mirrors the tree's own structure — left, root, right is literally the code order.

📖 Definition

Binary Tree vs Binary Search Tree

Two children vs two rules.

↳ The BST ordering rule is what turns a plain binary tree into a searchable structure.

⚠️ Common Mistake

Don't Confuse Height with Depth

Same tree, opposite directions.

↳ Depth goes down from root; height goes up from leaf — memorize the direction, not just the number.

🌍 Real World

Trees Are Everywhere You Look

Your computer is a forest of trees.

↳ If data has hierarchy, a tree is almost always the right model.

🛠️ Application

Why Databases Love B-Trees

Billions of rows, milliseconds to find one.

A B-tree is a balanced multi-way tree where each node holds many keys. Its short height means fewer disk reads per lookup.

↳ Balanced trees keep search fast at scale — that's the whole point of using them in databases.

🎯 Exam Tip

The Traversal Question Almost Always Appears

One traversal question, guaranteed marks.

↳ Traversal questions are free marks if you trace carefully — don't rush the order.

🧠 Memory Trick

Remember Traversals with 'Root Position'

Where's the root? That's the name.

↳ The prefix tells you exactly where the root sits — no memorizing needed.

🚫 Warning

Unbalanced Trees Kill Performance

A tree can secretly become a list.

↳ A BST is only fast if it's balanced — sorted input is the classic trap.

💡 Interview Tip

The Most-Asked Tree Interview Question

Height, depth, and balance — know all three.

↳ Master recursive height calculation — it unlocks half of all tree interview problems.

✅ Best Practice

Always Handle the Empty Tree

The null check saves your code.

↳ The base case isn't optional — it's what makes recursion on trees safe.

Smart notes

What you'll study, topic by topic

1

Non-Linear Data Structures: Trees

15 min

Trees are non-linear data structures that organize data hierarchically, with a root node branching into child nodes. Unlike linear structures such as arrays or linked lists, trees model relationships like file systems, f…

  • A tree is a non-linear data structure where each node connects to zero or more children.
  • The topmost node is the root; nodes with no children are leaves.
  • A parent is a node directly above another; children are nodes directly below.

Full explanation, worked examples & memory tricks in the app

Leveled MCQ practice

Try the smart MCQs from this kit

All 17 questions, laddered from warm-up to topper-level, each with its answer and the reasoning behind it.

Warm-up · 6 questions

Q1. Why is a tree classified as a non-linear data structure?

Beginner
A Its elements are stored in a single contiguous line.
B It always stores its data in sorted order.
C It allows each element only one predecessor and one successor.
D Each node can have many children, giving a one-to-many shape.
Show the answer

D · Each node can have many children, giving a one-to-many shape.

Linear structures like arrays and lists are one-to-one; a tree is one-to-many because a node can point to multiple children, which is the defining non-linear property.

Q2. In a tree, what do we call a node that has no children?

Beginner
A Subtree
B Parent
C Root
D Leaf
Show the answer

D · Leaf

A node with no children is a leaf (degree 0). The root is the topmost node, and a parent is a node with at least one child.

Q3. A tree has 15 nodes. How many edges does it contain?

Beginner
A 16
B 14
C 30
D 15
Show the answer

B · 14

Every node except the root has exactly one parent edge, so a tree with $n$ nodes has $n - 1$ edges: $15 - 1 = 14$.

Q4. Which traversal of a binary search tree visits nodes in ascending sorted order?

Beginner
A Postorder
B Preorder
C Level order
D Inorder
Show the answer

D · Inorder

Inorder visits left subtree, node, then right subtree. Because a BST keeps smaller values on the left and larger on the right, this produces sorted output.

Q5. A file explorer where folders contain folders and files is best modeled by which structure?

Beginner
A A flat array
B A queue
C A tree
D A stack
Show the answer

C · A tree

Nested folders form a hierarchy — each folder can contain many items, which is exactly the one-to-many shape of a tree.

Q6. A tree with $n$ nodes always has exactly $n - 1$ edges and contains no cycles.

Beginner
A True
B False
Show the answer

A · True

A tree with $n$ nodes always has exactly $n - 1$ edges and contains no cycles.

Building up · 6 questions

Q7. Which statement about the degree of a node is correct?

Intermediate
A It is the number of edges from the root to the node.
B It is the number of ancestors above the node.
C It is the number of children the node has.
D It is the maximum depth of the tree.
Show the answer

C · It is the number of children the node has.

Degree counts a node's children. The number of edges from the root is depth, and the maximum depth is the tree's height.

Q8. A structure has 10 nodes and 12 edges. What can you conclude?

Intermediate
A It is a valid tree with extra leaves.
B It cannot be a tree because it contains at least one cycle.
C It is a balanced binary search tree.
D It is a forest of two trees.
Show the answer

B · It cannot be a tree because it contains at least one cycle.

A tree with $n$ nodes must have exactly $n - 1$ edges. With 10 nodes and 12 edges there are more edges than a tree allows, so at least one cycle exists.

Q9. A BST is built by inserting values in strictly increasing order. What happens to search performance?

Intermediate
A It improves to $O(1)$ because values are sorted.
B It stays $O(\log n)$ because the tree is balanced.
C It degrades to $O(n)$ because the tree becomes list-like.
D It becomes $O(n \log n)$ due to rebalancing.
Show the answer

C · It degrades to $O(n)$ because the tree becomes list-like.

Sorted input makes every new node a right child, producing a degenerate linked-list-like tree of height $n$, so search becomes $O(n)$.

Q10. Which traversal should you use to delete an entire tree safely?

Intermediate
A Level order, so rows are removed top-down.
B Inorder, so values come out sorted.
C Preorder, so parents are removed first.
D Postorder, so children are removed before parents.
Show the answer

D · Postorder, so children are removed before parents.

Postorder processes left and right subtrees before the node, so every child is freed before its parent — the safe order for deletion.

Q11. What distinguishes a binary search tree from a plain binary tree?

Intermediate
A A BST never contains leaf nodes.
B A BST stores all values at the leaves only.
C A BST allows each node up to three children.
D A BST enforces left-smaller and right-larger ordering at every node.
Show the answer

D · A BST enforces left-smaller and right-larger ordering at every node.

Both limit children to two, but only a BST adds the ordering rule that makes fast search possible.

Q12. Which structure is a collection of disjoint trees with no shared nodes?

Intermediate
A A balanced BST
B A forest
C A cycle
D A subtree
Show the answer

B · A forest

A forest is exactly a set of disjoint trees. A subtree is a node plus its descendants within one tree.

Topper level · 5 questions

Q13. Assertion (A): A tree with $n$ nodes always has exactly $n - 1$ edges. Reason (R): Every node except the root has exactly one parent, and each parent-child link is one edge.

Advanced
A A is false but R is true.
B A is true but R is false.
C Both A and R are true, but R does not explain A.
D Both A and R are true, and R correctly explains A.
Show the answer

D · Both A and R are true, and R correctly explains A.

Each non-root node contributes exactly one edge to its parent, so edges equal non-root nodes, which is $n - 1$. The reason is the direct justification of the assertion.

Q14. Consider these statements about trees: I. A tree contains no cycles. II. Exactly one path connects any two nodes in a tree. III. Every graph is a tree. Which combination is correct?

Advanced
A I and II only
B II and III only
C I and III only
D I, II and III
Show the answer

A · I and II only

Trees are connected and acyclic, so I and II hold. Statement III is false: graphs may contain cycles or be disconnected, so not every graph is a tree.

Q15. A team needs fast lookups on millions of records that are inserted in sorted order. Which choice is best?

Advanced
A A stack holding the records
B A naive BST built by inserting the sorted records
C A plain unsorted array scanned linearly
D A self-balancing tree such as an AVL or red-black tree
Show the answer

D · A self-balancing tree such as an AVL or red-black tree

Sorted insertion degenerates a naive BST to $O(n)$ search. A self-balancing tree keeps height near $\log n$, preserving $O(\log n)$ lookups.

Q16. You draw a structure and can trace a loop that returns to your starting node. What does this tell you?

Advanced
A It is a forest of two trees.
B It is a graph but not a tree, because it contains a cycle.
C It is a tree with an extra leaf.
D It is a balanced binary search tree.
Show the answer

B · It is a graph but not a tree, because it contains a cycle.

A tree must be acyclic. Tracing a loop back to the start proves a cycle exists, so the structure is a general graph, not a tree.

Q17. Consider a binary search tree (BST) constructed by inserting the following values in the given order: 30, 20, 40, 10, 25, 35, 50. What will be the depth of the node containing the value 25?

Advanced
A 1
B 3
C 4
D 2
Show the answer

D · 2

The depth of a node in a tree is defined as the number of edges from the root to that node. In this BST, the root is 30 (depth 0), 20 is the left child of 30 (depth 1), and 25 is the right child of 20 (depth 2). Therefore, the depth of the node containing the value 25 is 2.

Flashcards

Tap a card to flip it

31 flashcards in this kit — the app reviews them with spaced repetition so the right card returns on the right day.

Learning games

Play your way through this kit

Every game is built from this kit's own content — scores feed your mastery, so playing counts as studying.

🎮

Word Match

Built from this kit's own content

🎮

True False

Built from this kit's own content

🎮

Memory Match

Built from this kit's own content

🎮

Flashcard Battle

Built from this kit's own content

🎮

Speed Quiz

Built from this kit's own content

🎮

Guess Term

Built from this kit's own content

🎮

Sequence Builder

Built from this kit's own content

🎮

Categorization

Built from this kit's own content

🎮

Revision Battle

Built from this kit's own content

Playable in the app

Study it properly — free, in the app

The full Veda Bites deck, complete notes, spaced-repetition flashcards, leveled MCQs, tests and games for this kit — plus Daily Facts and the Arena, every day.