4) ·Wha t is an AVL Tree? How do vL tree SiVe 5) What is a recursive function? u
ID: 3906044 • Letter: 4
Question
4) ·Wha t is an AVL Tree? How do vL tree SiVe 5) What is a recursive function? using a op yheh reaeslets Programs (Total: 50 Marks) Write a C++ Program to demonstrate Queue operations using linked list (Insert Element into the Queue, Delete Element from the Queue, Traverse the Queue? 1) (15 Marks) 2) Write a C++ Program to Implement the operation Inorder, Preorder, Postorder traverse in a Binary Search Tree (BST)? (15 Marks) #'s in) (5 Marks) ds (15 Marks) ) a) Write a C++ program for the structure of a node? b) Write a C++ program to reverse a linked list? isplay ucExplanation / Answer
4)Answer:
AVL Tree:
AVL tree is a self-balancing Binary Search Tree (BST) where the difference between heights of left and right subtrees cannot be more than one for all nodes.
It is a balanced binary search tree where the height of the two subtrees (children) of a node differs by at most one. Look-up, insertion, and deletion are O(log n), where n is the number of nodes in the tree.
In an AVL tree, every node maintains a extra information known as balance factor
Balance factor of a node is the difference between the heights of left and right subtrees of that node. The balance factor of a node is calculated either height of left subtree - height of right subtree (OR) height of right subtree - height of left subtree. In the following explanation, we are calculating as follows...
Balance factor = heightOfLeftSubtree - heightOfRightSubtree
5)Answer:
recursive function?:
A recursive function is a function that calls itself during its execution. This enables the function to repeat itself several times, outputting the result and the end of each iteration. Below is an example of a recursive function.
function Count (integer N)
if (N <= 0) return "Must be a Positive Integer";
if (N > 9) return "Counting Completed";
else return Count (N+1);
end function
The function Count() above uses recursion to count from any number between 1 and 9, to the number 10. For example, Count(1) would return 2,3,4,5,6,7,8,9,10. Count(7) would return 8,9,10. The result could be used as a roundabout way to subtract the number from 10.
Recursive functions are common in computer science because they allow programmers to write efficient programs using a minimal amount of code. The downside is that they can cause infinite loops and other unexpected results if not written properly. For example, in the example above, the function is terminated if the number is 0 or less or greater than 9. If proper cases are not included in the function to stop the execution, the recursion will repeat forever, causing the program to crash, or worse yet, hang the entire computer system
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.