
This course includes our updated coding exercises so you can practice your skills as you learn.
See a demo
Explore binary trees as non-linear data structures and learn the at most two children rule. Master recursion, learn to write recursive functions, and prepare to implement binary trees in C++.
Define recursion as a process where a function calls itself until a base case is reached, transferring control and building results, illustrated through a practical example.
Trace recursion step by step by following main function calls, backtracking from the base case, and computing returns to reveal the output.
Explore how to write recursive functions by solving factorial with base and recursive cases, illustrating the general structure, base case, and recursive call, using pen-and-paper practice before coding.
Learn to convert iterative problems into recursive solutions, including printing one to n and binary tree problems. Explore base cases, argument passing, a driver function for recursion and backtracking.
Explore core tree terminologies, including root, leaves, internal and external nodes, parent and child relations, siblings, degree, level, height, depth, and the subtree concept.
Explore binary trees and binary search trees, and learn preorder, inorder, postorder, and level order traversals to visit each node.
Learn how to implement a binary tree using a linked-node approach in C++ (and other languages), with left and right pointers, root and leaves, and dynamic memory allocation.
Define a self-referential node structure in C++ to implement a binary tree, with left and right pointers and a data field; allocate memory via dynamic allocation.
Create a simple binary tree in C++ by defining a node structure, allocating memory, and manually linking six nodes with left and right pointers, using an online compiler.
Learn preorder traversal of binary trees by visiting the root first, then the left subtree, then the right subtree, with multiple examples and practical rules.
Learn how to compute post order traversal of binary trees by visiting the left subtree, then the right subtree, then the root, with step-by-step examples and patterns.
Master inorder traversal of binary trees by visiting the left subtree, then the root, then the right subtree, using examples with preorder and postorder.
Explains how to implement post order traversal in C++ using a recursive approach, visiting left subtree, right subtree, then root, with base case null, and demonstrates with binary tree examples.
Explore a concrete implementation of pre-order traversal in C++, printing the root first and then recursively visiting the left and right subtrees.
Demonstrates a concrete in-order traversal implementation in C++, visiting the left subtree, printing the root between left and right, then traversing the right subtree.
This lecture presents a recursive algorithm to compute a binary tree’s height by taking the maximum of left and right subtree heights and adding one, with a null base case.
Implement a recursive algorithm to sum all nodes in a binary tree by adding the root data to the sums of left and right subtrees, with zero as base case.
Trace a recursive function to sum all tree nodes by adding the root data to the sums of its left and right subtrees, returning zero for null nodes.
Learn to derive a recursive algorithm to find the maximum element in a binary tree, using a custom max function and a three-way comparison in C++.
Convert the binary tree maximum-finding algorithm to find the minimum by swapping comparisons and updating initialization with a high value near infinity to ensure correct minimum logic.
Explore level order traversal without a queue using a brute-force method: compute the tree height, iterate levels, and print nodes at each level with a recursive printLevel function.
Learn how to derive level order traversal with a queue to traverse a tree level by level, using push, pop, and a level-separating null marker.
Learn to implement level order traversal using a queue to process tree nodes, pushing root and its left and right children, and using a level-end marker to print each level.
Learn to compute the left and right views of a binary tree using level-order traversal, printing the leftmost or rightmost node at each level by prioritizing left or right children.
Learn to perform vertical order traversal of a binary tree using a hash map to group node values by vertical columns, then print each column.
Trace vertical order traversal of a binary tree by mapping nodes to indices, starting at root index zero and visiting left and right subtrees while storing values in a map.
Print all leaf nodes of a binary tree using a traversal algorithm, such as vertical order, guided by the leaf condition and the tree height to reach the last level.
Print the cousins of a given node in a binary tree using a modified traversal. Identify the target level, ignore its siblings, and print the remaining nodes at that level.
Discover how a binary search tree, a binary tree with at most two children per node, keeps left values smaller and right values larger, yielding ascending order on in-order traversal.
Master counting nodes in a binary tree using recursion, starting from the root and aggregating left and right subtrees.
Define a node struct with left and right pointers, use malloc for dynamic memory in C, create a new node, and count tree nodes recursively with a null base case.
Learn to determine whether two binary trees are identical by comparing corresponding nodes recursively, ensuring roots, left subtrees, and right subtrees match.
Implement a recursive is-identical function to determine if two binary trees are identical by comparing root data and recursively checking left and right subtrees. Return 1 if identical, 0 otherwise.
Mirror a binary tree by swapping every left and right node while keeping the root unchanged, using a temporary variable for each swap, and verify with inorder traversal.
Mirror a binary tree in place by swapping left and right children, using in-order traversal to show before and after states with a recursive, root-null base-case.
Welcome to my crash course on Binary Trees which is one of the pivotal concepts in Advanced Data Structures and Algorithms!
In this course, we'll learn
1. What is Recursion? (Recursion is a prerequisite and a very useful tools to implement binary Trees)
2. Tricks to write recursive functions!
3. Tracing recursive functions
4. Converting an iterative solution to a recursive solution.
5. Basic Tree terminologies
6. Implementation of Binary Trees using LinkedLists
7. The basic traversal algorithms - How to code them?
8. Finding the height of the Tree - Algorithm, Code, Tracing.
9. How to find the Maximum and Minimum elements of a tree?
10. Finding the sum of all nodes in a tree
11. Level Order Traversal - Using Brute Force Approach and Improved Solution using Queue Data Structure.
12. Printing the left View of a Binary Tree
13. Printing the Right View of a Binary Tree
14. Understanding Hashmaps in C++ STL
15. Implementation of Vertical Order Traversals using Hashmaps
16. Printing all the leaf nodes of a Binary Tree using any one of the Traversal algorithms.
17. Printing the cousin nodes of a node in a Binary Tree.
18. Binary Search Trees - Explanation
Through these standard Tree problems, you'll easily be familiarized on implementing Trees in C or C++. Some ideas were also provided to implement the same using some other languages using Python too. So, if you're not comfortable in using C or C++, It's not a problem :)