seems to work

This commit is contained in:
ldlda committed 2024-10-23 22:40:17 +07:00
1 parent 8aa73bde5e
commit 2930b7217d
9 files changed
+280 -105

No files matched your search

+27
View File
@@ -0,0 +1,27 @@
# shit
## ex 1
- Implement one of the three elementary sorting algorithms (Selection, Bubble,
or Insert Sort) in C/C++.
- Implement the selected sorting algorithm using a recursive function.
- Implement the selected sorting algorithm using a data structure (List, Stack,
or Queue). Justify your choice.
## ex 2
A binary tree can sort n elements of an array of data. First, create a complete binary tree with all leaves at one level, whose height h = (log2 n) + 1, and store all array elements in the first n leaves. In each empty leaf, store an element E greater than any element in the array.
Figure (a) shows an example for data = {8, 20, 41, 7, 2}, h = (log2(5)) + 1 = 3, and E = 42. Then, starting from the bottom of the tree, assign the minimum of its two children values to each node, as in Figure (b), so that the smallest element emin in the tree is assigned to the root.
If a leaf node is to be removed, this node is replaced by a new node with the same value as its parent node.
If a node is added to the tree, it will be a leaf node. Normally, a node with value E is replaced with a new value. It’s necessary to verify recursively all values of its parent and make any possible modification, if necessary, so that the tree rules are respected.
Implement this tree structure in C/C++ with the necessary functions.
- write a function to initialize an array with n random values
- write a function to build this binary tree with the above definition with any data structure learned in lectures
- write a function to display the tree information
- write a function to search an input value using recursion. If found, display all the subtrees with the found node as the root of this subtree or return -1.
- write a function to insert new nodes into the tree and another one to remove nodes from the tree