1. Home
  2. Explore
  3. Computer Science
  4. Binary Tree Fundamentals

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Binary Tree Fundamentals

  • 33Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Tree Types and Properties

What is a full binary tree?

33 questions

  1. 1

    What is a full binary tree?

    Model answer

    A full binary tree is a tree where every node has either 0 or 2 children; internal nodes always have exactly two children.

    Explanation

    In a full binary tree, if a node has children, it must have two; leaves have no children. No node can have exactly one child.

  2. 2

    What is a complete binary tree?

    Model answer

    A complete binary tree is a tree where all levels are filled from top to bottom and left to right, with the last level filled as far left as possible.

    Explanation

    The filling order is strict: nodes are added level by level, left to right. If a node is missing on the left side, the tree is not complete.

  3. 3

    What is a perfect binary tree?

    Model answer

    A perfect binary tree is a tree where all leaf nodes are on the same level and every internal node has exactly two children.

    Explanation

    A perfect binary tree is both full and complete. All leaves are at the same depth.

  4. 4

    Can a perfect binary tree be full? Explain.

    Model answer

    Yes, a perfect binary tree is always full because every internal node has two children.

    Explanation

    By definition, a perfect tree requires internal nodes to have exactly two children, which matches the full tree condition.

  5. 5

    Can a complete binary tree be full? Explain.

    Model answer

    Yes, a complete binary tree can be full, but it is not required. For example, a complete tree may have nodes with two children but also nodes with one child if it is the last node filling left.

    Explanation

    A complete tree only requires left-to-right filling; a node may have only one child if it is the last node on the level.

  6. 6

    In a full binary tree, how many children does a leaf node have?

    Model answer

    A leaf node in a full binary tree has zero children.

    Explanation

    Leaves are nodes with no descendants. Full tree definition only restricts internal nodes to have two children; leaves have none.

  7. 7

    In a perfect binary tree, what is true about all leaves?

    Model answer

    All leaves are at the same level (same depth).

    Explanation

    This is a defining property of a perfect binary tree, along with every internal node having two children.

  8. 8

    Describe the filling rule for a complete binary tree.

    Model answer

    Nodes are filled from top to bottom, left to right, level by level.

    Explanation

    The tree is built by adding nodes level by level, ensuring that each level is completely filled before starting the next, and within a level, nodes are added from left to right.

  9. 9

    Give an example of a tree that is complete but not perfect.

    Model answer

    A tree with three nodes: root with left child only (or root with two children and no further nodes) is complete but not perfect because leaves are not all on the same level.

    Explanation

    A complete tree can have an incomplete last level; perfection requires all leaves on the same level.

  10. 10

    Why is a perfect binary tree both complete and full?

    Model answer

    Because all internal nodes have two children (full) and all levels are completely filled (complete).

    Explanation

    Perfect trees satisfy both definitions: every node has 0 or 2 children, and the tree is filled level by level without gaps.

  11. 11

    What are the three fundamental binary tree traversals?

    Model answer

    Pre-order, in-order, and post-order traversals.

    Explanation

    These are the standard depth-first traversals that visit nodes in different orders of root, left, and right.

  12. 12

    Explain the order of node visits in a pre-order traversal.

    Model answer

    Visit the current node, then recursively visit the left subtree, then recursively visit the right subtree (NLR).

    Explanation

    The node is visited before its subtrees. The prefix 'pre' indicates the node is visited first.

  13. 13

    Explain the order of node visits in an in-order traversal.

    Model answer

    Recursively visit the left subtree, then visit the current node, then recursively visit the right subtree (LNR).

    Explanation

    The node is visited between the left and right subtrees. The prefix 'in' indicates the node is visited in between.

  14. 14

    Explain the order of node visits in a post-order traversal.

    Model answer

    Recursively visit the left subtree, then recursively visit the right subtree, then visit the current node (LRN).

    Explanation

    The node is visited after both subtrees. The prefix 'post' indicates the node is visited last.

  15. 15

    What does the prefix 'pre' indicate in pre-order traversal?

    Model answer

    It indicates the node is visited before its left and right subtrees.

    Explanation

    The order is Node, Left, Right; 'pre' means the node comes first.

  16. 16

    What does the prefix 'in' indicate in in-order traversal?

    Model answer

    It indicates the node is visited in between the left and right subtrees.

    Explanation

    The order is Left, Node, Right; the node is in the middle.

  17. 17

    What does the prefix 'post' indicate in post-order traversal?

    Model answer

    It indicates the node is visited after both left and right subtrees.

    Explanation

    The order is Left, Right, Node; the node is last.

  18. 18

    In a pre-order traversal, when is the node visited relative to its subtrees?

    Model answer

    The node is visited before exploring either subtree.

    Explanation

    Pre-order follows Node-Left-Right, so the node is visited first.

  19. 19

    In an in-order traversal, when is the node visited relative to its subtrees?

    Model answer

    The node is visited after the left subtree and before the right subtree.

    Explanation

    In-order follows Left-Node-Right.

  20. 20

    In a post-order traversal, when is the node visited relative to its subtrees?

    Model answer

    The node is visited after both left and right subtrees have been traversed.

    Explanation

    Post-order follows Left-Right-Node.

  21. 21

    In the recursive traversal described, what is the 'policy' at each node?

    Model answer

    The policy is the set of tasks to execute at that node: visit node, visit left subtree, visit right subtree, in an order determined by the traversal type.

    Explanation

    Each recursive call applies the same policy, but the order of tasks changes per traversal.

  22. 22

    What data structure is used to manage the state during recursive traversal?

    Model answer

    The call stack (or recursion stack) is used to manage state.

    Explanation

    Each recursive call pushes a frame onto the call stack, storing local state such as which subtasks remain.

  23. 23

    In the example, what is the first node visited in pre-order traversal of the given tree?

    Model answer

    10 is the first node visited.

    Explanation

    Pre-order visits the root first, and the root of the tree is 10.

  24. 24

    In the example, what is the last node visited in pre-order traversal?

    Model answer

    22 is the last node visited.

    Explanation

    Pre-order traversal visits nodes in the order: 10, 7, 6, 1, 8, 9, 11, 20, 14, 22. The last node is 22.

  25. 25

    In the in-order traversal example, what order does the sequence produce for the given tree?

    Model answer

    The sequence is 1, 6, 7, 8, 9, 10, 11, 14, 20, 22 (increasing order).

    Explanation

    In-order traversal of a binary search tree yields sorted order. The tree given is a BST.

  26. 26

    Why does the in-order traversal of the given tree produce increasing order?

    Model answer

    Because the tree is a binary search tree: all left subtree values are less than the node, and all right subtree values are greater.

    Explanation

    In-order visits left first, then node, then right, so it naturally outputs values in ascending order for a BST.

  27. 27

    In post-order traversal, when does a node get visited?

    Model answer

    A node gets visited after both its left and right subtrees have been fully traversed.

    Explanation

    Post-order follows Left-Right-Node; the node is the last step in its own recursive call.

  28. 28

    Describe a base case in the recursive traversal.

    Model answer

    When the current node is null (or nonexistent), return without doing any work.

    Explanation

    The base case stops recursion when there is no node to process, preventing infinite recursion.

  29. 29

    What property makes a binary tree a binary search tree?

    Model answer

    For every node, all values in its left subtree are less than the node's value, and all values in its right subtree are greater.

    Explanation

    This ordering property allows efficient searching and produces sorted output from in-order traversal.

  30. 30

    How does in-order traversal behave on a binary search tree?

    Model answer

    It visits nodes in increasing order (sorted order).

    Explanation

    Due to the BST property, in-order traversal yields values in ascending sequence.

  31. 31

    What is the time complexity of a traversal that visits all nodes in a binary tree with n nodes?

    Model answer

    The time complexity is O(n)O(n)O(n), linear in the number of nodes.

    Explanation

    Each node is visited exactly once, so the work scales linearly with n.

  32. 32

    Can binary tree traversals be implemented iteratively? If so, what data structure can be used?

    Model answer

    Yes, iteratively using an explicit stack (or sometimes a queue).

    Explanation

    An explicit stack can simulate the call stack to control the order of visits.

  33. 33

    Name one traversal that might use a queue instead of a stack.

    Model answer

    Breadth-first traversal (level-order traversal) uses a queue.

    Explanation

    Breadth-first visits nodes level by level, which is naturally implemented with a FIFO queue.

1 of 33
Question 1 of 33

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent