Data Structures Final

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Consider the following Binary Search Tree 10 / \ 5 20 / / \ 4 15 30 / 11 If we randomly search one of the keys present in the above BST, what would be the expected number of comparisons?

2.57

The following numbers are inserted into an empty binary search tree in the given order: 10, 1, 3, 5, 15, 12, 16. What is the height of the binary search tree (the height is the maximum distance of a leaf node from the root)?

3

key % 1000 maps to indices 0 to ____.

999

inorder traversal. How to remember?

L cur R

Which of the following traversal outputs the data in sorted order in a BST?

LNR (inorder)

how do you calculate the height of a bst given an n number of nodes

log n *round down *base 2

what does the hash table return when a value is not found?

0

The preorder traversal sequence of a binary search tree is 30, 20, 10, 15, 25, 23, 39, 35, 42. Which one of the following is the postorder traversal sequence of the same tree?

15, 10, 23, 25, 20, 35, 42, 39, 30

how do you know if a tree is an AVL tree? or Balanced tree?

First, if it is a BST and If L - R = is between 0 and 1 then it is balanced

edge

the link from a node to a child

root

the top of the tree

parent

a node with a child

The keys 12, 18, 13, 2, 3, 23, 5 and 15 are inserted into an initially empty hash table of length 10 using open addressing with hash function h(k) = k %10 and linear probing. What is the resultant hash table?

0 1 2 12 3 13 4 2 5 3 6 23 7 5 8 18 9 5

Suppose the numbers 7, 5, 1, 8, 3, 6, 0, 9, 4, 2 are inserted in that order into an initially empty binary search tree. The binary search tree uses the usual ordering on natural numbers. What is the in-order traversal sequence of the resultant tree?

0 1 2 3 4 5 6 7 8 9

Consider a hash function that distributes keys uniformly. The hash table size is 20. After hashing of how many keys will the probability that any new key hashed collides with an existing one exceed 0.5.

10

How many different insertion sequences of the key values using the same hash function and linear probing will result in the hash table shown in problem 1?

30

How many nodes are possible at level 4 of a binary tree? [a]

31

A hash table of length 10 uses open addressing (collisions are dealt with by looking for the next open slot) with hash function h(k) = k%10, and linear probing. After inserting 6 values into an empty hash table, the table is shown below. 0 1 2 42 3 23 4 34 5 52 6 46 7 33 8 9 Which one of the following choices gives a possible order in which the key values could have been inserted in the table?

46, 34, 42, 23, 52, 33

A modulo hash function for a 50 entry hash table is: key % _____

50 so that it wil generate values form 0 to 49

The height of a complete binary tree with 52 nodes is ...?

7

The number of nodes in a complete binary tree with a height of 7 is between [a] and [b]

7 and 255

Given the following input (4322, 1334, 1471, 9679, 1989, 6171, 6173, 4199) and the hash function x mod 10, which of the following statements are true?

9679, 1989, 4199 hash to the same value 1471, 6171 has to the same value

Which of the following statement(s) are True?

A hash function takes a message of arbitrary length and generates a fixed length code. A hash function may give the same hash value for distinct messages.

level

All nodes with the same depth form a tree ex. a level =0 /\ b c level = 1

Which of the following is true about Binary Trees?

Every binary tree is either complete or full. Every complete binary tree is also a full binary tree. Every full binary tree is also a complete binary tree. No binary tree is both complete and full. Correct Answer: None of the above

In delete operation of BST, we need inorder successor (or predecessor) of a node when the node to be deleted has both left and right child as non-empty. Which of the following is true about inorder successor needed in delete operation?

Inorder successor is always either a leaf node or a node with empty left child

what is a hash table's big O notation?

O(1)

what is the best case for BST?

O(log n)

Removing a node from an n-node nearly-full BST has what computational complexity?

O(log(n))

an internal node

a node with at least one child

leaf

a tree node with no children

consider a hashtable from 0 to 9, If item keys range from 0 to 49, how many keys may map to the same bucket?

answer is 5 divide number of keys/ number of buckets

A hash table with linear probing handles a collision by starting at the key's mapped bucket, and then linearly searches subsequent buckets until an empty bucket is found.

basically if there is a collision, instead of chaining, you add the key to the next empty bucket found

Each hash table array element is called a

bucket

Searching a BST in the worst case requires how many comparisons?

h + 1, meaning O(h) comparisons, where h is the tree height

Which one of the following hash functions on integers will distribute keys most uniformly over 10 buckets numbered 0 to 9 for i ranging from 0 to 2020?

h(i) = i3 % 10

depth

is the number of edges on the path from the root to the node. The root node thus has depth 0.

For a binary mid-square hash function, how many bits are needed for an 80 entry hash table?

log( 80) = 6.32 = 7 lob base 2


Set pelajaran terkait

Microbiology-Chapter 1 (Microbiology Introduction)

View Set

Coding Final -- Match Term With Correct Statement

View Set

Chapter 13 Deserts and Wind Action

View Set

Med surg exam 3 ATI practice questions w/ rationales

View Set