C949
deque
A ________ is an ADT in which items can be inserted and removed at both the front and back.
Nearly Sorted
A _________ list only contains a few elements not in sorted order. Example: (4, 5, 17, 25, 89, 17) is nearly sorted having only one elements not in sorted position.
Doubly linked list
A __________ is a data structure impleminting a list ADT, where each node has data, a pointer to the next node, and a pointed to the previous node.
Singly Linked List
A __________ singly-linked list is a data structure for implementing a list ADT, where each node has data and a pointer to the next node.
Element Comparison Sorting Algorithm
A ____________ is a sorting algorithm that operates on an array of elements that can be compared to each other.
stack
A ____________ is an ADT in which items are only inserted on or removed from the top of the stack.
reverse traversal
A ___________________ visits all nodes starting with the list's tail node and ending after visiting the list's head node.
circular linked list
A ______________________ is a linked list where the tail node's next pointer points to the head of the list, instead of null.
Full
A binary tree is _____ if every node contains 0 to 2 children.
Complete
A binary tree is ______ if all levels, except possibly the last level, are completely full and all nodes in the last level are as far left as possible.
Perfect
A binary tree is ______, if all internal nodes have 2 children and all leaf nodes are at the same level.
modulo operator %
A common hash function uses the ___________, which computes the integer remainder when dividing two numbers.
Employee ID number Keys should be unique, assumedly the company would assign a unique ID number to each employee.
A company will store all employees in a hash table. Each employee item consists of a name, department, and employee ID number. Which is the most appropriate key?
Holly
A contact list is searched for Bob. Assume the following contact list: Amy, Bob, Chris, Holly, Ray, Sarah, Zoe What is the first contact searched?
Bob
A contact list is searched for Bob. Assume the following contact list: Amy, Bob, Chris, Holly, Ray, Sarah, Zoe What is the second contact searched?
False Fast sorting algorithms are classified based on average case, not worst care, runtime complexity.
A fast sorting algorithm's worst case runtime complexity must be O(N logN) or better.
True
A for loop of the form.... for (i = 0; i < N; ++i) {} that does not have nested loops or function calls, and does not modify i in the loop will always have a complexity of O(N)
Key The key is usually a part of the item, such as a student object that has a name, age, and student ID number, with the ID number serving as the key.
A hash function computer a bucket index from an item's ________.
Item 95
A hash table has buckets 0 to 9 and uses a hash function of key % 10. If the table is initially empty and the following inserts are applied in the order shown, the insert of which item results in a collision? HashInsert(hashTable, item 55) HashInsert(hashTable, item 90) HashInsert(hashTable, item 95)
2
A hash table's items will be positive integers, and -1 will be represented empty. A 5 bucket hash table is: -1, -1, 72, 93, -1. How many items are in the table?
O(N)
A linear search has a ________ runtime complexity.
False
A loop is never a constant time operation.
50
A modulo hash function for a 50 entry table is: key % _____.
10
A modulo hash function is used to map indices 0 to 9. The hash function should be: key % ______.
False
A recursive algorithm applies itself to a smaller subproblem in all cases.
True
A recursive function can have two base cases, such as n == 0 returning 0, and n == 1, returning 1.
True
A recursive function with parameter n counts up from any negative number to 0. An appropriate base case would be n == 0.
O(N^2)
A selection sort has a _________ runtime complexity.
Positional
A singly linked list is a type of _________ list.
Head
A singly linked lists first node is called the ________.
Tail
A singly linked lists last node is called the _______.
Insertion Sort
A sorting algorithm that treats the input as two parts, a sorted part and an unsorted part, and repeatedly inserts the next value from the unsorted part into the correct location in the sorted part.
itemgetter()
A special function, _________, defined by Python's operator module, can be used to get a key from an element using an index instead of a custom key function.
last in first out
A stack is referred to as a ____________ ADT.
False
After partitioning, the left and right parts should be sorted.
True When using the 1's digit for the array (10, 20, 30, 40), each integer will be in bucket 0, even though each integer is distinct.
All integers from an array could be placed into the same bucket, even if the array has no duplicates.
Array based list
An ___________ is an ADT implemented using an array.
empty since start
An ______________ bucket has been empty since the hash table was created.
empty after removal
An ____________________ bucket had an item removed that caused the bucket to now be empty.
False
An algorithm's best and worst case scenarios are always different.
False If the hashCode() method returns the minimum integer, -2147483648, then Math.abs(-2147483648) evaluates to -2147483648. The hash() method must not return a negaitve integer.
An alternative implementation of the hash() method could simply return Math.abs(key.hashCode())
Tail
An append node becomes the ________ of a linked list.
False An array based list starts with a length of 0, but the default allocation size must be >= 1.
An array based list can have a default allocation size of 0.
False An empty LinkedList has two data members, but both are set to None, thus the list has no nodes.
An empty LinkedList has a single node with a data value of None.
True Different types of hash tables represent the idea of an "empty" bucket in different ways. A chaining hash table represents an empty bucket with an empty list.
An empty bucket in a Python ChainHashTable class is really an empty list object.
True A length less than the array allocation size implies that at least one entry in the array is not used. An item can be appended into the available space.
An item can be appended to an array based list, provided the length is less than the array's location size.
3
Assume insertion sort's goal is to sort in ascending order. Given list (1, 9, 17, 18, 2), how many swaps will occur during outer loop execution (i = 4)?
False sort() is a list method that changes the order of items in the list. The method does not have a return value.
Assume num_list is a list defined in Python. num_list.sort() returns a list.
3 1st: (a, b, c, d) (e, f, g, h) 2nd: (a, b) (c, d) (e, f) (g, h) 3rd: (a) (b) (c) (d) (e) (f) (g) (h)
Assume quicksort always chooses a pivot that divides the elements into two equal parts. How many partitioning levels are required for a list of 8 elements?
1
Assume selection sort's goal is to sort in ascending order. Given the list (9, 8, 7, 6, 5), how many swaps will occur during the first pass of the outer loop? (i = 0)?
5
Assume selection sort's goal is to sort in ascending order. Given the list (9, 8, 7, 6, 5), what value will be in the 0th element after the first pass over the outer loop (i = 0)?
node_a
Assume the code below has been executed using a doubly linked list. word_list = LinkedList() node_a = Node("Python") node_b = Node("Is") node_c = Node("Fun!") word_list.append(node_a) word_list.append(node_b) word_list.append(node_c) For node_b what is the prev data member?
None of the above; the variable's value is None.
Assume the code below has been executed using a doubly linked list. word_list = LinkedList() node_a = Node("Python") node_b = Node("Is") node_c = Node("Fun!") word_list.append(node_a) word_list.append(node_b) word_list.append(node_c) Which node does node_c's next data member refer to?
nodeA
Assume the code below has been executed using a doubly linked list. Linkedlist wordList = new LinkedList(); Node nodeA = new Node("Java"); Node nodeB = new Node("is"); Node nodeC = new Node("fun!"); wordList.append(nodeA); wordList.append(nodeB); wordList.append(nodeC); Which node has previous set to null?
nodeA
Assume the code below has been executed using a doubly linked list. Linkedlist wordList = new LinkedList(); Node nodeA = new Node("Java"); Node nodeB = new Node("is"); Node nodeC = new Node("fun!"); wordList.append(nodeA); wordList.append(nodeB); wordList.append(nodeC); nodeB.previous is ________.
null
Assume the code below has been executed using a doubly linked list. Linkedlist wordList = new LinkedList(); Node nodeA = new Node("Java"); Node nodeB = new Node("is"); Node nodeC = new Node("fun!"); wordList.append(nodeA); wordList.append(nodeB); wordList.append(nodeC); nodeC.next is ______________.
Is empty
Assume the queue is implemented using a linked list. If the head pointer is null, the queue ________.
null
Assume the stack is implemented using a linked list. An empty stack is indicated by a list head pointer value of ________.
O(log(N))
Assuming nVals is an integer, what is the Big O notation for the worst case runtime? nVals = N steps = 0 while (nVal > 0) { nVal = nVal / 2 Steps = steps + 1 }
6
BinarySearch(numbers, low, high, key) { if (low > high) return -1 mid = (low + high) / 2 if (numbers[mid] < key) { return BinarySearch(numbers, mid + 1, high, key) } else if (numbers[mid] > key) { return BinarySearch(numbers, low, mid - 1, key) } return mid } Suppose BinarySearch is used to search a key within a list with 64 numbers. If the key is not found, how many recursive calls to BinarySearch are made?
True Bubble sort only swaps adjacent elements, so numerous swap are used to move elements into sorted order.
Bubble sort only swaps adjacent elements.
False Bubble sort uses 2 loops, the second of which is nested inside the first.
Bubble sort uses a single loop to sort the list.
True
Bubble sort's best and worst runtime complexity is O(N^2)
False
Calling ShellShort with gap array (7, 3, 1) vs )3, 7, 1), produces the same result with no difference in efficiency.
False The k argument is 0-based, so k = 0 corresponds to the smallest element in the list, not k = 1.
Calling quickselect with argument k equal to 1 returns the smallest element in the list.
True
Certain hardware may execute division more slowly than multiplication, but both may still be constant time operations.
False Collection.sort() doesn't require an object to compare list elements, but does support such an object.
Collections.sort() has a required second argument that references an object that compares list elements.
a collection that implements the List interface.
Collectons.sort() can sort only _______.
True
Computational complexity analysis allows the efficiency of algorithms to be compared.
False The bucket depends on what digit is being used to place the integers into buckets.
Consider integers X and Y, such that X < Y. X will always be in a lower bucket than Y
Unsorted
Determine if each of the following lists is unsorted, sorted, or nearly sorted. Assume ascending order. (15, 19, 21, 24, 2, 3, 6, 11)
Nearly Sorted
Determine if each of the following lists is unsorted, sorted, or nearly sorted. Assume ascending order. (23, 24, 36, 48, 19, 50, 101)
Sorted
Determine if each of the following lists is unsorted, sorted, or nearly sorted. Assume ascending order. (6, 14, 85, 102, 102, 151)
True
Determine if the low and high partitions are correct given highIndex and pivot. pivot = 35 1, 4, 35(highIndex), 62, 96
False
Determine if the low and high partitions are correct given highIndex and pivot. pivot = 5 5 13(highIndex) 16 77 84 20 19
True
Determine if the low and high partitions are correct given highIndex and pivot. pivot = 65 29 17 65 39(highIndex) 84
True
Determine if the low and high partitions are correct given highIndex and pivot. pivot = 8 8 3 8 41 57 8
O(N^2)
Determine the Big O worst case runtime for each algorithm for (i = 0; i < N; ++i) { for (j = i; j < N - 1; ++j) { cVals[i][j] = inVals[i] * j } }
O(N^3)
Determine the Big O worst case runtime for each algorithm for (i = 0; i < N; ++i) { sum = 0 for (j = 0; j < N; ++j) { for (k = 0; k < N; ++k) { sum = sum + aVals[i][k] * bVals[k][j] } cVals[i][j] = sum } }
O(N^2)
Determine the Big O worst case runtime for each algorithm for (i = 0; i < N; i = i + 2) { for (j = 0; j < N; i = j + 2) { cVals[i][j] = inVals[i] * j } }
O(N^2)
Determine the Big O worst case runtime for each algorithm for (i = 0; i < N; i++) { for (j = 0; j < N; j++) { if (numbers[i] < numbers[j]) { ++eqPerms } else { ++neqPerms } } }
O(N^2)
Determine the Big O worst case runtime for each algorithm for (i = 0; i < N; i++) { for j = 0; j < (N - 1); j++) { if (numbers[j + 1] < numbers[j]) { temp = numbers[j] numbers[j] = numbers[j + 1] numbers[j + 1] = temp } } }
2
Determine the index j and the left and right partitions. numbers = (1, 2, 3, 4, 5) i = 0, k = 4 j = ___?
(1, 2, 3)
Determine the index j and the left and right partitions. numbers = (1, 2, 3, 4, 5), i = 0, k = 4 Left partition = ( _______ )?
(4, 5)
Determine the index j and the left and right partitions. numbers = (1, 2, 3, 4, 5), i = 0, k = 4 Right partition = ( ______)?
35
Determine the index j and the left and right partitions. numbers = (34, 78, 14, 23, 8, 35), i = 3, k = 5 Right partition = ( _______)?
(23, 8)
Determine the index j and the left and right partitions. numbers = (34, 78, 14, 23, 8, 35), i = 3, k = 5 j = ____?
4 j = (3 + 5) / 2
Determine the index j and the left and right partitions. numbers = (34, 78, 14, 23, 8, 35), i = 3, k = 5
2
Determine the midpoint and pivot values. numbers = (1, 2, 3, 4, 5), lowIndex = 0, highIndex = 4. Midpoint = ______?
3
Determine the midpoint and pivot values. numbers = (1, 2, 3, 4, 5), lowIndex = 0, highIndex = 4. Pivot = _____?
1
Determine the midpoint and pivot values. numbers = (200, 11, 38, 9), lowIndex = 0, highIndex = 3. Midpoint = ______?
11
Determine the midpoint and pivot values. numbers = (200, 11, 38, 9), lowIndex = 0, highIndex = 3. pivot = _____?
5
Determine the midpoint and pivot values. numbers = (55, 7, 81, 26, 0, 34, 68, 125), lowIndex = 3, highIndex = 7 midpoint = ______?
34
Determine the midpoint and pivot values. numbers = (55, 7, 81, 26, 0, 34, 68, 125), lowIndex = 3, highIndex = 7. pivot = ____?
False EMPTY_AFTER_REMOVAL is a final field, so the field's value can never change after initialization.
EMPTY_AFTER_REMOVAL can be reassigned to a new bucket, if needed.
False The insert(), remove(), and search() methods have the same logic for all hash tables that use open addressing and thus are implemented in the OpenAddresingHashTable class. Inheriting classes need only implement the probe() method.
Each class that extends the OpenAddressingHashTable class must implement the probe(), insert(), remove(), and search() methods.
Two A doubly linked list node contains two pointers: A pointer to the next node and a pointer to the previous node.
Each node in a doubly linked list contains data and _______ pointer(s).
True The Node class declares the data member as an int for simplicity of illustration. Real world implementations commonly use an Object or generic type for greater flexibility.
Each node's data is an integer.
[ (18, 12), (10, 14) ] The sort is based on index 1, which is the second value. The keys are 12 and 14 from the items (18, 12) and (10, 14).
Enter the contents of the resulting sorted lists in the format: a, b, c. If the code is invalid enter Invalid. num_list = [ (10, 14), (18, 12) ] result = sorted(num_list, key = operator.itemgetter(1))
[Invalid] The itemgetter() is trying t access index 3, which is out of range for the items in this list.
Enter the contents of the resulting sorted lists in the format: a, b, c. If the code is invalid enter Invalid. num_list = [ (10, 14, 0), (2, 1, 40), (6, 10, 4) ] result = sorted(num_list, key = operator.itemgetter(3))
'eight', 'two', 'four', 'six'
Enter the contents of the resulting sorted lists in the format: a, b, c. If the code is invalid enter Invalid. word_list = [ 'two', 'four', 'six', 'eight' ] result = sorted(word_list, key = operator.itemgetter(2))
False For an ascending sort, -1 is returned when the first argument is less than the second. So for a descending sort, 1, not -1, is returned when the first argument is less than the second.
For a descending sort, a compare() method should return -1 when the first argument is less than the second.
O(1) Hash tables support fast search, insert, and remove.
For a well designed hash table, searching requires ________ on average.
2
For each question, assume a list with 6 elements. If a gap value of 2 is chosen, how many interleaved lists will be sorted?
4
For each question, assume a list with 6 elements. If a gap value of 4 is chosen, how many interleaved lists will be sorted?
3
For each question, assume a list with 6 elements. With a gap value of 3, how many interleaved lists will be sorted?
2
For each question, assume a list with 6 elements. With a gap value of 3, how many items will be in each interleaved list?
(-78, -42, -12)
For each question, assume radix sort has sorted integers by absolute value to produce the array (-12, 23, -42, 73, -78), and is about to build the negative and non-negative buckets to complete the sort. After reversal, what integers are in the negative bucket?
(-12, -42, -78)
For each question, assume radix sort has sorted integers by absolute value to produce the array (-12, 23, -42, 73, -78), and is about to build the negative and non-negative buckets to complete the sort. What integers will be places into the negative bucket?
(23, 73)
For each question, assume radix sort has sorted integers by absolute value to produce the array (-12, 23, -42, 73, -78), and is about to build the negative and non-negative buckets to complete the sort. What integers will be places into the non-negative bucket?
(-78, -42, -12, 23, 73)
For each question, assume radix sort has sorted integers by absolute value to produce the array (-12, 23, -42, 73, -78), and is about to build the negative and non-negative buckets to complete the sort. What is the final array after RadixSort concatenates the two buckets?
True If the list has n items, then the items use indices 0 through n - 1 in the internal array. The next available index will be n, which is the value of arrayListLength.
For each question, assume the following code has been executed. int[ ] numbers = { 6, 2, 8, 4, 3 }; ArrayList myList = new ArrayList(3); for (int number : numbers) { myList.append(number); } The append() method uses data member arrayListLength as the index of the next available space in the internal array.
True After resizing once, the internal array's allocation size is 6. The array initially has all values set to 0, so after appending 5 items, a single 0 value is in the final index position.
For each question, assume the following code has been executed. int[ ] numbers = { 6, 2, 8, 4, 3 }; ArrayList myList = new ArrayList(3); for (int number : numbers) { myList.append(number); } The content of myList.arrayData is: 6, 2, 8, 4, 3, 0
False removeAt() removes the value at the given index, which is zero based. So removeAt(4) removes the last item, which is the number 3. The resulting list is: 6, 2, 8, 4
For each question, assume the following code has been executed. int[ ] numbers = { 6, 2, 8, 4, 3 }; ArrayList myList = new ArrayList(3); for (int number : numbers) { myList.append(number); } The method call myList.removeAt(4) results in the list 6, 2, 8, 3
True The list has 5 items, so valid indices for removeAt() are 0-4.
For each question, assume the following code has been executed. int[ ] numbers = { 6, 2, 8, 4, 3 }; ArrayList myList = new ArrayList(3); for (int number : numbers) { myList.append(number); } The method call myList.removeAt(5) has no effect.
False search() returns -1 if the search item is not found, not the Boolean value false.
For each question, assume the following code has been executed. int[ ] numbers = { 6, 2, 8, 4, 3 }; ArrayList myList = new ArrayList(3); for (int number : numbers) { myList.append(number); } The method call myList.search(1) returns false.
False The internal array's initial size is 3 (from the constructor). When the 4th item is added, resize() is called to expand the allocation size to 6. Only 5 items are added in total, so no more resizing is needed.
For each question, assume the following code has been executed. int[ ] numbers = { 6, 2, 8, 4, 3 }; ArrayList myList = new ArrayList(3); for (int number : numbers) { myList.append(number); } The resize() method is called twice.
3 insertAfter() inserts 9 immediately after index 2. The index after 2 is 3.
For each question, assume the following code has been executed. int[ ] numbers = { 6, 2, 8, 4, 3 }; ArrayList myList = new ArrayList(3); for (int number : numbers) { myList.prepend(number); } myList.insertAfter(2, 9); At what index is the number 9?
3, 4, 8, 9, 2, 5, 6 The list is 3, 4, 8, 9, 2, 6 prior to inserting the number 5 after index 4. The number 5 is then inserted between 2 and 6.
For each question, assume the following code has been executed. int[ ] numbers = { 6, 2, 8, 4, 3 }; ArrayList myList = new ArrayList(3); for (int number : numbers) { myList.prepend(number); } myList.insertAfter(2, 9); What is the list's content after executing the additional statement below? myList.insertAfter(4, 5);
3 3 is the number most recently prepended to the list and therefore resides at index 0 in the list.
For each question, assume the following code has been executed. int[ ] numbers = { 6, 2, 8, 4, 3 }; ArrayList myList = new ArrayList(3); for (int number : numbers) { myList.prepend(number); } myList.insertAfter(2, 9); What number is at index 0 in the list?
0
For each question, consider the array of integers: 51, 47, 96, 27. When placing integers in the 1's digit, how many integers will be in bucket 5?
2
For each question, consider the array of integers: 51, 47, 96, 27. When placing integers using the 1's digit, how many integers will be in bucket 7?
1
For each question, consider the array of integers: 51, 47, 96, 27. When placing integers using the 10's digit, how many will be in bucket 9?
True Because every integer is less than 100, the 100's digit in each integer is implicitly 0.
For each question, consider the array of integers: 51, 47, 96, 27. all integers would be in bucket 0 if using the 100's digit.
list head
For the operation QueuePop(queue), poppedItem contains a pointer to the ____________
0 If ListRemoveAfter's second parameter is 0, the list's head node is removed. That head node is the queue's front node.
For the operation QueuePop(queue), what is the second parameter passed to ListRemoveAfter?
S(N) = k
GetEvent(list, listSize) { i = 0 evensList = Create new, empty list while (i < listSize) { if (list[i] % 2 == 0) Add list[i] to evensList i = i + 1 } return evensList } What is the best case auxiliary space complexity of GetEvent if N
listSize
GetEvent(list, listSize) { i = 0 evensList = Create new, empty list while (i < listSize) { if (list[i] % 2 == 0) Add list[i] to evensList i = i + 1 } return evensList } What is the maximum possible size of the returned list?
0
GetEvent(list, listSize) { i = 0 evensList = Create new, empty list while (i < listSize) { if (list[i] % 2 == 0) Add list[i] to evensList i = i + 1 } return evensList } What is the minimum possible size of the returned list?
S(N) = N + k
GetEvent(list, listSize) { i = 0 evensList = Create new, empty list while (i < listSize) { if (list[i] % 2 == 0) Add list[i] to evensList i = i + 1 } return evensList } What is the worst case space complexity of GetEvent if N is the list's size and k is a constant?
Head
Given a doubly linked list with nodes 20, 67, 11, node 20 is the ________.
4
Given a doubly linked list with nodes: 4, 7, 5, 1, node 7's previous pointer points to node
3
Given a doubly linked list with nodes: 8, 12, 7, 3, node 7's next pointer points to node
34 334 % 100 = 34 The insert operation uses the hash function to determine the bucket index.
Given a hash table with 100 buckets and modulo hash function, in which bucket will HashInsert(table, item 334) insert item 334?
1 201 % 50 = 1. Search, insert, and remove operations all use the hash function to determine the bucket index.
Given a hash table with 50 buckets and modulo hash function, in which bucket will HashSearch(table, 201) search for the item?
search
Given a key, a _____________ algorithm returns the first node whose data matches that key, or returns null if a matching node was not found.
2µs
Given a list of 10,000 element, and if each comparison takes 2µs, what is the fastest possible runtime for linear search?
20000µs
Given a list of 10,000 element, and if each comparison takes 2µs, what is the longest possible runtime for linear search?
11µs
Given a list of 1024 elements, what is the runtime for binary search if the search key is less than all elements in the list?
append
Given a new element, the ________ operation for an array based list of length X inserts the new element at the end of the list, or at index X.
Prepend
Given a new node, the ________ operation for a singly linked list inserts the new node before the list's head node.
Append
Given a new node, the ________ operations for a singly linked list inserts the new node after the list's tail node.
Append
Given a new node, the _________ operation for a doubly linked list inserts the new node after the list's tail node.
InsertAfter
Given a new node, the __________ operation for a doubly linked list inserts the new node after a provided existing list node.
InsertAfter
Given a new node, the ___________ operation for a singly linked list inserts the new node after a provided existing list node.
5
Given an array with 32 elements, how many list elements will be checked if the key is less than all elements in the list, using binary search?
2, 9, 4 Peek returns, but does not remove, the item at the top of the stack.
Given callStack: 2, 4, 9 What are the contents of the stack after Peek(callStack)?
4
Given inventoryStack: 70, 888, -3, 2 What does GetLength(inventoryStack) return?
4, 7, 5
Given jobsDeque:4, 7, 5, what are the deque contents after PeekBack(jobsDeque)?
True If k <= the last index in the low partition, then the recursive call searches the low partition.
Given k = 4, is the quickselect call Partition (numbers, 0, 10) returns 4, then the element being selected is in the low partition.
3
Given list: (4, 11, 17, 18, 25, 45, 63, 77, 89, 114) How many list elements will be checked to find the value 17 using binary search?
2
Given list: (4, 11, 17, 18, 25, 45, 63, 77, 89, 114) How many list elements will be checked to find the value 77 using binary search?
11
Given list: [20, 4, 114, 23, 34, 25, 45, 66, 77, 89, 11] How many list elements will be checked if the search key is not found using linear search?
3
Given list: [20, 4, 114, 23, 34, 25, 45, 66, 77, 89, 11] How many list elements will be checked to find the value 114 using linear search?
9
Given list: [20, 4, 114, 23, 34, 25, 45, 66, 77, 89, 11] How many list elements will be compared to find 77 using linear search?
four
Given numList is: 5, 8, 3, 2. ListTraverse(numsList) visits ____ node(s).
9
Given numStack: 2, 9, 5, 8, 1, 3 (top is 2). What is returned by the second pop operation? Pop(numStack) Pop(numStack) _______
4, 11, 34, 20
Given numStack: 34, 20 (top is 34) Type the stack after the following push operation. Type the stack as: 1, 2, 3 Push(numStack, 11) Push(numStack, 4) ____________
2, 8
Given numStack: 41, 8 (top is 41) What is the stack after the following operations?
5
Given numStack: 5, 9, 1 (top is 5) What is returned by the following pop operation? Pop(numStack)
8, 7, 5
Given numStack: 7, 5 (top is 7) Type the stack after the following push operation. Type the stack as: 1, 2, 3 Push(numStack, 8) __________
2
Given numbers (7, 4, 2, 25, 19) lowIndex = 0, and highIndex = 4, what are the contents of the low partition? type answer as 1, 2, 3
6
Given rosterDeque: 351, 814, 216, 636, 48, 102, what does GetLngth(rosterDeque) return?
0
Given that jobsDeque is empty, what does GetLength(jobsDeque) return?
0 and 5
Given the call InsertionSortInterleaved(values, 10, 0, 5), what are the indices of the first two elements compared?
5
Given the call InsertionSortInterleaved(values, 4, 1, 4), what is the value of the loop variable i in the for loops first insertion?
9, 4
Given the callStack: 2, 9, 4 What are the contents of the stack after Pop(callStack)?
5, 6, 8, 7, 9
Given the list (5, 9, 8, 7, 6) and i = 1, what will be the list after completing the second outer loop iteration?
9, 1
Given the numStack: 5, 9, 1 (top is 5) What is the stack after the following pop operation? Pop(numStack) _________
5 (16 % 11 + 0 * (5 - 16 % 5)) % 11 = 5 The bucket at index 5 is empty prior to the insertion of 16, so item 16 is stored at index 5.
Given: hash1(key) = key % 11 hash2(key) = 5 - key % 5 and a hash table with a size of 11. Determine the index for each item after the following operations have been executed. Item 16 ____________.
10 55 % 11 = 0, but the bucket at index 0 already holds item 77. i is incremented to 1, and the bucket index is computed as (55 % 11 + 1 * (5 - 55)) % 11 = 5. Bucket 5 is occupied by item 16, so i is incremented to 2, and the bucket index is computed as (55 % 11 + 2 * ( 5 - 55 % 5)) % 11 = 10. Bucket 10 is empty, so item 55 is inserted into this bucket.
Given: hash1(key) = key % 11 hash2(key) = 5 - key % 5 and a hash table with a size of 11. Determine the index for each item after the following operations have been executed. Item 55 _____________
1 63 % 11 = 8, but the bucket at index 8 already holds item 41. i is incremented to 1, and the bucket index is computed as (63 % 11 + 1 * (5 - 63 % 5)) % 11 = 10. Bucket 10 is occupied by item 55, so i is incremented to 2 and the bucket index is computed as (63 % 11 + 2 * (5 - 63 % 5)) % 11 = 1. Bucket 1 is empty, so item 63 is inserted in this bucket.
Given: hash1(key) = key % 11 hash2(key) = 5 - key % 5 and a hash table with a size of 11. Determine the index for each item after the following operations have been executed. Item 63 __________
3
How many array items are compared to he key by binarySearch() for the example? Array: (12, 18, 22, 34, 41, 74, 88) Key: 10
2
How many array items are compared to he key by binarySearch() for the example? Array: (12, 18, 22, 34, 41, 74, 88) Key: 74
7
How many comparisons are performed by linear_search()? List: 12, 75, 18, 22, 94, 16, 22 Key: 10
4
How many comparisons are performed by linear_search()? List: 12, 75, 18, 22, 94, 16, 22 Key: 22
5
How many comparisons are performed by linear_search()? List: 12, 75, 18, 22, 94, 16, 22 Key: 94
7
How many comparisons are performed by the linearSearch() for the example? Array:(12, 75, 18, 22, 94, 16, 22) Key: 10
4
How many comparisons are performed by the linearSearch() for the example? Array:(12, 75, 18, 22, 94, 16, 22) Key: 22
5
How many comparisons are performed by the linearSearch() for the example? Array:(12, 75, 18, 22, 94, 16, 22) Key: 94
500
How many elements will the temporary merge list have for merging two partitions with 250 elements each?
3
How many list items are compared to the key by binary_search() for the example? List: [12, 18, 22, 34, 41, 74, 88] Key: 10
2
How many list items are compared to the key by binary_search() for the example? List: [12, 18, 22, 34, 41, 74, 88] Key: 74
10 log_2(1024)
How many partitioning levels are required for a list of 1024 elements?
1023
How many partitioning levels are required for a list of 1024 elements?
4 1st: (a) (b, c, d, e) 2nd: (a) (b) (c, d, e) 3rd: (a) (b) (c) (d, e) 4th: (a) (b) (c) (d) (e)
How many partitioning levels are required for a list of 5 elements?
3 1st: (a, b, c, d) (e, f, g, h) 2nd: (a, b) (c, d) (e, f) (g, h) 3rd: (a) (b) (c) (d) (e) (f) (g) (h)
How many recursive partitioning levels are required for a list of 8 elements?
11 log_2(2048) = 11
How many recursive partitions levels are required for a list of 2048 elements?
13
How many times is InsertionSortInterleaved called if ShellSort is called with gap array (10, 2, 1)?
4: (20^2 / 10^2)
How many times longer will sorting a list of 20 elements take compared to sorting a list of 10 elements?
100: (500^2 / 50^2)
How many times longer will sorting a list of 500 elements take compared to a list of 50 elements?
2047
How many total calls to the Quicksort() function are made to sort a list of 1024 elements?
10240 log_2(1024) * 1024 = 10 * 1024
How many total comparisons are required to sort a list of 1024 elements?
True
If 10 buckets were used instead of 5, no bucket would have more than 1 number.
5
If Factorial(6) is called, how many additional calls are made to Factorial to compute the result of 720? Factorial(N) { if (N ==1) return 1 else return N * Factorial(N - 1) }
False
If a gap value of 2 is chosen, then the following 2 function calls will fully sort a list: InsertionSortInterleaved(list, 9, 0, 2) InsertionSortInterleaved(list, 9, 1, 2)
5
If mergeSort() is called with i = 0 and k = 4, what is the size of the partition that will be sorted?
2
If mergeSort() is called with i = 0 and k = 5, what is the value of j after the following line executes? j = (i + K ) / 2; ?
2 (0 + 5) / 2 is 2.5, but (0 + 5) // 2 is 2.
If merge_sort is called with i = 0 and k = 5 what is the value of j after the folloing line executes? j = (i + k) // 2?
26
If shellSort() is run with an input array of size 20 and a gap values array of {15, 7, 3, 1}, how many times will insertionSortInterleaved() be called?
26
If shell_sort() is run with an input list of size 20 and a gap values list of [15, 7, 3, 1], how many times will insertion_sort_interleaved() be called?
-20, -40
If the array {0 , 10, -20, 30, -40} is passed to radixSort(), then before the method's last 2 for loops execute, the contents of negatives are _________.
3
If the array {56, 19, 2, 101, 70} is passed to the radixSort(), after the line int maxDigits = radixGetMaxLength(numbers), what is the value of max digits?
False
If the insertionSortInterleaved() method runs with an array of size 10, startIndex assigned with 2, and gap assigned with 3, then the loop variable i will be assigned with the values 2, 5, and 8.
False
If the insertion_sort_interleaved() function runs with a list of size 10, start_index assigned with 2, and gap assigned with 3, then the loop variable i will be assigned with the values 2, 5, and 8.
3 radix_get_max_length() returns the maximum length, in number of digits, among all list values. The value 101 has the maximum length of 3 digits.
If the list [56, 19, 2, 101, 70] is passed to radix_sort(), after the line max_digits = radix_get_max_length(numbers), what is the value of max_digits?
5 k + 1, 4 + 1 = 5
If the merge_sort is called with i = 0 and k = 4, what is the size of the partition that will be sorted?
len(bucket) The extend function adds all elements from bucket to numbers, making the length of the previously empty numbers list equal to the length of the bucket.
If the numbers list is empty prior to the line numbers.extend(bucket), which expression represents the length of numbers after this line?
True return item1.name.compareTo(item2.name); yields an ascendnig sort, so return item2.name.compareTo(item1.name); yields a descending sort name.
Implementing a compare() method with the following code allows for a descending sort by item name. return item2.name.compareTo(item1.name);
True In a list with 1 node, the tail's next and previous pointers point to the only node in the list.
In a circular linked list with 1 node, the tail node's next pointer points to the tail.
List head
In a circular linked list with at least 2 nodes, where does the tail node's next pointer point to?
True
In a doubly linked list the first node's previous data member is null.
The node before the node to be removed remove_after() removes a node after an existing node, known as current_node
In remove_after(), what does the variale current_node sigify?
True
In the code below, suppose str1 is a pointer or reference to a string. The code only executes in constant time if the assignment copies the pointer/reference, and not all the characters in the string. srt2 = str1
45 µs: (1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9) * 1µs
In the worst case, assuming each comparison takes 1 µs, how long will insertion sort algorithm take to sort a list of 10 elements?
False Insertion sort has a runtime of O(N^2).
Insertion sort is a fast sorting algorithm.
True
InsertionSort() is the same as InsertionSortInterleaved() with a gap space of 1.
False
InsertionSortInterleaved will result in an out of bounds array access if called on an array of size 4, a starting index of 1, and a gap value of 4
True
Insertion_sort() is the same as insertion_sort_interleaved() with a gap space of 1.
False Base-10 integers have 10 possible values (0 - 9) for a digit, meaning 10 buckets are necessary regardless of array size.
Integers will be paced into buckets based on the 1's digit. More buckets are needed for an array with one thousand integers than for an array with one hundred integers.
False Example: A difference of 0.25 means that item2's price is greater, so a positive integer must be returned. But casting 0.25 yields 0, not a positive integer.
InventoryItemReversePriceComparer's compare() method could also be implemented as: return (int) (item2.price - item1.price);
Probing sequence
Iterating through sequential i values to obtain the desired table index is called the __________________.
class Linkedlist { private Node head; private Node tail; public LinkedList() { head = null; tail = null; } }
LinkedList class definition for a doubly lined list.
head
ListSeatch starts with the list's ________ node.
the list's head node
ListTraverse begins with ____________.
True
ListTraverse can be used to traverse a doubly-linked list.
False Reverse traversal cannot be used for a singly-linked list, because singly-linked list nodes do not contain a pointer to the previous node.
ListTraverseReverse can be used to traverse a singly-linked list.
insert()
May return true without changing the length of a bucket's linked list.
True Merge sort's average runtime is O(NlogN).
Merge sort is a fast sorting algorithm.
lowIndex + (highIndex - lowIndex) / 2
Midpoint formula??
False
Nearly every algorithm has a best-case time complexity when N = 0.
True The prepend, append, and insert after operations may resize the list's array, but search and remove do not.
Neither search nor remove all will resize the list's array.
class Node { public int data; public Node next; public Node previous; public Node(int initialData) { data = initialData; next = null; previous = null; } }
Node class definition for a doubly liked node.
arrayListLength
Number of array elements currently in use.
Constant
O(5) has a ______ runtime complexity.
Quadratic
O(N + N^2) has a ________ runtime complexity.
Log Linear
O(N log(N)) has a ________ runtime complexity.
False Either a single or doubly linked list can be circular.
Only a doubly-linked list can be circular.
True EMPTY_SINCE_START is a static field, not an instance variable. So only one instance exists and is independent of the number of OpenAddressingBucket instances created.
Only one instance of EMPTY_SINCE_START exists, no matter how many OpenAddressingBucket instances are created.
sorted()
Python has a built-in ________ function that takes one list argument, sorts the list's elements in ascending order using the less thna operator, and returns a new list with sorted elements.
sort()
Python lists also have a _______ method to do an in-place sorting of list elements in ascending order, meaning the list is modified and another list is not returned.
False Both Stack pop() and Queue dequeue() methods operate exactly the same by removing the head node and returning the removed node's data.
Queue's dequeue() method operates differently than Stack's pop() method.
False Both the Stack and Queue pop() method operate exactly the same by removing the head element and returning the removed element.
Queue's pop() method operated differently than Stack's pop() method.
True Radix sort's average runtime is O(N), which is better than O(NlogN).
Radix sort is a fast sorting algorithm.
False RadixSort makes use of digits, and thus only works for integers. Example: The statement bucketIndex abs(array[i] / pow10) % 10 specifically requires the array to be an integer.
RadixSort can be used to sort an array of strings.
False Radix sort uses 10 buckets, but the number of integers in the buckets increases as the array gets larger. Because buckets collectively must store the entire array's contents of n elements, the space complexity of RadixSort is O(n).
Raidx sort has a space complexity of O(1).
arrayData
Reference to array data.
False Removing the element at index 0 is the worst case, because all items in the array except the first, need to be moved down 1 position.
Removing at index 0 yields the best case runtime for remove-at.
remove()
Returns false and makes no change to a bucket's linked list if the key is not found.
search()
Returns null if the key is not found.
False
Runtime and memory usage are the only two resources making up computational complexity.
True All elements in the array are compared against the search key before the search algorithm determines that the key is not found.
Searching for a key that is not in the list yields the worst case runtime for search.
Compute the bucket, call append(item) on the bucket list.
Select the proper order of steps for the following processes. Insert an item into a hash table with chaining.
Compute the bucket index, check if the key is in the bucket list, call remove(key) on the bucket list (if present)
Select the proper order of steps for the following processes. Remove an item from a hash table with chaining.
Compute the bucket index, check if the key is in the list, return the list (or None).
Select the proper order of steps for the following processes. Search for an item in a hash table with chaining.
True
Selection sort can be used to sort an array of strings.
True
ShellSort will properly sort an array using any collection of gap values, provided the collection contains 1.
True
StackPop points a local variable to the list's head node.
3
Suppose BinarySearch(numbers, 0, 7, 42) is used to search the list (14, 26, 42, 59, 71, 88, 92) for key 42. How many calls to BinarySearh will be made by the time 42 is found?
59
Suppose BinarySearch(numbers, 0, 7, 42) is used to search the list (14, 26, 42, 59, 71, 88, 92) for key 42. What is the first middle element that is compared against 42?
low = 0, high = 2
Suppose BinarySearch(numbers, 0, 7, 42) is used to search the list (14, 26, 42, 59, 71, 88, 92) for key 42. What will the low and high argument values be for the first recursive call?
The list element at index mid is less than the key.
Suppose BinarySearch(numbers, 0, 7, 42) is used to search the list (14, 26, 42, 59, 71, 88, 92) for key 42. Which does not describe a base case for a BinarySearch?
False
Suppose BucketSort is called to sort the list (71, 22, 99, 7, 14), using 5 buckets. 71 and 99 will be placed in the same bucket.
False
Suppose BucketSort is called to sort the list (71, 22, 99, 7, 14), using 5 buckets. No bucket will have more than 1 number.
False
Suppose ReversalList is called on a list of size 3, a start of index 0, and an out-of-bounds end index of 3. The base case ensures that he function still properly sorts the list ReversalList(list, startIndex, endIndex) { if (startIndex >= endIndex) return else { Swap elements at startIndex and endIndex ReversalList(list, startIndex + 1, endIndex - 1) } }
True
Suppose T(N) = 2N^2 + N + 9 T(N) = O(N^2)
True
Suppose T(N) = 2N^2 + N + 9 T(N) = O(N^3)
False
Suppose T(N) = 2N^2 + N + 9 T(N) = 𝛀(N^2)
False
Suppose T(N) = 2N^2 + N + 9 T(N) = 𝛀(N^3)
True
Suppose T(N) = 2N^2 + N + 9 T(N) =𝞗(N^2)
N
Suppose a recursive function's runtime is T(N) = 7 + T(N - 1) How many levels will the recursion tree have?
O(N)
Suppose a recursive function's runtime is T(N) = 7 + T(N - 1) What is the runtime complexity of the function using O notation?
N
Suppose a recursive function's runtime is T(N) = N + T(N - 1) How many levels will the recursion tree have?
(N / 2) * (N + 1)
Suppose a recursive function's runtime is T(N) = N + T(N - 1) The runtime can be expressed by the series N + (N - 1) + (N - 2) + ... + 3 + 2 + 1. Which expression is mathematically equivalent?
O(N^2)
Suppose a recursive function's runtime is T(N) = N + T(N - 1) What is the runtime complexity of the function using O notation?
True
Suppose an algorithm's best case runtime complexity is T(N) = 3N + 6, and the algorithm's worst case runtime is T(N) = 5N^2 + 7N 5N^2 is an upper bound for the algorithm
3N
Suppose an algorithm's best case runtime complexity is T(N) = 3N + 6, and the algorithm's worst case runtime is T(N) = 5N^2 + 7N Which function is a lower bound for the algorithm?
12N^2
Suppose an algorithm's best case runtime complexity is T(N) = 3N + 6, and the algorithm's worst case runtime is T(N) = 5N^2 + 7N Which function is an upper bound for the algorithm?
True
Suppose the following code is executed: int[ ] numbers = {8, 2, 7, 6, 1, 4, 3, 5]; quicksort (numbers, 3, 6); After this code finished, the numbers array would be: {6, 2, 7, 1, 3, 4, 6, 5}
5
Suppose the selectionSort() method is executed with the array (3, 12, 7, 2, 9, 14, 8) What is the final value for the variable i inside the inner loop?
1
Suppose the selectionSort() method is executed with the array (3, 12, 7, 2, 9, 14, 8) When i is assigned with 0 in the outer loop, what is j assigned with in the inner loop?
5: The outer loop assigns i wih all indices except the final index, which is 6.
Suppose the selection_sort() function is executed with the list [3, 12, 7, 2, 9, 14, 8] What is the final value for the variable i inside the inner loop?
1: The inner loop always starts with j = i + 1 so 3 would be compared to 12.
Suppose the selection_sort() function is executed with the list [3, 12, 7, 2, 9, 14, 8] When i is assigned with 0 in the outer loop, what is j assigned with in the inner loop?
if type(self.table[bucket]) is EmptyBucket
Tests if a bucket is any type of empty.
if self.table[bucket] is self.EMPTY_SINCE_START
Tests if a bucket is empty, and has never held an item.
if self.table[bucket] is self.EMPTY_AFTER_REMOVAL
Tests if a bucket is empty, but only after holding a data item at one point.
True The Node class has a member for a node's data value and for the next node in the list.
The Node class has two data members.
True Every table that uses open addressing needs an allocated array of buckets, each initially set to EMPTY_SINCE_START
The OpenAddressingHashTable class allocatesthe table array in the constructor and sets each bucket to EMPTY_SINCE_START
False AN item os any type can be passed as an argument to hash(). The hash() function returns an integer, regardless of the item's type.
The Python build in hash() function must take an integer argument.
True New elements are added to the end of a queue.
The Queue class' push() method uses the LinkedList append() method to insert elements into a queue.
True New elements are added to the end of a queue.
The Queue class's enqueue() method uses the LinkedList append() method to insert elements in a queue.
False The stack class only has a LinkedList data member.
The Stack class has both a LinkedList and Node data member.
False Stack's push() method calls LinkedList's prepend() method because new elements are places on the top of the stack, not at the bottom of the stack.
The Stack class' push() method uses the LinkedList append() method to place elements on a stack.
False The push() method takes an int, not a Node, as a parameter. The method created a new node, whose data is the integer parameter, and inserts the new node into the linked list.
The Stack class's push() method takes a Node as a parameter.
False Stack's push() method calls LinkedList's prepend() method because new elements are placed on the top of the stack, not at the bottom of the stack.
The Stack class's push() method uses the LinkedList append() method to place elements on a stack.
prepend
The __________ operation for an array based list inserts a new item at the start of the list.
Remove
The ____________ operation for a doubly linked list removes a provided existing list node.
InsertAfter
The ____________ operation for an array based list inserts a new item after a specified index.
False: The array must be sorted (12, 16, 18, 22, 22, 75, 94)
The array (12, 75, 18, 22, 94, 16, 22) can be used as input to the binarySearch() method.
True
The base case is what ensures that a recursive algorithm eventually terminates.
True Each element is the array is a reference to the EMPTY_SINCE_START bucket.
The code below initializes a table of 11 empty-since-start buckets. OpenAddressingBucket[] buckets = new OpenAddressingBucket[11]; for (int i = 0; i < buckets.length; i++) { buckets[i] = OpenAddressingBucket.EMPTY_SINCE_START; }
True
The complexity of the algorithm below is O(1) for (i = 0; i < 24; ++i) { if (timeHour < 6) { tollSchedule[i] = 1.55 } else if (timeHour < 10) { tollSchedule[i] = 4.65 } else if (timeHour < 18) { tollSchedule[i] = 2.35 } else { tollSchedule[i] = 1.55 } }
True
The complexity of the algorithm below is O(1). if (timeHour < 6) { tollAmount = 1.55 } else if (timeHour < 10) { tollAmount = 4.65 } else if (timeHour < 18) { tollAmount = 2.35 } else { tollAmount = 1.55 }
after find_insertion_location() determines where in the list the current node should be after sorting. The current node is placed after the returned location.
The current node to be sorted is placed ________ the location returned by find_insertion_position().
False A node's value is always set to an initial value whether the node is in a list or not.
The data value of a node is set to None if the node is not in a list.
True
The fastest averate runtime complexity of a comparison sorting algorithm is O(N logN).
True A linked list's head node does not have a previous node, thus the prev data member has a value of None.
The first node in a doubly linked list has a previous value of None.
True
The following array is properly partitioned with pivot 17: {3, 1, 14, 12, 19, 17, 22}
True The forward and reverse traversal algorithms have the same structure. Reverse traversal starts at the tail, traverses using previous pointers, and stops when coming back to the tail node.
The following code can be used to traverse a circular, doubly linked list in reverse order. CurcularTraverseReverse(tail) { current = tail do { visit current current = current->previous } while (current != tail) }
True Each word will be converted to all lower-case for key comparisons. This sort could also be done without a custom key function by using the key = str.lower argument in sort() or sorted().
The following function can be sued as a key function to do a case-insensitive sort. def custom_key(word): return word.lower()
True Quickselect produces a result equivalent to that of sorting the list and returning the item at index k. But quickselect only partially sorts the list, and is often more efficient than sorting the entire list.
The following function produces the same result as quickselect, albeit with a different runtime complexity. Quickselect(numbers, first, last, k) { Quicksort (numbers, first, last) return numbers [ k ] }
True
The following list is properly partitioned with pivot 17: [3, 1, 14, 12, 19, 17, 22]
False
The hardware running the code is the only thing that affects what is and what is not a constant time operation.
False The modulo operator maps the key to a hash table bucket by diving the integer returned from hash() by the size of the hash table and returning the remainder, which must be between 0 and the size of the hash table -1.
The hash() function returns an integer that can be used directly as a bucket's index.
2147483600 Negative hash codes are added to 2147483648 before returning. -48 + 2147483645 = 2146483600
The hash() method returns _________ when key.hashCode() eturns -48.
True The insert(), remove(), and search() methods must each use the probing sequence to find the appropriate bucket for the given key.
The insert(), remove(), and search() methods each call the probe() method.
False The insertion algorithm can insert into empty-since-start and empty-since-removal buckets. Whichever bucket is encountered first in the probing sequence will be used for the insertion.
The insertion algorithm can only insert into empty-since-start buckets.
False
The insertionSortSinglyLinked() method can also sort a double linked list.
False Though doubly linked nodes have a next data member, the linked list data structure does not have the remove_after() method. The current insertion sort algorithm would need to be changed to accommodate the doubly linked list's remove() method.
The insertion_sort_singly_linked() method would also sort a doubly linked list.
False The list's length and allocation size are two separate values, such that the length is <= the array location size.
The length of an array based list equals the list's array allocation size.
False: The list must be in sorted order [12, 16, 18, 22, 22, 75, 94]
The list [12, 75, 18, 22, 94, 16, 22] can be used as input to the binary_search() function.
False
The list is sorted into ascending order: (3, 9, 44, 18, 76)
True
The list is sorted into ascending order: (chopsticks, forks, knives, spork)
True
The list is sorted into ascending order: (great, greater, greatest)
True
The list is sorted into descending order: (20, 15, 10, 5, 0)
True
The list is sorted into descending order: (99.87, 99.02, 67.93, 44.10)
True
The list is sorted into descending order: (F, D, C, B, A)
successor node
The node that comes immediately after the currentNode in the list is __________.
predecessor node
The node that comes immediately before the currentNode in the list ___________.
True
The partition method has O(N) runtime complexity.
True
The pop() method removed the head of a stack's LinkedList data member.
True pop() uses LinkedList's remove_after() method to remove the top element of the stack, which is the head of the stack's LinkedList data member.
The pop() method removed the head of a stack's LinkedList data member.
False
The presence of a base case is what identifies an algorithm as being recursive.
False Contents are copied from buckets to the numbers array each iteration, but the buckets' combined length equals the numbers array's length, so the numbers array is not reallocated.
The radixSort() method reallocated the numbers array during each iteration of the digit-index loop.
False The new line reassigns numbers to reference a net list, but the radix_sort() function should sort the elements in the list passed to the function.
The radix_sort function() would still operate correctly if the last line was changes from numbers.extend(negatives + non_negatives) to numbers = negatives + non_negatives.
True The search algorithm is used by the remove algorithm to find the correct bucket. If found, the removal algorithm must mark the bucket as empty-after-removal.
The removal algorithm searches for the bucket containing the key to remove. If found, the bucket is marked as empty-after-removal.
False Encountering a bucket with the key being searched for is not the only case that stops the search algorithm. Probing N buckets or encountering an empty-since-start bucket will also stop the search.
The search algorithm stops only when encountering a bucket containing the key being searched for.
True The sorted() function and the sort() method both can use a custom key function.
The sorted() function and the list's sort() method both take an optional argument for a key function.
pop
The stack ______ operation removes an returns the item at he top of the stack.
push
The stack ________ operation inserts an item on the top of the stack.
True
The statement below that assigns x with y is a constant time operation y = 10 x = y
False
The value 15 would be selected as the pivot in the array: {5, 3, 15, 72, 14, 41, 32, 18}
False
The value 15 would be selected as the pivot in the list: [5, 3, 15, 72, 14, 41, 32, 18]
False EMPTY_AFTER_REMOVAL's key and value fields are null and should not be used. A direct reference comparison between the bucket and EMPTY_AFTER_REMOVAL must be used instead. Ex: if (bucket == OpenAddressingBucket.EMPTY_AFTER_REMOVAL) { ... }
To check if a bucket is empty-after-removal, the bucket's key and value fields must be compared with EMPTY_AFTER_REMOVAL's key and value fields.
False The third argument must be the list size minus 1. list, 0, 9
To sort a list with 10 elements, the arguments passed to merge_sort will be: list, 0, 10.
False
To sort an array with 10 elements, the arguments passed to mergeSort() will be: array, 0, 10.
14
Trace the merge operation by determining the next value added to mergedNumbers 14 18 35 17 38 49 0 1 2 3 4 5 leftPos = 0, rightPos = 3
17
Trace the merge operation by determining the next value added to mergedNumbers 14 18 35 17 38 49 0 1 2 3 4 5 leftPos = 1, rightPos = 3
18
Trace the merge operation by determining the next value added to mergedNumbers 14 18 35 17 38 49 0 1 2 3 4 5 leftPos = 1, rightPos = 4
35
Trace the merge operation by determining the next value added to mergedNumbers 14 18 35 17 38 49 0 1 2 3 4 5 leftPos = 2, rightPos = 4
38
Trace the merge operation by determining the next value added to mergedNumbers 14 18 35 17 38 49 0 1 2 3 4 5 leftPos = 3, rightPos = 4
49
Trace the merge operation by determining the next value added to mergedNumbers 14 18 35 17 38 49 0 1 2 3 4 5 leftPos = 3, rightPos = 5
False
Two different algorithms that produce the same result have the same computational complexity.
2, 8
Type the list after the given operations. Tyle the list as: 4, 19, 3 numsList: 2, 8, 1 ListRemove(numsList, list tail) numsList: _________
70, 41, 120
Type the list after the given operations. Tyle the list as: 4, 19, 3 numsList: 70, 82, 41, 120, 357, 66 ListRemove(numsList, node 82) ListRemove(numsList, node 357) ListRemove(numsList, node 66) numsList: _________
71, 54 curNode points to he node that will be removed, so ListRemove(numsList, node 29) removes node 29.
Type the list after the given operations. Tyle the list as: 4, 19, 3 numsList: 71, 29, 54 ListRemove(numsList, node 29) numsList: _________.
10, 20, 40, 60
Type the list after the given operations. Type the list as 4, 19, 3 numsList: 10, 20, 30, 40, 50, 60 ListRemoveAfter(numsList, 40) ListRemoveAfter(numsList, 20) numsList: ________
2, 5
Type the list after the given operations. Type the list as 4, 19, 3 numsList: 2, 5, 9 ListRemoveAfternumsList, node 5) numsList: __________
9, 4, 11
Type the list after the given operations. Type the list as 4, 19, 3 numsList: 9, 4, 11, 7 ListRemoveAfter(numsList, node 11) numsList: ________
80, 77 ListRemoveAfter(numsList, 60) yields 91, 80, 77, 60 ListRemoveAfter(numsList, 77) yields 91, 80, 77 ListRemoveAfter(numsList, 0) yields 80, 77
Type the list after the given operations. Type the list as 4, 19, 3 numsList: 91, 80, 77, 60, 75 ListRemoveAfter(numsList, 60) ListRemoveAfter(numsList, 77) ListRemoveAfter(numsList, 0) numsList: ________
57, 28, 40
Type the list after the given operations. Type the list as 4, 19, 3'' numsList: 3, 57, 28, 40 ListRemoveAfter(numsList, 0) numsList: _________
1, 4, 6
Type the list after the given operations. Type the list as: 5, 7, 9 numsList: 1 ListInsertAfter(numsList, node 1, node 6) ListInsertAfter(numsList, node 1, node 4) numsList: __________
23, 5, 17, 8 ListInsertAfter(numsList, node: 23, node 5) inserts node 5 after node 23
Type the list after the given operations. Type the list as: 5, 7, 9 numsList: 23, 17, 8 ListInsertAfter(numsList, node, 23, node 5) numsList: ___________
5, 9, 4 ListInsertAfter(numsList, node 9, node 4) inserts node 4 after node 9
Type the list after the given operations. Type the list as: 5, 7, 9 numsList: 5, 9 ListInsertAfter(numsList, node 9, node 4) numsList: __________.
77, 32, 46, 50 77 (original list) 77, 32 77, 32, 50 77, 32, 46, 50
Type the list after the given operations. Type the list as: 5, 7, 9 numsList: 77 ListInsertAftr(numsList, node 77, node 32) ListInsertAfter(numsList, node 32, node 50) ListInsertAfter(numsList, node 32, node 46) numsList: ________
4: 20^2 / 10^2 = 400 / 100
Using the Big O runtime complexity, how many times longer will sorting a list of 20 elements take compared to sorting a list of 10 elements?
Elements in a linked list cannot be accessed by index. Lack of indexed access is what prevents many sorting algorithms from being easily adapted to work with linked lists.
What aspect of linked lists make adapting array-based sorting algorithms to linked lists difficult?
1
What does FibonacciNumber(2) return? FibonacciNumber(termIndex) { if(termIndex == 0) return 0 else if (termIndex == 1) return 1 else return FibonacciNumber(termIndex - 1) + FibonacciNumber(termIndex - 2)
3
What does FibonacciNumber(4) return? FibonacciNumber(termIndex) { if(termIndex == 0) return 0 else if (termIndex == 1) return 1 else return FibonacciNumber(termIndex - 1) + FibonacciNumber(termIndex - 2)
21
What does FibonacciNumber(8) return? FibonacciNumber(termIndex) { if (termIndex == 0) return 0 else if (termIndex == 1) return 1 else return FibonacciNumber(termIndex - 1) + FibonacciNumber(termIndex - 2) }
O(1)
What is the Big O notation for the best case runtime? i = 0 belowMinSum = 0.0 belowMinCount = 0 while( i < N && numbers[i] <= maxVal) { belowMinCount = belowMinCount + 1 belowMinSum = numbers[i] ++i avgBelow = belowMinSum / belowMinCount
O(N)
What is the Big O notation for the worst case runtime? for(i = 0; i < N; ++i) { if((i % 2) == 0) { outVal[i] = inVals[i] * i } }
O(N)
What is the Big O notation for the worst case runtime? negCount = 0 for(i = 0; i < N; ++i) { if(numbers[i] < 0) { ++negCount } }
N == 0
What is the condition for the base case in CumulativeSum function? CumulativeSum(N) { if (N == 0) return 0 else return N + CumulativeSum( N - 1) }
4, 1, 5, 2 The first three append() calls create the list: 1, 2, 3. After the prepend() call the list is: 4, 1, 2, 3 insertAfter() puts the 5 after the 1, to give: 4, 1, 5, 2, 3. The final remove() call takes the 3 out of the list.
What is the final list after the following code is executed? Linkedlist numList = new linkedList(); Node nodeA = new Node(1); Node nodeB = new Node(2); Node nodeC = new Node(3); Node nodeD = new Node(4); Node nodeE = new Node(5); numList.append(nodeA); numList.append(nodeB); numList.append(nodeC); numList.prepend(nodeD); numList.insertAfter(nodeA, nodeE); numList.remove(nodeC); ___________________________
4, 1, 5, 2 The first three append() instructions create the list: 1, 2, 3 After the prepend() instruction the list is: 4, 1, 2, 3 InsetAfter() puts the 5 after the 1, to give: 4, 1, 5, 2, 3 The final remove() method takes the 3 out of the list.
What is the final list after the following list is executed? num_list = linkedList() node_a = Node(1) node_b = Node(2) node_c = Node(3) node_d = Node(4) node_e = Node(5) num_list.append(node_a) num_list.append(node_b) num_list.append(node_c) num_list.append(node_d) num_list.insert_after(node_a, node_e) num_list.remove(node_c) ____________________
3, 0, 4, 1, 5, 2, 6 h_1 = 101 % 7 = 3 h_2(101) = 4 The first index is 3, then the indices go up by 4 (mod 7 when necessary.)
What is the order of indices examined when trying to insert the key 101 into a table of size 7? h_1(x) = hash(x) % 7 h_2(x) = 5 - hash(x) % 7
Lacking a prev data member. A singly linked node has no reference to the previous node, thus singly linked lists cannot be traversed backward to find the correct insertion points for shifting nodes.
What prevents singly linked list from using the current insertion sort algorithm?
Lack of having a previous data member.
What prevents singly linked lists from using the doubly linked list insertion sort algorithm?
null
What value does ListSearch return if the search key is not found?
2
What will RadixGetLength(17) evaluate to?
3 101 is the largest length, 3 digits, among all the integers in the array.
What will RadixGetMaxLength return when the array is (17, 4, 101)?
hash(key) % table.length
When 0 is passed as the second argument to the probe() method, each class's returned value equals _______.
False All entries must be initialized to empty-since-start.
When a hash table is initialized, all entries must be empty-after-removal.
True findinsertionPosition() determines where in the list the current node should be after sorting. The current node is placed after the returned position.
When findInsertionPosition() returns a non null node not equal to beforeCurrent, insertionSortSinglyLinked() inserts currentNode after the returned node.
49
When sorting a list with 50 elements, indexSmallest will be assigned to a minimum of ___ times.
True With all integers being 3 digits, maxDigits is the constant 3 and RadixSort has a constant number of iterations in the outer loop. Each inner loop is O(n), making the algorithm O(n).
When sorting an array of n-3digit integers, RadixSort's worst-case time complexity is O(n).
True If all integers in the array share a digit, then all integers will be put into the same bucket. Example: If every element in the array were 7, then every element would go into bucket 7.
When sorting an array with n elements, the maximum number of elements that RadixSort may put in a bucket is n.
1 When processing the 1's digit, only 5 has a digit value of 5. When processing the 10's digit, only 57 has a digit value of 5. When processing the 100's digit, only 501 has a digit value of 5. Bucket 5 never contains more than one integer.
When sorting the array (57, 5, 501) with RadixSort, what is the largest number of integers that will be in bucket 5 at any given moment?
False
When the low and high arguments are equal, BinarySearch does not make a recursive call.
insertAfter Can insert a new node anywhere into the list.
Which LinkedList method inserts a new node in the middle of a list?
quickselect(numbers, 4, 6, 5); The low partition is between indices 4 and 6, while the high partition starts at index 7. The target index is 5, so the recursive call is made on the low partition.
Which action will the quickselect() method take for each condition? numbers: {1, 2, 3, 4, 8, 12, 7, 6, 17, 15, 41, 22, 19} startIndex: 4 endIndex: 7 k: 5 lowLastIndex: 6 After partition(numbers, 4, 7) returns:
quickselect(numbers, 4, 9, 5); The target index, 5, is within the high partition. The recursive call is made on the high partition between indices 4 and 9.
Which action will the quickselect() method take for each condition? numbers: {6, 2, 12, 8, 4, 3, 15, 17, 1, 7, 41, 22, 19} startIndex: 0 endIndex: 9 k: 5 lowLastIndex: 3 After partition(numbers, 0, 9) returns:
partition(numbers, 0, 12); If the base case is not applicable, the first thing quickselect() does is partition the entire array, from startIndex to endIndex.
Which action will the quickselect() method take for each condition? numbers{6, 2, 12, 8, 4, 3, 19, 17, 22, 41, 7, 1, 15} startIndex: 0 endIndex: 12 k: 5 The first action is:
DoubleHashingHashTable
Which class implements an additional hash function?
remove() and prepend()
Which combination of LinkedList methods can move a doubly linked node backward?
remove() and prepend() The combination of remove() and prepend() removes a node from the current position and then reinserts the node at the front of the list, moving the node backward. insert_after() can also be used to reinsert a node by moving the node backward.
Which combination of LinkedList methods can move a doubly linked node backward?
Quicksort Quicksort's worst case runtime complexity is O(N^2), which is worse than O(N logN).
Which fast sorting algorithm's worst case runtime complexity is worse than O(N logN)?
f(N) = 3N + 3
Which function best represents the number of operations in the worst case? i = 0 sum = 0 while (i < N) { sum = sum + numbers[i] ++i }
h_2(x) = hash(x) % 5 The mod 5 operation could return zero (Ex: 35 % 5 is 0), which is not valid.
Which function can't be used as h_2?
T(N) = 6N + T(N/4)
Which function is a recurrence relation?
[31, 15, 7, 3, 1] Powers of 2 minus 1 is a common choice, in decreasing order. 1 should be the last value.
Which is a reasonable choice for gap values, given an input array of size 75?
[31, 15, 7, 3, 1] Powers of 2 minus 1 is a common choice, in decreasing order. 1 should be the last value.
Which is a reasonable choice for gap values, given an input list of size 75?
O(N)
Which of the following Big O Notations is equivalent to O(N + 9999)?
O(N^3)
Which of the following Big O notations is equivalent to O(12 * N + 6 * N^3 + 1000)?
O(N)
Which of the following Big O notations is equivalent to O(734 * N)?
IsEmpty
Which operation determines if the deque contains no items?
IsEmpty
Which operation determines if the stack contains no items?
Pop
Which operation should usually be preceded by a check that the stack is not empty?
is The "is" operator check if two objects are the same, meaning the objects share a memory location
Which operator is used to test if two objects share the same memory location?
Shell sort Shell sort uses a gap value to jump between non-sequential elements in constant time, which cannot be done in a linked list.
Which sorting algorithm uses a gap value to jump between elements, and is difficult to adapt to linked lists for this reason?
Swaps the values located at indices i and indexSmallest
Which statement best describes the following code fragment taken from the selctionSort() method? int temp = numbers[i]; numbers[i] = numbers[indexSmallest]; numbers[indexSmallest] = temp;
Swaps the values located at indices i and index_smallest.
Which statement best describes the following code fragment taken from the selection_sort() function? temp = numbers[i] numbers[i] = numbers[index_smallest] numbers[index_smallest] = temp
node_a = Node(15) num_List.append(node_a) The first statement creates a node with a value 15, and the second statement appends node_a to the list, num_list.
Which statements append a node with data value 15 to the num_list?
new_node prepend() adds a new node to the beginning of a list.
Which variable is a parameter of prepend()?
Singly linked lists do not support backward traversal. Several sorting algorithms traverse backward through list elements, which cannot be done with a singly linked list.
Why are sorting algorithms for arrays generally more difficult to adapt to singly linked list than to doubly linked lists?
Pivot
________ can be any value within the array being sorted, commonly the value of the middle array element.
chaining
_________ handles hash table collisions by using a list for each bucket, where each list may store multiple items that map to the same bucket.
Comparator
__________ is a Java interface that represents a comparison function.
Selection Sort
__________ is a sorting algorithm that treats the input as two parts, a sorted part and an unsorted part, and repeatedly selects the proper next value to move from the unsorted part to he end of the sorted part.
Null
__________ is a special value indicating a pointer points to nothing.
Sorting
__________ is the process of converting a list of elements into ascending or descending order.
Shell Sort
___________ is a sorting algorithm that treats the input as a collection of interleaved lists, and sorts each list individually with a variant of the insertion sort algorithm.
Double hashing
___________ is an open-addressing collision resolution technique that uses 2 different hash functions to compute bucket indices.
curNode
___________ points to an existing list node. If ________ is null, RemoveAfter implements a special case that removes the list's head node. Otherwise the algorithm removes the node after __________.
Partition() method
____________ has three parameters: the unsorted array, the start index, and the end index.
Bucket sort
____________ is a numerical sorting algorithm that distributes numbers into buckets, sorts each bucket with an additional sorting algorithm, and then concatenates buckets together to build the sorted result.
Merge sort
____________ is a sorting algorithm that divides a list into two halved, recursively sorts each half, and then merges the sorted halves to produce a sorted list. Used three index variables to keep track of the elements to sort for each recursive function call. i: the index of first element in the list. k: the index of the last element. j: is used to divide the list into two halves.
Radix sort
_____________- is a sorting algorithm designed specifically for integers. The algorithm makes use of a concept called buckets and is a type of bucket sort.
Quickselect
______________ is an algorithm that selects the kth smallest element in a list. Example: Running on the list (15, 73, 5, 88, 9) with k = 0, returns the smallest element in the list, or 5.
Merge sort
______________- is a sorting algorithm that divides a list into two halves, recursively sorts each half, and then merges the sorted halves to produce a sorted list.
RemoveAfter
_______________ operation removes the node after the specified list node.
Bubble Sort
________________ is a sorting algorithm that iterates through a list, comparing and swapping adjacent elements if the second element is less than the first element.
Quicksort
___________________ is a sorting algorithm that repeatedly partitions the input into low and high parts (each part unsorted), and then recursively sorts each of those parts.
2 All elements after the removed element will be moved down by 1 position. Two elements exist after index 3: 26 and 45.
array: 94 82 16 48 26 45 allocationSize: 6 length: 6 ArrayListRemoveAt(list, 3) causes how many items to be moved down by 1 index?
0 Only elements after the removed element will be moved down, and index 5 is the list's end. No items are moved.
array: 94 82 16 48 26 45 allocationSize: 6 length: 6 ArrayListRemoveAt(list, 5) causes how many items to be moved down by 1 index?
-1 33 will not be found in the list. ArrayListSearch returns -1 when the item is not found.
array: 94 82 16 48 26 45 allocationSize: 6 length: 6 What is the return value from ArrayListSearch(list, 33)?
4 Four elements, 94, 82, 16, and 48, will be compared with 48.
array: 94 82 16 48 26 45 allocationSize: 6 length: 6 When searching for 48, how many elements in the list will be compared with 48?
a positive integer "V" comes after "C" in the alphabet, so "Vitamins" is greater than "Candy". String's compareTo() method returns a positive integer when the left item is greater than the right.
class InventoryItemNumberInStockComparer implements Comparator<InventoryItem> { public int compare(InventoryItem item1, InventoryItem item2) { return item1.numberInStock - item2.numberInStock; } } InventoryItemNameComparer's compare method returns ______ when item1's name is "Vitamins" and item2's name is "Candy".
10 item2's numberInStock is subtracted from item1's numberInStock. 50 - 40 = 10
class InventoryItemNumberInStockComparer implements Comparator<InventoryItem> { public int compare(InventoryItem item1, InventoryItem item2) { return item1.numberInStock - item2.numberInStock; } } InventoryItemNumberInStockComparer's compare method returns ______ when item1's numberInStock is 50 and item2's numberInStock in 40.
-1 -1 is returned when item1's price is less than item2's price.
class InventoryItemNumberInStockComparer implements Comparator<InventoryItem> { public int compare(InventoryItem item1, InventoryItem item2) { return item1.numberInStock - item2.numberInStock; } } InventoryItemPriceComparer's compared method returns _____ when item1's price is less than item2's price.
True
def find(lst, item, low, high, indent): """ Finds index of string in list of strings, else -1. Searches only the index range low to high Note: Upper/Lower case characters matter """ print(indent, 'find() range', low, high) range_size = (high - low) + 1 mid = (high + low) // 2 if item == lst[mid]: # Base case 1: Found at mid print(indent, 'Found person.') pos = mid elif range_size == 1: # Base case 2: Not found print(indent, 'Person not found.') pos = 0 else: # Recursive search: Search lower or upper half if item < lst[mid]: # Search lower half print(indent, 'Searching lower half.') pos = find(lst, item, low, mid, indent + ' ') else: # Search upper half print(indent, 'Searching upper half.') pos = find(lst, item, mid+1, high, indent + ' ') print(indent, 'Returning pos = %d.' % pos) return pos attendees = [] attendees.append('Adams, Mary') attendees.append('Carver, Michael') attendees.append('Domer, Hugo') attendees.append('Fredericks, Carlo') attendees.append('Li, Jie') name = input("Enter person's name: Last, First: ") pos = find(attendees, name, 0, len(attendees)-1, ' ') if pos >= 0: print('Found at position %d.' % pos) else: print( 'Not found.') Each recursive call should add a few spaces to the indent parameter.
True
def find(lst, item, low, high, indent): """ Finds index of string in list of strings, else -1. Searches only the index range low to high Note: Upper/Lower case characters matter """ print(indent, 'find() range', low, high) range_size = (high - low) + 1 mid = (high + low) // 2 if item == lst[mid]: # Base case 1: Found at mid print(indent, 'Found person.') pos = mid elif range_size == 1: # Base case 2: Not found print(indent, 'Person not found.') pos = 0 else: # Recursive search: Search lower or upper half if item < lst[mid]: # Search lower half print(indent, 'Searching lower half.') pos = find(lst, item, low, mid, indent + ' ') else: # Search upper half print(indent, 'Searching upper half.') pos = find(lst, item, mid+1, high, indent + ' ') print(indent, 'Returning pos = %d.' % pos) return pos attendees = [] attendees.append('Adams, Mary') attendees.append('Carver, Michael') attendees.append('Domer, Hugo') attendees.append('Fredericks, Carlo') attendees.append('Li, Jie') name = input("Enter person's name: Last, First: ") pos = find(attendees, name, 0, len(attendees)-1, ' ') if pos >= 0: print('Found at position %d.' % pos) else: print( 'Not found.') The above debug approach requires an extra parameter to be passed to indicate the amount of indentation.
False
def find(lst, item, low, high, indent): """ Finds index of string in list of strings, else -1. Searches only the index range low to high Note: Upper/Lower case characters matter """ print(indent, 'find() range', low, high) range_size = (high - low) + 1 mid = (high + low) // 2 if item == lst[mid]: # Base case 1: Found at mid print(indent, 'Found person.') pos = mid elif range_size == 1: # Base case 2: Not found print(indent, 'Person not found.') pos = 0 else: # Recursive search: Search lower or upper half if item < lst[mid]: # Search lower half print(indent, 'Searching lower half.') pos = find(lst, item, low, mid, indent + ' ') else: # Search upper half print(indent, 'Searching upper half.') pos = find(lst, item, mid+1, high, indent + ' ') print(indent, 'Returning pos = %d.' % pos) return pos attendees = [] attendees.append('Adams, Mary') attendees.append('Carver, Michael') attendees.append('Domer, Hugo') attendees.append('Fredericks, Carlo') attendees.append('Li, Jie') name = input("Enter person's name: Last, First: ") pos = find(attendees, name, 0, len(attendees)-1, ' ') if pos >= 0: print('Found at position %d.' % pos) else: print( 'Not found.') The function should remove a few spaces from the indent parameter before returning.
i
def insertion_sort(num_list): for i in range(1, len(num_list)): j = i # Insert num_list[i] into sorted part # stopping once num_list[i] in correct position while j > 0 and num_list[j] < num_list[j - 1]: # Swap num_list[j] and num_list[j - 1] temp = num_list[j] num_list[j] = num_list[j - 1] num_list[j - 1] = temp j -= 1 # Create a list of unsorted values numbers = [10, 2, 78, 4, 45, 32, 7, 11] # Print unsorted list print('UNSORTED:', numbers) # Initial call to insertion_sort with index insertion_sort(numbers) # Print sorted list print('SORTED:', numbers) Which index variable denotes the starting position of the current element in the unsorted part?
numbers
def insertion_sort(num_list): for i in range(1, len(num_list)): j = i # Insert num_list[i] into sorted part # stopping once num_list[i] in correct position while j > 0 and num_list[j] < num_list[j - 1]: # Swap num_list[j] and num_list[j - 1] temp = num_list[j] num_list[j] = num_list[j - 1] num_list[j - 1] = temp j -= 1 # Create a list of unsorted values numbers = [10, 2, 78, 4, 45, 32, 7, 11] # Print unsorted list print('UNSORTED:', numbers) # Initial call to insertion_sort with index insertion_sort(numbers) # Print sorted list print('SORTED:', numbers) Which variable is passed as an argument to the insertion_sort function?
None
def insertion_sort(num_list): for i in range(1, len(num_list)): j = i # Insert num_list[i] into sorted part # stopping once num_list[i] in correct position while j > 0 and num_list[j] < num_list[j - 1]: # Swap num_list[j] and num_list[j - 1] temp = num_list[j] num_list[j] = num_list[j - 1] num_list[j - 1] = temp j -= 1 # Create a list of unsorted values numbers = [10, 2, 78, 4, 45, 32, 7, 11] # Print unsorted list print('UNSORTED:', numbers) # Initial call to insertion_sort with index insertion_sort(numbers) # Print sorted list print('SORTED:', numbers) Which variable is returned by the insertion_sort function?
True positionB initially references the list's head and positionA is initially null. If dataValue is <= the head node's data, then the loop terminates immediately and positionA, which is null is returned.
findInsertionPosition() returns null if the dataValue argument is <= the head node's data.
6
import java.util.Arrays; public class InsertionSortDemo { private static void insertionSort(int[] numbers) { for (int i = 1; i < numbers.length; i++) { int j = i; while (j > 0 && numbers[j] < numbers[j - 1]) { // Swap numbers[j] and numbers [j - 1] int temp = numbers[j]; numbers[j] = numbers[j - 1]; numbers[j - 1] = temp; j--; } } } public static void main(String[] args) { // Create an array of numbers to sort int[] numbers = { 10, 2, 78, 4, 45, 32, 7, 11 }; // Display the contents of the array System.out.println("UNSORTED: " + Arrays.toString(numbers)); // Call the insertionSort method insertionSort(numbers); // Display the sorted contents of the array System.out.println("SORTED: " + Arrays.toString(numbers)); } } If the number array has 4 elements in descending order, then the insertionSort() method does ________ swaps.
i
import java.util.Arrays; public class InsertionSortDemo { private static void insertionSort(int[] numbers) { for (int i = 1; i < numbers.length; i++) { int j = i; while (j > 0 && numbers[j] < numbers[j - 1]) { // Swap numbers[j] and numbers [j - 1] int temp = numbers[j]; numbers[j] = numbers[j - 1]; numbers[j - 1] = temp; j--; } } } public static void main(String[] args) { // Create an array of numbers to sort int[] numbers = { 10, 2, 78, 4, 45, 32, 7, 11 }; // Display the contents of the array System.out.println("UNSORTED: " + Arrays.toString(numbers)); // Call the insertionSort method insertionSort(numbers); // Display the sorted contents of the array System.out.println("SORTED: " + Arrays.toString(numbers)); } } Which index variable denotes the starting position of the current element in the unsorted part?
numbers
import java.util.Arrays; public class InsertionSortDemo { private static void insertionSort(int[] numbers) { for (int i = 1; i < numbers.length; i++) { int j = i; while (j > 0 && numbers[j] < numbers[j - 1]) { // Swap numbers[j] and numbers [j - 1] int temp = numbers[j]; numbers[j] = numbers[j - 1]; numbers[j - 1] = temp; j--; } } } public static void main(String[] args) { // Create an array of numbers to sort int[] numbers = { 10, 2, 78, 4, 45, 32, 7, 11 }; // Display the contents of the array System.out.println("UNSORTED: " + Arrays.toString(numbers)); // Call the insertionSort method insertionSort(numbers); // Display the sorted contents of the array System.out.println("SORTED: " + Arrays.toString(numbers)); } } Which variable is passed as an argument to the last insertionSort() method?
999
key % 1000 maps to indices 0 to _____.
O(log(N))
log_2(N)
True
Suppose the following code is executed: numbers = [8, 2, 7, 6, 1, 4, 3, 5] quicksort (numbers, 3, 6) After this code finished, the numbers list would be: [8, 2, 7, 1, 3, 4, 6, 5]
10 Since 10 is a non-negative, the hash() method returns the hash code without any changes.
The hash() method returns ______ wen key.hashCode() returns 10.
False
n factorial (n!) is commonly implemented as a recursive function due to being easier to understand and executing faster than a loop implementation.
False, is it the last item's index, which equals the array's length minus 1.
quicksort()'s third parameter is the array's length.
False
quicksort()'s third parameter is the list's length.
4 (55 + 2 * 1 + 2 * 1 * 1) = 59 59 % 11 = 4
Assume for each question that the same key object is used, hash(key) returns 55, and the table's length is 11. probe(key, 4) returns _____ for DoubleHashingHashTable.
6, 10, 20, 14, 7
Assume insertion sort's goal is to sort in ascending order. Given list (10, 20, 6, 14, 7), what will be the list after completing the second outer loop iteration (i = 2)? Type answer as 1, 2, 3
14
Assume insertion sort's goal is to sort in ascending order. Given the list (20, 14, 85, 3, 9), what value ill be in the 0th element after the first pass over the outer loop (i =1)?
1024µs
Answer the following question assuming each comparison takes 1µs. Given a list of 1024 elements, what is the runtime for linear search if he search key is less than all elements in the list?
arrayData.length
Array's current allocation size, in number of elements.
nothing and sorts the numbers in place.
Array.sort(numbers) returns _______.
2 (55 + 2) % 11 = 2
Assume for each question that the same key object is used, hash(key) returns 55, and the table's length is 11. probe(key, 2) returns ______ for LinearProbingHashTable.
4 7- 55 % 7 = 1 (55 + 4 * 1) = 59 59 % 11 = 4
Assume for each question that the same key object is used, hash(key) returns 55, and the table's length is 11. probe(key, 4) returns ____ for DoubleHashingHashTable.
1
Assume insertions sort's goal is to sort in ascending order. Given list (10, 11, 12, 13, 14, 5) how many comparisons will be made during the third outer loop execution (i = 3)?
5
Assume insertions sort's goal is to sort in ascending order. Given list (10, 11, 12, 13, 14, 7), how many comparisons will be made during the final outer loop execution (i = 5)?
7: Iterations 1, 2, and 3 requires 1 comparison, and iteration 4 requires 4 comparisons.
Assume insertions sort's goal is to sort in ascending order. Given list (18, 23, 34, 75, 3), how many total comparisons will insertion sort require?
False The sorted() function sorts in ascending order by defauls. To sort in descending order, the function must be called with the argument reverse = True.
Assume num_list is a list defined in Python. The sorted() function has an order parameter that can be assigned with "ascending" or "descending".
List tail
In a circular doubly linked list with at least 2 nodes, where does the head node's previous pointer point to?
Binary Search
mid = (high + low) / 2 is an example of what kind of search?
Gap Value
__________ is a positive integer representing the distance between elements in an interleaved list.
False A custom key function takes a list element as the argument, not an entire list. The function returns sorting key for the element.
A custom key function takes a list as an argument and returns the smallest item in the list.
Positional list
A doubly linked list is a type of ____________. A list where elements contain pointers to the next and/or previous elements in the list.
True
A doubly linked node has both next and previous data members.
O(N^2)
10 * O(N^2)
O(N^2)
10 + O(N^2)
O(N^3)
2 * N^3 + O(N^2)
O(N^3)
3 * N * O(N^2)
True
3N + 6 is a lower bound for the algorithm
buckets Each hash table array element is called a bucket
A 100 element hash table has 100 __________.
False Can use any many fields as needed
A Comparator can use at most 2 fields for sorting.
Bucket
A ______ is a container for numerical values in a specific range. Example: All numbers in the range from 0 to 49 may be stored in a bucket representing this range.
Fast Sorting Algorithm
A ________ is a sorting algorithm that has an average runtime complexity of O(NlogN) or better.
prepend
Which LinkedList method inserts a new node at the beginning of a list?