CS445 Exam 2

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

How many disks (Tower of Hanoi) are moved in a single call to the method?

1

Consider a key to hash as an 8 character string of ASCII (8-bit) characters. Also assume that an integer can be arbitrarily large. How large would a hash table have to be in order to completely avoid hash collisions?

256^8

Number of moves in Towers of Hanoi

2^N - 1

Consider linear probing vs. double hashing. As alpha increases toward 1 how do their performances compare?

Both degrade toward linear access, but linear probing degrades more quickly than double hashing

When is data compared in the MergeSort algorithm

After both recursive calls have completed

When backtracking occurs, what is happening in execution?

An activation record is being popped off the run time stack

Comparison based sorting has a lower bound of NlgN which means

Any comparison based sorting algorithm has a run-time of at least NlgN

Why use a base case other than 1 for QuickSort

As the problem size get smaller, the benefit of divide and conquer approach decreases

Searching a Sorted Array/Vector

Binary Search - Run Time Theta(lgN)

Why does ShellSort outperform InsertionSort

By time InsertionSort is performed the data is already mostly sorted

ShellSort, the last iteration of the outer loop

Does a full InsertionSort of the data

8 Queens problem (indicies 0 - 7) : what happens is a queen cannot be placed in row 6 of column k

Try to place queen in row 7

What happens when iterator reaches end of collection and next() method is called

Exception is thrown

The Median of 3 version of QuickSort will have the worst case performance when the array is reverse sorted

False

Which of the following statements about the Rabin-Karp string matching algorithm (for a pattern, P, of size M and a text, A, of size N) are true? Assume H(x) is the hash function used for the algorithm. Indicate ALL true statements.

If H(P) != H(M consecutive characters in T) then P is not (yet) found in T

Integer multiplication compared to int and long multiplication

Integer multiplication is not constant time but int and long are due to fixed bit length

What do K and V represent

K represents Key type and V represents Value type

Basic approach to implementing the Iterator<T> interface in the LList<T> class

Make the Iterator implementation a private inner class within LList<T>

Towers of Hanoi algorithm

Move N-1 disks from start to middle, last disk from start to end, N-1 disks from middle to end

Ave chain length for separate chaining

N/M

Sole instance variable in a linked list implementation of an iterator

Node refrence

Towers of Hanoi: single call of size N size of subproblems

O(1), N-1

Assume that I have a linear probing hash table of size M, containing N keys. I detect that alpha is getting a bit big so I decide to make a new table double the old size (actually the smallest prime >= double the old size) and to hash all of the data into the new table. Assuming that I have a good hash function, how much total time should this resizing process take overall?

O(N)

MergeSort: single call of size N size of subproblems generated

O(N), N/2

Consider the pattern string, P, of length M and the text string, A, of length N, below: P = ABCDE A = ABCDVABCDWABCDXABCDYABCDZ How would you describe the run-time of the Boyer Moore mismatched character heuristic in this case?

O(N/M0

Average run time Insertion Sort

O(N^2)

Worst Case run-time Insertion Sort

O(N^2)

MergeSort has an asymptotic run-time of O(NlgN) b/c

O(lgN) levels, each requiring O(N) work

Data types for MergeSort

Object types

What does each recursive call represent in 8-Queens problem soln?

Placing a queen at some row within a given column of the board

Good divide and Conquer solution for power function

Power(X,N) = (Power(X,N/2))^2

Worst case situation Insertion Sort

Reverse sorted

Searching Sorted Linked List

Sequential Search - Run Time Theta(N)

Searching an Unsorted Array/Vector

Sequential Search - Run Time theta(N)

Searching Unsorted Linked List

Sequential Search - Theta(N)

Last iteration of the outer loop for InsertionSort

The last remaining item could end up in any position within the array

Step 2 in divide and conquer for Binary search

The recursive answer IS the answer - we simply pass it on

What is true about the 8 queens problem?

There is 1 queen in each column and 1 queen in each row

Guaranteed with the median of three partition algorithm

There will be at least one item on the left side and at least one item on the right side

Consider a hash table using separate chaining with table size M = 100 and number of keys N = 150. What will be the performance of this table?

Theta(1)

In linear probing hash table, as alpha --> 1, what happens to the performance of linear probing for insert and find?

They approach N (linear time)

In the linear probing collision resolution scheme, how do we know when a key, K, is NOT found in the table (assuming that the table is not completely full)?

We reach an empty location in the table

How do we "fix" the delete issue with a linear probing hash table?

We rehash (in the same table) all of the values after the deleted item and up to the end of the current cluster

QuickSort algorithm, data comparisons are done

While the data is being "divided", prior to the recursive calls

If for QuickSort data is already sorted, and leftmost is taken instead of rightmost will it affect run-time

Will still be worst-case since it is still an extreme value

If data is already sorted and rightmost element chosen as pivot which behavior will algorithm exhibit

Worst Case Behavior

Rabin Karp uses hash function for algorithm but

a hash table is not actually used in the algorithm

dictionary

abstract data structure that associates a value with a key

Recursive binary search v iterative binary search

both proceed through the data in identical ways, always comparing the same values

Implementation of ListIterator<T> interface with singly linked list

cannot efficiently implement ListIterator<T> with singly linked list

MergeSort does not sort in place which

does not affect the asymptotic run-time but it degrades the empirical run-time of MergeSort

Define a collision in a hash table

h(x1) == h(x2) where x1 != x2

Methods in Iterator<T> interface

hasNext(), next(), remove()

ConcurrentModificationException

if we modify the underlying list via another access (list methods or another iterator) it will produce this error when next() method is called

Issues with recursion

overhead, space taken up by AR on RTS, and time taken to create AR on RTS

Data types for QuickSort

primitive types

Backtracking

proceed forward to a soln until no soln can be achieved, at that point undo the soln

Tail Recursion

recursive algorithm in which the recursive call is the last statement in a call of the method

Run-time for an iterator with an underlying ArrayList v. an underlying LinkedList

run-times will be similar for both objects

True at the end of the partition algorithm

the pivot value is in its final correct location within the array, The values on the "right" side of the array are all greater than or equal to the pivot

In a maze, when do we backtrack

when we can no longer move forward

In the best case scenario for QuickSort how would the data be divided

~N/2 items <= pivot and ~N/2 items >= the pivot


Set pelajaran terkait

Worksheet 22.1: The Bankruptcy Code & Chapter 7 -- Liquidation

View Set

Chapter 46: Care of Patients with Oral Cavity and Esophageal conditions

View Set

Essential FLACS Checkpoint B French Vocab

View Set