Skills101
← All practice quizzes

Quiz: Tree Traversals

5 questions · new set on every retakeNo time limitPass: 60%+10 XP on first pass

The four ways to visit every node of a binary tree, recursive and iterative, with a diagram of one tree in all four orders — plus which traversal to pick for which problem.

Log in to take the quiz

Free account · see your score, answers and explanations, earn XP

  1. Question 1

    For the tree with root 10, left child 5 and right child 20, what is the postorder?

  2. Question 2

    Which traversal of a binary search tree gives the values in sorted order?

  3. Question 3

    What does this print?

    from collections import deque
    tree = {1: [2, 3], 2: [4], 3: [5, 6], 4: [], 5: [], 6: []}
    q, out = deque([1]), []
    while q:
        n = q.popleft()
        out.append(n)
        q.extend(tree[n])
    print(out)
    
  4. Question 4

    What extra space does a recursive traversal use on a tree of height h?

  5. Question 5

    Computing the height of every node from its children's heights is which kind of traversal?

🎯 Today’s placement challenge — 10 questions, no login. Can you score 10/10?Take today’s challenge →