Unit Focus

What this unit is really teaching

The unit links recursion, searching, and structure design through binary trees and binary search trees.

Key Topics

  • +Tree vocabulary: root, leaf, parent, child, height, depth, and subtree
  • +Binary trees and recursive traversal patterns
  • +Preorder, inorder, postorder, and level-order traversal
  • +Binary search tree search, insertion, and deletion concepts
  • +Balanced versus unbalanced trees and runtime consequences
  • +Expression trees, decision trees, and hierarchical data modeling

Practice Work

Implementation and analysis tasks

Student task

Implement recursive tree traversals and print structured trace output.

Student task

Build a binary search tree and compare performance with a sorted ArrayList.

DSA Assignment Bank

30 interview-style algorithm questions for this unit

Code Scholars provides structured assignments, implementation support, edge-case review, and runtime analysis coaching so students learn the concept rather than only memorizing a solution.

1

Recursive tree traversal

Compute tree height

Return the height of a binary tree and define the result for an empty tree.

2

Bounds recursion

Validate a binary search tree

Check whether every node respects a valid lower and upper bound, not just its immediate children.

3

Recursive search

Find lowest common ancestor

Given two nodes in a binary tree, find the lowest node that has both nodes in its subtrees.

4

Preorder with null markers

Serialize and deserialize a tree

Convert a tree to a string and rebuild it while preserving missing children.

5

Recursive partitioning

Build a tree from traversals

Reconstruct a binary tree from preorder and inorder traversal arrays.

6

Recursive accumulation

Find path sum from root to leaf

Determine whether any root-to-leaf path has a target sum.

7

Backtracking on trees

List all root-to-leaf paths

Collect every root-to-leaf path while adding and removing values from a path list.

8

Postorder reasoning

Compute maximum path sum

Find the largest sum of any path in a tree and explain what value each recursive call returns to its parent.

9

Height plus validity

Check whether a tree is balanced

Return both height and balance status so the algorithm does not recompute heights repeatedly.

10

Recursive swapping

Invert a binary tree

Swap left and right subtrees at every node and trace the result on a small example.

11

Queue-based traversal

Perform level-order traversal

Return tree values grouped by depth using a queue.

12

Level-order selection

Find right-side view

Use breadth-first traversal to report the last visible node at each level.

13

Inorder traversal

Find kth smallest in a BST

Use the sorted order of inorder traversal to find the kth smallest value in a BST.

14

BST mutation

Delete from a BST

Delete a value from a BST and handle leaf, one-child, and two-child cases.

15

BST search path

Find successor in a BST

Find the next larger value after a given value using tree structure rather than sorting all nodes.

16

Divide and conquer

Convert sorted array to balanced BST

Build a height-balanced BST by choosing middle elements recursively.

17

Traversal transformation

Flatten tree to linked order

Rearrange a tree into a single right-child chain following preorder order.

18

Structure-based optimization

Count complete tree nodes

Use the shape of a complete binary tree to count nodes faster than visiting every node when possible.

19

Tree comparison

Check subtree match

Determine whether one tree appears inside another using recursive equality checks.

20

Postorder aggregation

Find diameter of a tree

Compute the longest path between any two nodes using heights from subtrees.

21

Recursive evaluation

Evaluate expression tree

Evaluate a tree where leaves are numbers and internal nodes are operators.

22

Coordinate traversal

Print vertical columns

Assign horizontal positions to nodes and group values by column.

23

Inorder anomaly detection

Recover a swapped BST

Find two swapped nodes in a BST by looking for order violations during inorder traversal.

24

Recursive pruning

Trim a BST by range

Remove nodes outside a value range while preserving valid BST structure.

25

Level tracking

Find deepest leaves sum

Compute the sum of values on the deepest level of a binary tree.

26

Hierarchical modeling

Design a file-tree search

Model folders and files as a tree and search for names matching a condition.

27

Tree interpretation

Build a decision tree trace

Given a simple decision tree, trace how an input record reaches a final classification.

28

Runtime tradeoff

Compare tree and sorted list lookup

Explain when a balanced BST gives an advantage over a sorted ArrayList and when it does not.

29

Aliasing and null checks

Debug recursive tree mutation

Given code that accidentally drops a subtree, identify the assignment order that causes the loss.

30

DSA support

Plan a tree assignment

Create a tree assignment requiring diagrams, recursive implementation, traversal tests, and runtime explanation.

Need support with Unit 6?

Work through the concepts, code, edge cases, and runtime analysis with 1:1 guidance.