Skills101
← All practice quizzes

Quiz: Binary Search Tree Operations

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

How a binary search tree keeps its keys in order, and how to search, insert, delete (all three cases), check whether a tree is a valid BST and find the k-th smallest key — with diagrams, Python and Java.

Log in to take the quiz

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

  1. Question 1

    In a binary search tree, which statement is always true for every node?

  2. Question 2

    What does this print?

    class Node:
        def __init__(self, k):
            self.key, self.left, self.right = k, None, None
    
    def insert(r, k):
        if r is None:
            return Node(k)
        if k < r.key:
            r.left = insert(r.left, k)
        else:
            r.right = insert(r.right, k)
        return r
    
    def inorder(r):
        return inorder(r.left) + [r.key] + inorder(r.right) if r else []
    
    root = None
    for k in [8, 3, 10, 1, 6]:
        root = insert(root, k)
    print(inorder(root))
    
  3. Question 3

    Keys 1, 2, 3, 4, 5 are inserted in that order into an empty plain BST. What is the height of the tree?

  4. Question 4

    A node to be deleted has two children. Which key replaces it?

  5. Question 5

    Why does the inorder successor of a node with two children never have a left child?

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