• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/120

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

120 Cards in this Set

  • Front
  • Back

What is the best definition of a collision in a hash table?

Two entries with different keys have the same exact hash value.

Selectionsort and quicksort both fall into the same category of sorting algorithms. What is this category?

Interchange sorts

Suppose we are sorting an array of eight integers using heapsort, and we have just finished one of the reheapifications downward. The array now looks like this: 6 4 5 1 2 7 8How many reheapifications downward have been performed so far?

2

Suppose that you place 180 items in a hash table with an array size of 200. What is the the average number of table elements that you expect to have examined during a successful search for a double hashing?

2.56

The following is the specification of the table’s never_used member function.


// bool never_used(size_t index) const// Precondition: index < CAPACITY.// Postcondition: If data[index] has never// been used, then the return value is true.// Otherwise the return value is false.What would be the best implementation for the inline never_used member function?

template bool Table::never_used(size_t index) const{ return (data[index].key == NEVER_USED);}


An empty hash table has a capacity of 103, and you insert six entries with keys 103, 0, 205, 308, 411, and 2. Using double hashing (with hash2(key)returning the value 1 + (key % 101)), where will the 411 be placed in the table?

7

Use the insert function defined in section 12.3 to place six items in a hash table with a table size of 811. Use the keys 811, 0, 1623, 2435, 3247, and 2, which key(s) will be stored at data[1] list?

1623

What are the advantages of hashing over performing a binary search?

Hashing can be fast in the average case. Adding and deleting elements is easier in a container that provides hashing, because a binary search requires that the items remain sorted.

How are collisions resolved in open-address hashing?

Collisions are resolved by placing the item in the next open spot of the array.

Use the insert function defined in section 12.3 to place six items in a hash table with a table size of 811. Use the keys 811, 0, 1623, 2435, 3247, and 2, which key(s) will be stored at data[0] list?

0 and 811

An empty hash table has a capacity of 103, and you insert six entries with keys 103, 0, 205, 308, 411, and 2. Using linear probing and a division hash function, where will the 0 be placed in the table?

1

If we will be able to arrange the key in an order, what is the advantage to keep each linked list of the table sorted from smallest key to largest key?

If the lists are kept in order, then a search can stop as soon as it reaches a key that is greater than the target

One common way of ordering records is to choose one special field, which is then called the ______________ , and to sort the records according to that ___________ .

key field, key field

What is the worst-case running times for a selectionsort?

quadratic

Provide two ways to use pointer arithmetic to print the ninth element of an array data

cout << (data + 9)[0];cout << (data + 6)[3];

What would be the best statement about quicksort and mergesort?

The running time of the quicksort depends on the pivot element. The running time of mergesort does not depend on the array elements, but on the array length.

What is the worst-case running times for a mergesort ?

O ( n log n)

What is the average-case running times for a quicksort ?

O ( n log n)

An entire array can be sorted by a series of swaps. Any sorting algorithm that is based on swapping is referred to as an ________________________.

interchange sort

If we have a data array as following, what is the "cout << ++((data + 5)[1]); " displayed?

If we have a data array as following, what is the "cout << ++((data + 5)[1]); " displayed?

21

What is the worst-case time for binary search finding a single item in an array?

Logarithmic time

What is the worst-case time for quicksort to sort an array of n elements?

O(n²)

What is the worst-case time for heapsort to sort an array of n elements?

O(n log n)

In our new table class (section 12.3), the array is still a fixed size. So why do we need the copy constructor, destructor, and overloaded assignment operator?

The ADT does use dynamic memory (the linked lists).

What are the stopping cases in the recursive binary search function?

When size becomes zero, or when the target is found.

The following is the specification of the table’s is_present member function.// CONSTANT MEMBER FUNCTIONS for the table class:bool is_present(int key) const// Postcondition: The return value is true if there is a record in the table with the// specified key. Otherwise, the return value is false.What would be the best implementation for the is_present member function?


template bool table::is_present(int key) const{ bool found; std::size_t index; assert(key >= 0); find_index(key, found, index); return found;}


An empty hash table has a capacity of 103, and you insert six entries with keys 103, 0, 205, 308, 411, and 2. Using linear probing and a division hash function, where will the 103 be placed in the table?

0

What would be the best insert member function for the chaining version (section 12.3) of the table?

template void Table :: insert(const RecordType& entry){ main_savitch_6B::node *cursor; cursor = find_ptr(entry.key); //returns a pointer to a node with the specified key (or returns NULL if there is no such node) if (cursor == NULL) { list_head_insert (data[hash(entry.key)], entry); ++used; } else cursor->setdata(entry);}


Suppose that we place 180 items in a hash table with an array size of 200. What is the load factor?

0.9

An empty hash table has a capacity of 103, and you insert six entries with keys 103, 0, 205, 308, 411, and 2. Using double hashing (with hash2(key)returning the value 1 + (key % 101)), where will the 308 be placed in the table?

5

An empty hash table has a capacity of 103, and you insert six entries with keys 103, 0, 205, 308, 411, and 2. Using linear probing and a division hash function, where will the 205 be placed in the table?

102

We want to place 1000 elements in a hash table, and we’d like an average search to examine just two table elements. How big does the table’s array need to be for a double hashing?

1250

What is the worst-case running times for a quicksort ?

O( n2 )

If we have a data array as following, what is the meaning of "selectionsort((data + 4), 2); "?

If we have a data array as following, what is the meaning of "selectionsort((data + 4), 2); "?

Sorts data[4] through data[5]

Which statement of the following is the most appropriate one?

All the sorting algorithms presented in chapter 13 apply to any type of values sorted according to any reasonable ordering relation. The array values do not need to be integers.

Suppose that data is an array of 1000 integers. What would be a single quicksort (section 13.2) function call that will sort the 100 elements data[222] through data[321]?

quicksort((data + 222), 100);

If we have a data array as following, what is the meaning of "selectionsort((data + 5), 4); "?

If we have a data array as following, what is the meaning of "selectionsort((data + 5), 4); "?

Sorts data[5] through data[8

Which one of the following is a correct statement?

Divide-and-conquer works best with two equally sized subproblems,each of which is solved with a recursive call

If we have a data array as following, what would be the data array after going through the third run of an insertionsort?

If we have a data array as following, what would be the data array after going through the third run of an insertionsort?

Which recursive sorting technique always makes recursive calls to sort subarrays that are about half the size of the original array?

merge sort

What additional requirement is placed on an array, so that binary search may be used to locate an entry?

The array must be sorted.

Suppose we are sorting an array of ten integers using a some quadratic sorting algorithm. After four iterations of the algorithm's main loop, the array elements are ordered as shown here: 1 2 3 4 5 0 6 7 8 9Which statement is correct? (Note: Our selectionsort picks largest items first.)

The algorithm might be either selectionsort or insertionsort.

In a selectionsort of n elements, how many times is the swap function called in the complete execution of the algorithm?

n - 1

Compute the H(9) value (H is the halving function)?

4

When is a serial search an acceptable choice?

A serial search is acceptable when you are searching a small array only a few times.

Suppose that a hash table is full and you try to insert a new entry. What happens if the new entry’s key is not already in the table?

If the key was not already present, then the assertion tests whether size( ) < CAPACITY is true, and this assertion fails, halting the program.

Why does a binary search function require parameters of the first array index and the size of the array?

Because of the recursive calls in a binary search, the array is repeatedly split in half. The first and size parameters keep track of the portion of the array that is currently being searched.

An empty hash table has a capacity of 103, and you insert six entries with keys 103, 0, 205, 308, 411, and 2. Using double hashing (with hash2(key)returning the value 1 + (key % 101)), where will the 205 be placed in the table?

102

Use the insert function defined in section 12.3 to place six items in a hash table with a table size of 811. Use the keys 811, 0, 1623, 2435, 3247, and 2, which key(s) will be stored at data[800] list?

empty

The following is the specification of the table’s is_vacant member function. // bool is_vacant(size_t index) const// Library facilities used: stdlib.h// Precondition: index < CAPACITY.// Postcondition: If data[index] is not now// being used, then the return value is true.// Otherwise the return value is false.What would be the best implementation for the inline is_vacant member function?

template inline bool Table:: is_vacant(size_t index) const{ Return (data[index].key < 0);}


Suppose that a hash table is full and you try to insert a new entry. What happens if the new entry’s key is already in the table?

If the key was already present, then the record with that key is overwritten.

Compute the H(8) value (H is the halving function)?

4

Which statement of the following is the most appropriate one?

Selectionsort and insertionsort have quadratic running times in both the worst case and the average case. This is comparatively slow. However, if the arrays to be sorted are short, or if the sorting program will only be used a few times, then they are reasonable algorithms to use. Insertionsort is particularly good if the array is nearly sorted beforehand.

What would be the best statement about heapsort and selectionsortt?

Heapsort uses a heap to store, locate, and swap values, which results in a much more efficient implementation than selectionsort does.

An array contain the following elements, 5 19 13 36 23 2, what would be all the steps of each iteration of insertionsort, using the largest element version of swapping?

What would be the best statement about mergesort, quicksort and heapsort?

The mergesort and heapsort have a worst-case running time that is O(n log n). The heapsortt and quicksort do not require an additional array

What would be the big O notation for a merges sort recursive sorting?

O(n log n)

What is the average-case running times for a mergesort ?

O ( n log n)

If we have a data array as following, what would be a temp array after going through the second run of a mergesort?

If we have a data array as following, what would be a temp array after going through the second run of a mergesort?

If we have a data array as following, what is the meaning of "selectionsort((data + 2), 5); "?

If we have a data array as following, what is the meaning of "selectionsort((data + 2), 5); "?

Sorts data[2] through data[6]

What kind of initialization needs to be done for an open-address hash table?

The key at each array location must be initialized.

Mergesort makes two recursive calls. Which statement is true after these recursive calls finish, but before the merge step?

Elements in each half of the array are sorted amongst themselves.

Suppose we are sorting an array of eight integers using quicksort, and we have just finished the first partitioning with the array looking like this: 2 5 1 7 9 12 11 10Which statement is correct?

The pivot could be either the 7 or the 9.

How can clustering of elements in linear probing can be solved?

Double hashing can solve this problem by using a second hash function to resolve a collision.

Use the insert function defined in section 12.3 to place six items in a hash table with a table size of 811. Use the keys 811, 0, 1623, 2435, 3247, and 2, which key(s) will be stored at data[3] list?

3247

Use the insert function defined in section 12.3 to place six items in a hash table with a table size of 811. Use the keys 811, 0, 1623, 2435, 3247, and 2, which key(s) will be stored at data[4] list?

empty

An empty hash table has a capacity of 103, and you insert six entries with keys 103, 0, 205, 308, 411, and 2. Using linear probing and a division hash function, where will the 411 be placed in the table?

3

We want to place 1000 elements in a hash table, and we’d like an average search to examine just two table elements. How big does the table’s array need to be for a linear probing?

1500

Suppose that you place 180 items in a hash table with an array size of 200. What is the the average number of table elements that you expect to have examined during a successful search for a linear probing?

5.50

Compute the H(7) value (H is the halving function)?

3

Suppose that you place 180 items in a hash table with an array size of 200. What is the the average number of table elements that you expect to have examined during a successful search for a chained hashing?

1.45

An empty hash table has a capacity of 103, and you insert six entries with keys 103, 0, 205, 308, 411, and 2. Using linear probing and a division hash function, where will the 2 be placed in the table?

4

A small array, which is actually part of a larger array, is called a ______________.

subarray

If we have a data array as following, what would be the array after going through the first positions interchange of a quicksort?

If we have a data array as following, what would be the array after going through the first positions interchange of a quicksort?

Which statement of the following is the most appropriate one?

In divide-and-conquer sorting methods, the values to be sorted are split into two approximately equal groups, the groups are sorted by a recursive call, and then the two sorted groups are combined into the final sorted list. Mergesort and quicksort are examples of divide-and-conquer sorting algorithms.

An array contain the following elements, 5 19 13 36 23 2, what would be all the steps of each iteration of selectionsort, using the largest element version of swapping?

Why is mergesort a good choice for sorting a large file?

A large file may be sorted effectively by mergesort by dividing the file into several pieces, and merging the sorted pieces into a single file. The individual pieces can be removed after the file is sorted.

What is the average-case running times for a selectionsort?

quadratic

If we have a data array as following, what would be the array after going through the third positions interchange of a quicksort?

If we have a data array as following, what would be the array after going through the third positions interchange of a quicksort?

If we have a data array as following, what would be the data array after going through the second run swap function of a selectionsort?

If we have a data array as following, what would be the data array after going through the second run swap function of a selectionsort?

In an open-address hash table there is a difference between those spots which have never been used and those spots which have previously been used but no longer contain an item. Which function has a better implementation because of this difference?

Two or more of the above functions

Suppose that a selectionsort of 100 items has completed 42 iterations of the main loop. How many items are now guaranteed to be in their final spot (never to be moved again)?

42

Suppose we are sorting an array of eight integers using a some quadratic sorting algorithm. After four iterations of the algorithm's main loop, the array elements are ordered as shown here: 2 4 5 7 8 1 3 6Which statement is correct? (Note: Our selectionsort picks largest items first.)

The algorithm is not selectionsort, but it might be insertionsort.

Compute the H(1) value (H is the halving function)?

1



Use the insert function defined in section 12.3 to place six items in a hash table with a table size of 811. Use the keys 811, 0, 1623, 2435, 3247, and 2, which key(s) will be stored at data[400] list?

empty

What would be a problem with linear probing?

Linear probing can result in clustering of elements when several different keys are hashed to the same location. Insertions and searching take longer as clustering gets worse.

The following is a pseudocode for Serial Search// Searches for a desired item in the n array elements starting at a[first]Set a size_t variable i to 0, and set a boolean variable found to false.while ((i < n) && !found) { if (a[first+i] is the desired item) found = true; else ++i; }if (found) The desired item is in a[first+i]. else The desired item does not appear in the n items starting at a[first].What would be the most appropriate implementation of the serialSearch function?

void searilSearch(const int a[ ], size_t first, size_t size, int target, bool& found, size_t& location){ size_t i; bool found; i = 0; found = false; while ((i < size) && !found) { if (a[first+i] == target) { found = true; location = first+i; } else ++i; }}

What would be a good pair of twin primes between 1200 and 1250, with the upper prime having the form 4k+3 for some k?

There is a twin prime pair at 1229 and 1231.

An empty hash table has a capacity of 103, and you insert six entries with keys 103, 0, 205, 308, 411, and 2. Using double hashing (with hash2(key)returning the value 1 + (key % 101)), where will the 2 be placed in the table?

2

An empty hash table has a capacity of 103, and you insert six entries with keys 103, 0, 205, 308, 411, and 2. Using linear probing and a division hash function, where will the 308 be placed in the table?

2



Compute the H(2) value (H is the halving function)?

1

Use the insert function defined in section 12.3 to place six items in a hash table with a table size of 811. Use the keys 811, 0, 1623, 2435, 3247, and 2, which key(s) will be stored at data[2] list?

2 and 2435.

What is the average-case running times for a insertionsort?

quadratic

If we have a data array as following, what would be the data array after going through the first run of an insertionsort?

If we have a data array as following, what would be the data array after going through the first run of an insertionsort?

If we have a data array as following, what would be the array after going through the second positions interchange of a quicksort?

If we have a data array as following, what would be the array after going through the second positions interchange of a quicksort?

If we have a data array as following, what is the "cout << (data + 3)[1]; " displayed?

If we have a data array as following, what is the "cout << (data + 3)[1]; " displayed?

5

Why is mergesort not a good choice for sorting arrays?

Mergesort is not a good choice for sorting arrays because of the additional memory required for the temporary array in the merge step.

If we have a data array as following, what is the "cout << (data + 5)[2]; " displayed?

If we have a data array as following, what is the "cout << (data + 5)[2]; " displayed?

11

If we have a data array as following, what would be the data array after going through the second run of an insertionsort?

If we have a data array as following, what would be the data array after going through the second run of an insertionsort?

Which one of the following is a correct statement?

The selectionsort algorithm performs the same number of operations no matter what values are in the array that it sorts.

What kind of initialization needs to be done for an chained hash table?

The head pointer of each chain must be set to NULL.

When is insertionsort a good choice for sorting an array?

The array has only a few items out of place.

What is the worst-case time for mergesort to sort an array of n elements?

O(n log n)

What are the possible template parameters?a. a data typeb. a constant data valuec. a functiond. a constructor

a, b, and c

What is the worst-case, average-case, and best-case running time for a successful serial search?

Worst case: O(n). Average case: O(n). Best case: O(1).

Why doesn’t the new table (section 12.5) need a copy constructor, destructor, or assignment operator?

A copy constructor, destructor, and assignment operator are needed only when a class makes direct use of dynamic memory. The new table class uses dynamic memory, but only through the vector class, which is another great reason to use the STL classes.

We want to place 1000 elements in a hash table, and we’d like an average search to examine just two table elements. How big does the table’s array need to be for a chained hashing?

500

An empty hash table has a capacity of 103, and you insert six entries with keys 103, 0, 205, 308, 411, and 2. Using double hashing (with hash2(key)returning the value 1 + (key % 101)), where will the 0 be placed in the table?

0

Consider the chaining version of the table that we have described (section 12.3). What value will the constructor place in each component of data?

NULL

Compute the H(4) value (H is the halving function)?

3

If we have a twin prime pair at 1229 and 1231, what would be a good size for a hash table that uses double hashing and has a capacity around 1225?

1231

When should a programmer use a struct rather than a class?

Programmers tend to use a struct only when all the members are public.

What is the best-case running times for a insertionsort?

linear

If we have a data array as following, what is the meaning of "selectionsort(data , 2); "?

Sorts data[0] through data[1]

What would be the best statement about quicksort?

When there is good splitting in quicksort, the resulting time is O(n log n). When there is bad splitting in quicksort, the result can be quadratic time.

If we have a data array as following, what would be the data array after going through the third run swap function of a selectionsort?

If we have a data array as following, what would be the data array after going through the third run swap function of a selectionsort?

What is the best-case running times for a quicksort ?

O ( n log n)

What is the worst-case running times for a insertionsort?

quadratic

What is the best-case running times for a selectionsort?

quadratic

If we have a data array as following, what would be a temp array after going through the first run of a mergesort?

If we have a data array as following, what would be a temp array after going through the first run of a mergesort?