This project explores and applies the concept of binary tree data structures.
At the end of this project students should be able to explain to anyone, without the help of Google:
- What is a binary tree
- What is the difference between a binary tree and a Binary Search Tree
- What is the possible gain in terms of time complexity compared to linked lists
- What are the depth, the height, the size of a binary tree
- What are the different traversal methods to go through a binary tree
- What is a complete, a full, a perfect, a balanced binary tree
- Read Binary tree -> note the first line:
Not to be confused with B-tree.
- Also read Data Structure and Algorithms - Tree, Tree Traversal and Binary Search Tree
- Watch this video
- Allowed editors:
vi
,vim
,emacs
- All your files will be compiled on Ubuntu 14.04 LTS
- Your programs and functions will be compiled with
gcc 4.8.4
using the flags-Wall
-Werror
-Wextra
and-pedantic
- All your files should end with a new line
- A
README.md
file, at the root of the folder of the project, is mandatory - Your code should use the
Betty
style. It will be checked using betty-style.pl and betty-doc.pl - You are not allowed to use global variables
- No more than 5 functions per file
- You are allowed to use the standard library
- In the following examples, the
main.c
files are showed as examples. You can use them to test your functions, but you don't have to push them to your repo (if you do we won't take them into account). We will use our ownmain.c
files at compilation. Ourmain.c
files might be different from the one showed in the examples - The prototypes of all your functions should be included in your header file called
binary_trees.h
- Don't forget to push your header file
- All your header files should be include guarded
Please use the following data structures and types for binary trees. Don't forget to include them in your header file.
/**
* struct binary_tree_s - Binary tree node
*
* @n: Integer stored in the node
* @parent: Pointer to the parent node
* @left: Pointer to the left child node
* @right: Pointer to the right child node
*/
struct binary_tree_s
{
int n;
struct binary_tree_s *parent;
struct binary_tree_s *left;
struct binary_tree_s *right;
};
typedef struct binary_tree_s binary_tree_t;
typedef struct binary_tree_s bst_t;
typedef struct binary_tree_s avl_t;
typedef struct binary_tree_s heap_t;
To match the examples in the tasks, you are given this function This function is used only for visualisation purpose. You don't have to push it to your repo. It may not be used during the correction
Task # | Type | Short description | File name and link |
---|---|---|---|
0 | Mandatory | Write a function that creates a binary tree node
|
0-binary_tree_node.c |
1 | Mandatory | Write a function that inserts a node as the left-child of another node
|
1-binary_tree_insert_left.c |
2 | Mandatory | Write a function that inserts a node as the right-child of another node
|
2-binary_tree_insert_right.c |
3 | Mandatory | Write a function that deletes an entire binary tree
|
3-binary_tree_delete.c |
4 | Mandatory | Write a function that checks if a node is a leaf
|
4-binary_tree_is_leaf.c |
5 | Mandatory | Write a function that checks if a given node is a root
|
5-binary_tree_is_root.c |
6 | Mandatory | Write a function that goes through a binary tree using pre-order traversal
|
6-binary_tree_preorder.c |
7 | Mandatory | Write a function that goes through a binary tree using in-order traversal
|
7-binary_tree_inorder.c |
8 | Mandatory | Write a function that goes through a binary tree using post-order traversal
|
8-binary_tree_postorder.c |
9 | Mandatory | Write a function that measures the height of a binary tree
|
9-binary_tree_height.c |
10 | Mandatory | Write a function that measures the depth of a node in a binary tree
|
10-binary_tree_depth.c |
11 | Mandatory | Write a function that measures the size of a binary tree
|
11-binary_tree_size.c |
12 | Mandatory | Write a function that counts the leaves in a binary tree
|
12-binary_tree_leaves.c |
13 | Mandatory | Write a function that counts the nodes with at least 1 child in a binary tree
|
13-binary_tree_nodes.c |
14 | Mandatory | Write a function that measures the balance factor of a binary tree
|
14-binary_tree_balance.c |
15 | Mandatory | Write a function that checks if a binary tree is full
|
15-binary_tree_is_full.c |
16 | Mandatory | Write a function that checks if a binary tree is perfect
|
16-binary_tree_is_perfect.c |
17 | Mandatory | Write a function that finds the sibling of a node
|
17-binary_tree_sibling.c |
18 | Mandatory | Write a function that finds the uncle of a node
|
18-binary_tree_uncle.c |