Quiz 1

¡Supera tus tareas y exámenes ahora con Quizwiz!

Consider the below left-left rotation pseudo code where the node contains value pointers to left, right child nodes and a height value and Height() function returns height value stored at a particular node. avltree leftrotation(avltreenode z): avltreenode w =x-left x-left=w-right w-right=x x-height=max(Height(x-left),Height(x-right))+1 w-height=max(missing)+1 return w What is missing?

Height(w-left), x-height

What are the worst case and average case complexities of a binary search tree?

O(n), O(logn)

What does the following piece of code do? public void func(Tree root) { func(root.left()); func(root.right()); System.out.println(root.data()); }

Post-order traversal

What does the following piece of code do? public void func(Tree root) { System.out.println(root.data()); func(root.left()); func(root.right()); }

Preorder traversal

What maximum difference in heights between the leaves of an AVL tree is possible?

log(n) where n is the number of nodes

What is the maximum height of an AVL tree with p nodes?

log(p)

How will you find the maximum element in a binary search tree?

public void max(Tree root) { while(root.right() != null) { root = root.right(); } System.out.println(root.data()); }

To restore the AVL property after inserting an element, we start at the insertion point and move towards root of that tree. is this statement true?

true

What is the maximum height of any AVL-tree with 7 nodes? Assume that the height of a tree with a single node is 0.

- 3 Solution: For finding maximum height, the nodes should be minimum at each level. Assuming height as 2, minimum number of nodes required: N(h) = N(h-1) + N(h-2) + 1 N(2) = N(1) + N(0) + 1 = 2 + 1 + 1 = 4. It means, height 2 is achieved using minimum 4 nodes. Assuming height as 3, minimum number of nodes required: N(h) = N(h-1) + N(h-2) + 1 N(3) = N(2) + N(1) + 1 = 4 + 2 + 1 = 7. It means, height 3 is achieved using minimum 7 nodes. Therefore, using 7 nodes, we can achieve maximum height as 3. Following is the AVL tree with 7 nodes and height 3.

What is the specialty about the in-order traversal of a binary search tree?

It traverses in an increasing order

Consider the pseudo code: int avl(binarysearchtree root): if(not root) return 0 left_tree_height = avl(left_of_root) if(left_tree_height== -1) return left_tree_height right_tree_height= avl(right_of_root) if(right_tree_height==-1) return right_tree_height Does the above code can check if a binary search tree is an AVL tree?

NO

Which of the following is false about a binary search tree?

None of the mentioned - the following are all true a) The left child is always lesser than its parent b) The right child is always greater than its parent c) The left and right sub-trees should also be binary search trees

Which of the below diagram is following AVL tree property?

The property of AVL tree is it is height balanced tree with difference of at most 1 between left and right subtrees. - only 2

Which of the following is not an advantage of trees?

Undo/Redo operations in a notepad

What is an AVL tree?

a tree which is balanced and is a height balanced tree

True statements about AVL tree are

a) It is a binary search tree. b) Left node and right node differ in height by at most 1 unit c) Worst case time complexity is O(log 2 n)

Given an empty AVL tree, how would you construct AVL tree when a set of numbers are given without performing any rotations?

find the median of the set of elements given, make it as root and construct the tree

What is the time complexity for finding the height of the binary tree?

h = O(log n)


Conjuntos de estudio relacionados

CWTS-2-Introduction to Wireless Local Area Networking

View Set

Lección 15 Lesson Test Review 1-Escuchar; 2- Imágenes; 3-Completar; 4-Opciones; 5-Oraciones; 6-Completar; 7-Escoger; 8-Oraciones; 9-Ayer; 10 Lectura"Beber Alcohol" (corrected)

View Set

Chapter 23: Adult Women and Men (FINAL EXAM)

View Set

Module 5 Speaking Questions : Questions - French

View Set

UNMC health assessment exam 4 practice questions

View Set

el gran robo argentino sentences

View Set

Legal Concepts of the insurance Contract- chapter 2

View Set

ACCT 3230 - Chapter 14 - LearnSmart

View Set

CHOICE IN A WORLD OF SCARCITY QUIZ

View Set