1.Fix any tree T on 10 vertices. Draw the recursion tree of the algorithm Find-size-node when run on the input T with a being the root of T. Can you use this to give a bound on the running time of T?
2. Consider the following problem. Check-BST • Input: A binary tree T • Output: 1 if T is a binary search tree, and 0 otherwise. Give an efficient algorithm for this problem.
3.Give a recursive algorithm for the following problem. BST-In-Order • Input: A BST T • Output: An array containing the keys of T in increasing order. What is the running time of your algorithm?
1.Fix any tree T on 10 vertices. Draw the recursion tree of the algorithm Find-size-node when...
Recall that in a binary search tree, at every node, all elements to the left of the node have a smaller key, and all elements to the right of a node have a larger key. Write a program called that takes two parameters: a pointer to a binary search tree node, and an int parameter called min which will print all the elements bigger than the specified value, min. Your program should allow the user to enter data (integer) from...
2. Write a recursive algorithm which computes the number of nodes in a general tree. 3. Show a tree achieving the worst-case running time for algorithm depth. 4. Let T be a tree whose nodes store strings. Give an efficient algorithm that computes and prints, for every node v of T, the string stored at v and the height of the subtree rooted at v. Hin Consider 'decorating' the tree, and add a height field to each node (initialized to...
Binary Search Tree Part A: The code attached in this document is a sample code to demonstrate insert operation in binary search tree. Please fill in the missing part for the insert method to make the program work. The expected output should be as follows. 20 30 40 50 60 70 80 Part B: Find Lowest Common Ancestor (LCA) of a Binary Search Tree. According to WikiPedia definition , The lowest common ancestor is defined between two nodes v and...
Using Racket Recursion, tail-recursion, high-order functions and functional programming. 1. Modify our filter function so that it is tail-recursive. You may use the letrec form but do not use any additional forms and functions besides those we've talked about in class. (define filter (lambda (input-list func) (cond ((null? input-list) '()) ((func (car input-list)) (cons (car input-list) (filter (cdr input-list) func))) (else (filter (cdr input-list) func))))) 2. Test your filter function on '(25 -22 44 56...
Using C Please comment Part 1: BST Create a link based Binary Search tree composed of a Node and a Tree struct. You should have a header file, BST.h, with the following: o Node struct containing left, right, and parent pointers, in addition to holding an Data struct value Tree struct containing a pointer to the root of the tree A function declaration for a function that allocates a tree, and initializes the root to NULL o o o A...
Let T be a proper binary tree. Given a node v ∈ T, the imbalance of v, denoted imbalance(v), is defined as the difference, in absolute value, between the number of leaves of the left subtree of v and the number of leaves of the right subtree of v. (If v is a leaf, then imbalance(v) is defined to be 0.) Define imbalance(T) = maxv∈T imbalance(v). (a) Provide an upper bound to the imbalance of a proper binary tree with...
8. You are given a binary tree T (V,E) with a designated root node. In addition, there is an array z with a value for each node in V. Define a new array z as follows: for each u e V, zu is the maximum of the -values associated with u's descendants. Give a linear-time algorithm which calculates the entire z array. (7 points)
From the code below with Binary Search Tree recurrence T(n)=? use the recursion method and substitution method to solve the recurrence. Find the tightest bound g(n) for T(n) you can for which T(n)= O(g(n)). Explain your answer and use recursion tree method. void insert(int data) { struct node *tempNode = (struct node*) malloc(sizeof(struct node)); struct node *current; struct node *parent; tempNode->data = data; tempNode->leftChild = NULL; tempNode->rightChild = NULL; //if tree is empty if(root == NULL) { root = tempNode;...
A heap can be encoded either as an array, or as a full binary tree. For this question, write a function that takes the array representation of a heap and outputs its binary tree representation. More specifically, you should write a function with the specifications given below. Specifications for the function: # def arrayToTree(A, j): # input: array A representing a heap, an index j in [0:len(A)] # output: a Node object storing the heap with root j in the...
2. (10 pts) Let T be a B-tree with a minimum degree (minimum branching factor) of t that holds n keys. Write the most efficient procedure you can to print the keys of T in sorted order. Then analyze the time complexity of your algorithm. Hint: Extend the procedure for inorder traversal of BST. 2. (10 pts) Let T be a B-tree with a minimum degree (minimum branching factor) of t that holds n keys. Write the most efficient procedure...