Data Structures and Algorithms (DSA27) · Week 11

Trees (Lecture 11)

These quizzes are for self-study. Your answers are saved on this device only and are not sent anywhere.

Score: 0 / 22 · Answered: 0

  1. W11-M01 Recall

    A leaf is a node that:

  2. W11-M02 Recall

    With height counted in edges, the height of a tree with exactly one node is:

  3. W11-M03 Apply

    The largest number of nodes a binary tree of height 3 can hold is:

  4. W11-M04 Apply

    The smallest possible height of a binary tree with 100 nodes is:

  5. W11-M05 Recall

    A binary tree is a binary search tree when, for every node x:

  6. W11-M06 Apply

    In the tree Q, the right child of the root's left child is:

  7. W11-M07 Apply

    contains(25) on Q compares 25 with how many nodes?

  8. W11-M08 Explain

    The worst-case cost of contains on a BST of n nodes, built by dsa/tree.py from values in an unknown order, is:

  9. W11-M09 Apply

    Which insertion order of 1 to 7 builds the tallest BST?

  10. W11-M10 Apply

    The pre-order walk of Q is:

  11. W11-M11 Apply

    The post-order walk of Q is:

  12. W11-M12 Recall

    Which walk of any BST lists its values in increasing order?

  13. W11-M13 Explain

    You save a BST to a file as a list of values, and later rebuild it by inserting the list into an empty tree. To get back the same shape, the list should be the tree's:

  14. W11-M14 Explain

    Which walk frees a tree safely in a language where you release memory yourself, and evaluates an expression tree?

  15. W11-M15 Explain

    level_order uses a queue rather than the call stack because:

  16. W11-M16 Apply

    During level_order on Q, the largest number of nodes waiting in the queue at one time is:

  17. W11-M17 Recall

    Deleting a node with two children, dsa/tree.py replaces its value with:

  18. W11-M18 Apply

    delete(30) on Q. Which value ends up at the root?

  19. W11-M19 Explain

    The in-order successor of a node with two children never has a left child. Why does that matter to delete?

  20. W11-M20 Explain

    A student's is_valid checks, at every node, only that the left child is smaller and the right child larger. It:

  21. W11-M21 Apply

    The expression tree for (2 + 3) * 4 is walked in post-order. The result is:

  22. W11-M22 Recall

    AVL trees and red-black trees:

19 marks

Written questions

5 written questions (19 marks). Write your answer first, then open the model answer and its marking points, and mark yourself honestly: each point is worth about one mark.

Written total: 0 / 19

  1. W11-E1 Recall 3 marks

    Define root, leaf, parent, subtree, depth and height, using the tree Q as the example for each. Why does a tree of n nodes always have exactly n - 1 edges?

  2. W11-E2 Explain 4 marks

    State the BST property. Give a tree in which every parent–child pair is in the right order but which is not a BST, and explain how is_valid must be designed to reject it. What is its cost?

  3. W11-E3 Explain 4 marks

    Describe the three cases of BST deletion. For the two-children case, explain why the in-order successor may take the deleted value's place, and why removing the successor is always easy.

  4. W11-E4 Explain 4 marks

    Name the four traversals of a binary tree, give the order of each, and for each say one thing it is used for and why it suits that use.

  5. W11-E5 Explain 4 marks

    "A BST gives O(log n) search." When is that true, and when is it false? Explain with the height, give an insertion order that makes it false, and name the cure. Compare a BST with a sorted array for search, insert and listing in order.