Look for 3 by comparing at each node and report the result.
Acceptance criteria
- 1.#out should show found.
DSA Tutorial · Trees
These 10 tasks go with the Binary Search Trees chapter. 5 of them ask you to build something small from scratch; 5 give you code that is already broken and ask you to work out why. Set aside about 90 minutes for the whole set, though you can do them in any order.
Nothing here is marked by a person. When you press Submit, the editor checks your code against the points listed under each task and tells you straight away what passed and what didn't (you need a free account to submit). If you get stuck, there are hints, and a worked solution once you've had a go. The first 2 tasks are free; the rest are part of the practice plan.
If it's been a while since you read the chapter, here is how it starts: “A binary search tree is a sorted array that is cheap to insert into. Its whole advantage disappears the moment it becomes unbalanced, which happens on the most ordinary input there is: sorted data.” .
1.Search a BSTexercise · easy · 10 min
Look for 3 by comparing at each node and report the result.
Passes when: #out should show found.
2.In-order gives sortedexercise · easy · 10 min · practice plan
Walk in order and confirm the values come out ascending.
Passes when: #out should show 1-2-3.
3.Validate with boundsexercise · easy · 10 min · practice plan
Check the BST property using a range and report valid or broken.
Passes when: #out should show valid.
4.Find the smallestexercise · easy · 10 min · practice plan
Walk left to the end and show the smallest value.
Passes when: #out should show smallest 1.
5.Degenerate treeexercise · medium · 10 min · practice plan
Insert ascending values and report the resulting shape.
Passes when: #out should show a chain.
6.Fix the search going the wrong waybug fix · easy · 8 min
Comparing backwards walks away from the target.
Passes when: #out should show found.
7.Fix validation checking only childrenbug fix · medium · 8 min · practice plan
Comparing with the immediate children accepts a tree that breaks the rule deeper down.
Passes when: #out should show broken.
8.Fix the smallest read from the rootbug fix · easy · 8 min · practice plan
The root is not the smallest; the leftmost node is.
Passes when: #out should show smallest 1.
9.Fix the largest walked leftbug fix · easy · 8 min · practice plan
The largest value sits at the rightmost node.
Passes when: #out should show largest 3.
10.Fix the bound passed unchangedbug fix · easy · 8 min · practice plan
Failing to narrow the range on recursion lets invalid values through.
Passes when: #out should show broken.
Between them these tasks cover BST property, Validation and Insertion.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.