Quiz 2

Réussis tes devoirs et examens dès maintenant avec 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)

When to choose Red-Black tree, AVL tree?

many inserts, many searches and when managing more items respectively

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 below diagram is following AVL tree property?

only ii

How to search for a key in a binary search tree?

public Tree search(Tree root, int key) { if( root == null || root.key == key ) { return root; } if( root.key < key ) { return search(root.right,key); } else return search(root.left,key); }

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()); }

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

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

Why we need to a binary tree which is height balanced?

to avoid formation of skew trees

Why do we impose restrictions like . root property is black . every leaf is black . children of red node are black . all leaves have same black

to get logarithm time complexity

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

How can you save memory when storing color information in Red-Black tree?

using least significant bit of one of the pointers in the node for color information

When it would be optimal to prefer Red-black trees over AVL trees?

when there are more insertions or deletions

Which of the following is an application of Red-black trees and why?

can be used in process schedulers, maps, sets

Consider the below formations of red-black tree. All the above formations are incorrect for it to be a red-black tree. then what may be the correct order?

50-black root, 18-red left subtree, 100-red right subtree

Why to prefer red-black trees over AVL trees?

AVL tree store balance factor in every node which costs space

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

It traverses in an increasing order

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

None of the mentioned

Which of the following is not an advantage of trees?

Undo/Redo operations in a notepad

What is the special property of red-black trees and what root should always be?

a color which is either red or black and root should always be black color only

What is an AVL tree?

a tree which is balanced and is a height balanced tree

Why Red-black trees are preferred over hash tables though hash tables have constant time complexity?

because of resizing issues of hash table and better ordering in red-black trees

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)

What is the below pseudo code trying to do, where pt is a node pointer and root pointer redblack(Node root, Node pt) : if (root == NULL) return pt if (pt.data < root.data) { root.left = redblack(root.left, pt); root.left.parent = root } else if (pt.data > root.data) { root.right = redblackt(root.right, pt) root.right.parent = root } return root

insert a new node

What are the operations that could be performed in O(logn) time complexity by red-black tree?

insertion, deletion, finding predecessor, successor


Ensembles d'études connexes

Chapter 1 MIDTERM StudyGuide (BI)

View Set

Chapter 1 study guide - music appreciation

View Set

PrepU Chapter 6: Values, Ethics, and Advocacy

View Set

Chapter 3 Income Statement and Statement of Stockholders' Equity

View Set

Unit/module quiz questions WGU Intro to Communications

View Set