A Binary Tree is a non-linear Data Structure.
Any node can have a maximum of two child nodes (which is why it's called a binary tree).
Let's look at how to organise this set of data into a Binary Tree.
| 13 | 7 | 5 | 9 | 11 | 18 | 16 | 21 |
Here is the above array sorted visually into a binary tree:
If you have studied singular linked lists, you will recall that nodes in a list of nodes contain data and a pointer to the next node in the list.
Binary trees are similar but each node has:
We can imagine that if either pointer does not point to another node then it just references null or something equivalent to that.
Let's take another look at the binary tree above.
Use the simulator to create a binary tree for the following set of data:
100 , 56 , 34 , 77 , 120 , 115 , 113 , 1 , 200 , 33
As you are doing it, try to predict where each noce will be placed. How good are your predictions?!
Using a piece of paper and a pencil (or digitally if you can), construct a binary tree using the following data:
"Kansas", "Idaho", "Texas", "Massachusets", "New York", "Albaquerque", "Boston", "Wyoming", "Tallahassee", "Denver"
Annotate your tree to clearly identify:
Submit your annotated tree as instructed.
The following video will explain how to set up a Binary Tree in Python and how to search a Binary Tree for an item.
For Topic 5, this is just for background knowledge. You are not expected to code a binary tree in Topic 5 (Paper 1).
Make sure you review the Course Guide to fully appreciate what you need to know in this topic!