{"id":20287052,"url":"https://github.com/codewithsegnet/binary_trees","last_synced_at":"2025-03-04T04:14:26.168Z","repository":{"id":147741742,"uuid":"609370979","full_name":"CodewithSegNet/binary_trees","owner":"CodewithSegNet","description":"Project","archived":false,"fork":false,"pushed_at":"2023-03-04T02:00:45.000Z","size":21,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-14T08:23:35.526Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CodewithSegNet.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-03-04T01:21:51.000Z","updated_at":"2023-03-04T01:24:24.000Z","dependencies_parsed_at":"2023-08-28T13:54:21.193Z","dependency_job_id":null,"html_url":"https://github.com/CodewithSegNet/binary_trees","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodewithSegNet%2Fbinary_trees","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodewithSegNet%2Fbinary_trees/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodewithSegNet%2Fbinary_trees/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodewithSegNet%2Fbinary_trees/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CodewithSegNet","download_url":"https://codeload.github.com/CodewithSegNet/binary_trees/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241780497,"owners_count":20019061,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-14T14:37:59.094Z","updated_at":"2025-03-04T04:14:26.150Z","avatar_url":"https://github.com/CodewithSegNet.png","language":"C","readme":"# C - Binary trees\n\nThis was a partner project in which we learned about the details, advantages,\nand disadvantages of using trees as data structures. We learned about how to\nqualify trees as well as how to traverse them. Throughout the project, we\nimplemented binary, binary search, AVL, and Max Binary Heap trees.\n\n## Tests :heavy_check_mark:\n\n* [tests](./tests): Folder of test files for all tasks. Provided by Holberton\nSchool.\n\n## Helper File :raised_hands:\n\n* [binary_tree_print.c](./binary_tree_print.c): C function that prints binary\ntrees in a pretty way.\n\n## Header File :file_folder:\n\n* [binary_trees.h](./binary_trees.h): Header file containing definitions and\nprototypes for all types and functions written for the project.\n\nData Structures\n```\nstruct binary_tree_s\n{\n    int n;\n    struct binary_tree_s *parent;\n    struct binary_tree_s *left;\n    struct binary_tree_s *right;\n};\n\ntypedef struct binary_tree_s binary_tree_t;\ntypedef struct binary_tree_s bst_t;\ntypedef struct binary_tree_s avl_t;\ntypedef struct binary_tree_s heap_t;\n```\n\nFunction Prototypes\n\n| File                             | Prototype                                                                                        |\n| -------------------------------- | ------------------------------------------------------------------------------------------------ |\n| `binary_tree_print.c`            | `void binary_tree_print(const binary_tree_t *tree)`                                              |\n| `0-binary_tree_node.c`           | `binary_tree_t *binary_tree_node(binary_tree_t *parent, int value);`                             |\n| `1-binary_tree_insert_left.c`    | `binary_tree_t *binary_tree_insert_left(binary_tree_t *parent, int value);`                      |\n| `2-binary_tree_insert_right.c`   | `binary_tree_t *binary_tree_insert_right(binary_tree_t *parent, int value);`                     |\n| `3-binary_tree_delete.c`         | `void binary_tree_delete(binary_tree_t *tree);`                                                  |\n| `4-binary_tree_is_leaf.c`        | `int binary_tree_is_leaf(const binary_tree_t *node);`                                            |\n| `5-binary_tree_is_root.c`        | `int binary_tree_is_root(const binary_tree_t *node);`                                            |\n| `6-binary_tree_preorder.c`       | `void binary_tree_preorder(const binary_tree_t *tree, void (*func)(int));`                       |\n| `7-binary_tree_inorder.c`        | `void binary_tree_inorder(const binary_tree_t *tree, void (*func)(int));`                        |\n| `8-binary_tree_postorder.c`      | `void binary_tree_postorder(const binary_tree_t *tree, void (*func)(int));`                      |\n| `9-binary_tree_height.c`         | `size_t binary_tree_height(const binary_tree_t *tree);`                                          |\n| `10-binary_tree_depth.c`         | `size_t binary_tree_depth(const binary_tree_t *tree);`                                           |\n| `11-binary_tree_size.c`          | `size_t binary_tree_size(const binary_tree_t *tree);`                                            |\n| `12-binary_tree_leaves.c`        | `size_t binary_tree_leaves(const binary_tree_t *tree);`                                          |\n| `13-binary_tree_nodes.c`         | `size_t binary_tree_nodes(const binary_tree_t *tree);`                                           |\n| `14-binary_tree_balance.c`       | `int binary_tree_balance(const binary_tree_t *tree);`                                            |\n| `15-binary_tree_is_full.c`       | `int binary_tree_is_full(const binary_tree_t *tree);`                                            |\n| `16-binary_tree_is_perfect.c`    | `int binary_tree_is_perfect(const binary_tree_t *tree);`                                         |\n| `17-binary_tree_sibling.c`       | `binary_tree_t *binary_tree_sibling(binary_tree_t *node);`                                       |\n| `18-binary_tree_uncle.c`         | `binary_tree_t *binary_tree_uncle(binary_tree_t *node);`                                         |\n| `100-binary_trees_ancestor.c`    | `binary_tree_t *binary_trees_ancestor(const binary_tree_t *first, const binary_tree_t *second);` |\n| `101-binary_tree_levelorder.c`   | `void binary_tree_levelorder(const binary_tree_t *tree, void (*func)(int));`                     |\n| `102-binary_tree_is_complete.c`  | `int binary_tree_is_complete(const binary_tree_t *tree);`                                        |\n| `103-binary_tree_rotate_left.c`  | `binary_tree_t *binary_tree_rotate_left(binary_tree_t *tree);`                                   |\n| `104-binary_tree_rotate_right.c` | `binary_tree_t *binary_tree_rotate_right(binary_tree_t *tree);`                                  |\n| `110-binary_tree_is_bst.c`       | `int binary_tree_is_bst(const binary_tree_t *tree);`                                             |\n| `111-bst_insert.c`               | `bst_t *bst_insert(bst_t **tree, int value);`                                                    |\n| `112-array_to_bst.c`             | `bst_t *array_to_bst(int *array, size_t size);`                                                  |\n| `113-bst_search.c`               | `bst_t *bst_search(const bst_t *tree, int value);`                                               |\n| `114-bst_remove.c`               | `bst_t *bst_remove(bst_t *root, int value);`                                                     |\n| `120-binary_tree_is_avl.c`       | `int binary_tree_is_avl(const binary_tree_t *tree);`                                             |\n| `121-avl_insert.c`               | `avl_t *avl_insert(avl_t **tree, int value);`                                                    |\n| `122-array_to_avl.c`             | `avl_t *array_to_avl(int *array, size_t size);`                                                  |\n\n## Tasks :page_with_curl:\n\n* **0. New node**\n  * [0-binary_tree_node.c](./0-binary_tree_node.c): C function that creates a\n  binary tree node with a given parent and value.\n  * Returns a pointer to the new node, or `NULL` on failure.\n\n* **1. Insert left**\n  * [1-binary_tree_insert](./1-binary_tree_insert): C function that inserts a\n  node as the left-child of another.\n  * Returns a pointer to the new node, or `NULL` on failure.\n  * If the given `parent` already contains a left node, the new node takes its\n  place and the old left-child becomes the left-child of the new node.\n\n* **2. Insert right**\n  * [2-binary_tree_insert_right.c](./2-binary_tree_insert_right.c): C function that\n  inserts a node as the right-child of another.\n  * Returns a pointer to the new node, or `NULL` on failure.\n  * If the given `parent` already contains a right node, the new node takes its\n  place and the old right-child becomes the right-child of the new node.\n\n* **3. Delete**\n  * [3-binary_tree_delete.c](./3-binary_tree_delete.c): C function that deletes\n  an entire binary tree.\n\n* **4. Is leaf**\n  * [4-binary_tree_is_leaf.c](./4-binary_tree_is_leaf.c): C function that checks\n  if a given node is a leaf.\n  * Returns `1` if the node is a leaf, `0` otherwise.\n\n* **5. Is root**\n  * [5-binary_tree_is_root.c](./5-binary_tree_is_root.c): C function that checks\n  if a given node is a root.\n  * Returns `1` if the node is a root, `0` otherwise.\n\n* **6. Pre-order traversal**\n  * [6-binary_tree_preorder.c](./6-binary_tree_preorder.c): C function that\n  traverses a tree using pre-order traversal.\n\n* **7. In-order traversal**\n  * [7-binary_tree_inorder.c](./7-binary_tree_inorder.c): C function that\n  traverses a tree using in-order traversal.\n\n* **8. Post-order traversal**\n  * [8-binary_tree_postorder.c](./8-binary_tree_postorder.c): C function that\n  traverses a tree using post-order traversal.\n\n* **9. Height**\n  * [9-binary_tree_height.c](./9-binary_tree_height.c): C function that returns\n  the height of a binary tree.\n\n* **10. Depth**\n  * [10-binary_tree_depth.c](./10-binary_tree_depth.c): C function that returns\n  the depth of a given node in a binary tree.\n\n* **11. Size**\n  * [11-binary_tree_size.c](./11-binary_tree_size.c): C function that returns\n  the size of a binary tree.\n\n* **12. Leaves**\n  * [12-binary_tree_leaves.c](./12-binary_tree_leaves.c): C function that returns\n  the number of leaves in a binary tree.\n\n* **13. Nodes**\n  * [13-binary_tree_nodes.c](./13-binary_tree_nodes.c): C function that returns\n  the number of nodes in a binary tree with at least one child.\n\n* **14. Balance factor**\n  * [14-binary_tree_balance.c](./14-binary_tree_balance.c): C function that\n  returns the balance factor of a binary tree.\n\n* **15. Is full**\n  * [15-binary_tree_is_full.c](./15-binary_tree_is_full.c): C function that\n  checks if a binary tree is full.\n  * Returns `1` if a tree is full, `0` otherwise.\n\n* **16. Is perfect**\n  * [16-binary_tree_is_perfect.c](./16-binary_tree_is_perfect.c): C function\n  that checks if a binary tree is perfect.\n  * Returns `1` if a tree is perfect, `0` otherwise.\n\n* **17. Sibling**\n  * [17-binary_tree_sibling.c](./17-binary_tree_sibling.c): C function that\n  returns a pointer to the sibling of a given node in a binary tree.\n  * Returns `NULL` if no sibling is found.\n\n* **18. Uncle**\n  * [18-binary_tree_uncle.c](./18-binary_tree_uncle.c): C function that\n  returns a pointer to the uncle of a given node in a binary tree.\n  * Returns `NULL` if no uncle is found.\n\n* **19. Lowest common ancestor**\n  * [100-binary_trees_ancestor.c](./100-binary_trees_ancestor.c): C function\n  that returns a pointer to the lowest common ancestor node of two given nodes\n  in a binary tree.\n  * Returns `NULL` if no common ancestor is found.\n\n* **20. Level-order traversal**\n  * [101-binary_tree_levelorder.c](./101-binary_tree_levelorder.c): C function\n  that traverses a binary tree using level-order traversal.\n\n* **21. Is complete**\n  * [102-binary_tree_is_complete.c](./102-binary_tree_is_complete.c): C function\n  that checks if a binary tree is complete.\n  * Returns `1` if the tree is complete, `0` otherwise.\n\n* **22. Rotate left**\n  * [103-binary_tree_rotate_left.c](./103-binary_tree_rotate_left.c): C function\n  that performs a left-rotation on a binary tree.\n  * Returns a pointer to the new root node of the tree after rotation.\n\n* **23. Rotate right**\n  * [104-binary_tree_rotate_right.c](./104-binary_tree_rotate_right.c): C function\n  that performs a right-rotation on a binary tree.\n  * Returns a pointer to the new root node of the tree after rotation.\n\n* **24. Is BST**\n  * [110-binary_tree_is_bst.c](./110-binary_tree_is_bst.c): C function that\n  checks if a binary tree is a valid binary search tree.\n  * Returns `1` if the tree is a valid BST, `0` otherwise.\n\n* **25. BST - Insert**\n  * [111-bst_insert.c](./111-bst_insert.c): C function that inserts a value into\n  a binary search tree.\n  * Returns a pointer to the new node, or `NULL` on failure.\n  * If the tree is `NULL`, the value becomes the root node.\n  * The value is ignored if it is already present in the tree.\n\n* **26. BST - Array to BST**\n  * [112-array_to_bst.c](./112-array_to_bst.c): C function that builds a binary\n  search tree from an array.\n  * Returns a pointer to the root node of the created tree, or `NULL` on failure.\n\n* **27. BST - Search**\n  * [113-bst_search.c](./113-bst_search.c): C function that searches for a value\n  in a binary search tree.\n  * If the value is matched in the BST, returns a pointer to the matched node.\n  * Otherwise, returns `NULL`.\n\n* **28. BST - Remove**\n  * [114-bst_remove.c](./114-bst_remove.c): C function that removes a node from\n  a binary search tree.\n  * Returns a pointer to the new root node of the tree after deletion.\n  * If the node to be deleted has two children, it is replaced with its first\n  in-order successor.\n\n* **29. Big O #BST**\n  * [115-O](./115-O): Text file containing the average time complexities of\n  binary search tree operations (one answer per line):\n    * Inserting the value `n`.\n    * Removing the node with the value `n`.\n    * Searching for a node in a BST of size `n`.\n\n* **30. Is AVL**\n  * [120-binary_tree_is_avl.c](./120-binary_tree_is_avl.c): C function that checks if\n  a binary tree is a valid AVL tree.\n  * If the tree is a valid AVL tree, returns `1`.\n  * Otherwise, returns `0`.\n\n* **31. AVL - Insert**\n  * [121-avl_insert.c](./121-avl_insert.c): C function that inserts a value in an AVL tree.\n  * Returns a value to the inserted node, or `NULL` on failure.\n\n* **32. AVL - Array to AVL**\n  * [122-array_to_avl.c](./122-array_to_avl.c): C function that builds an AVL tree\n  from an array.\n  * Returns a pointer to the root node of the created AVL tree, or `NULL` on failure.\n  * Ignores duplicate values.\n\n* **35. Big O #AVL Tree**\n  * [125-O](./125-O): Text file containing the average time complexities of AVL tree\n  opeartions (one answer per line):\n    * Inserting the value `n`.\n    * Removing the node with the value `n`.\n    * Searching for a node in an AVL tree of size `n`.\n\n* **41. Big O #Binary Heap**\n  * [135-O](./135-O): Text file containing the average time complexities of\n  binary heap opeartions (one answer per line):\n    * Inserting the value `n`.\n    * Extracting the root node.\n    * Searching for a node in a binary heap of size `n`.\n\n## Authors :black_nib:\n\n* __Olusegun Emmanuel__ \u003c[codewithsegnet](https://github.com/codewithsegnet)\u003e\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodewithsegnet%2Fbinary_trees","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodewithsegnet%2Fbinary_trees","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodewithsegnet%2Fbinary_trees/lists"}