Stage 4 · Lesson 9 of 10
Trees at a first look
A is a set of nodes (items) where each node has children and exactly one parent. The only is the root, the node at the top. Folders on your disk, the HTML of a web page and an organisation chart are all trees.
A binary tree gives each node at most two children. A tree also keeps smaller values on the left and larger ones on the right. So finding a value takes O(log n) steps when the tree is balanced (evenly filled), and O(n) when it degrades into a long chain.
Most tree code uses : handle the node, then call the same on each child. At this stage, aim to build a small binary search tree and walk it, not to master balancing.
A question to check yourself, an AI practice session and 2 cheat sheet entries come when you add the roadmap to your account. Add it
Resources for this stage
Start with· follow one of these
- CoursePaidGrokking Data Structures & Algorithms for Coding Interviews
Design Gurus · Beginner · Subscription
Each structure built from first principles, with solutions in Python, Java, C++, JavaScript and C#
- CourseFreeCS50: Introduction to Computer Science
Harvard University · Beginner
Free: weeks 3 and 5 cover searching, sorting, linked lists, hash tables and trees
Practise
Keep handy
Also worth your time
Time and space complexity worked through five common algorithms