Midterm 2 CSCI 2082 Data Structures

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

The following algorithm is an example of _____. def MyMath(num) if num <= 1 return num return MyMath(num - 2) + MyMath(num - 1) a) a constant runtime complexity b) a linear runtime complexity c) a logarithmic runtime complexity d) an exponential runtime complexity

d) an exponential runtime complexity

During insertions, if the bucket is occupied, iterating over i values to determine the next empty bucket is called ___. a) arithmetic sequence b) probing sequence c) geometric sequence d) hashing sequence

d) hashing sequence

If a stack is implemented as a linked list, which XXX would replace the missing statement?StackPop(stack) { XXX ListRemoveAfter(stack, null) return headData } a) headData = null b) headData = stack c) headData = stack⇢tail⇢data d) headData = stack⇢head⇢data

d) headData = stack⇢head⇢data

which of the following sorting algorithm cannot perform on doubly linked list. a) insertion sort b)merge sort c) quick sort d) heap sort

d) heap sort

What operation is used to compute a bucket index in the range 0 to 16 from a key? a) key * 17 b) key - 17 c) key / 17 d) key % 17

d) key % 17

Which is not a characteristic of an NP-complete problem? a. No efficient algorithm has been found to solve an NP-complete problem. b. An efficient algorithm to solve an NP-complete problem may be possible. c. If an NP-complete problem has an efficient solution, then all NP-complete problems will have an efficient solution. d. All NP-complete problems can be solved efficiently.

d. All NP-complete problems can be solved efficiently.

Which of the following statements is correct? a. Every data structure has a specific algorithm to implement a certain operation. b. Algorithms cannot utilize data structures to store and organize data. c. The algorithm to append an item in an array is the same as appending an item to a linked list. d. Data structures define only how data is organized and stored.

d. Data structures define only how data is organized and stored.

Identify the correct way to insert 52 at the end of the following list: 12, 24, 36, 48. a. ListPrepend(list, node 52) b. InsertAfter(list, node 52) c. ListInsert (tail, node 52) d. ListAppend(list, node 52)

d. ListAppend(list, node 52)

Given the doubly-linked list students (Tom, Sam, Hal, Pam), what will the list's head node after the operation ListInsertAfter(students, node Tom, node Tim)? a. Tim b. Sam c. Tom d. Pam

c. Tom

Consider a hash table using chaining with 10 buckets and a hash function of key % 10. What would bucket 3's list be after the following operations?HashInsert(hashTable, item 12) HashInsert(hashTable, item 23) HashInsert(hashTable, item 34) HashInsert(hashTable, item 45) HashInsert(hashTable, item 33) HashInsert(hashTable, item 31) HashInsert(hashTable, item 30) a) 23, 33 b) 23, 30, 31, 33 c) 34, 33 d) 24, 33, 31, 30

a) 23, 33

If a stack is implemented as a linked list, then a pop will remove the _____. a) head node b) tail node c) middle node d) null

a) head node

Given the following code for generating the Fibonacci series for N numbers, which XXX would replace the missing statement?FibonacciNumber(N) { XXX return 0 else if N == 1 return 1 else return FibonacciNumber(N-1) + FibonacciNumber(N-2) } a) if (N == 0) b) if (N > 0) c) if (N != 0) d) if (N < 0)

a) if (N == 0)

given the following list, if ListTraversReverseRecursive(node) were called directly on node chips the node visited would be a) only tea b)tea, chips, and pizza c) chips and pizza d) tea and chips

a) only tea

The worst-case runtime of an algorithm is _____ number of steps taken to execute a program. a) the maximum b) the minimum c) the average d) the optimum

a) the maximum

After resizing a hash table with 13 buckets, the new size will be a. 23 b. 29 c. 31 d. 37

a. 23

Which is an abstract data type (ADT)? a. A list b. A string c. A boolean d. A float

a. A list

Identify the correct way to remove 18 from the singly-linked list (18, 20, 22, 24). a. ListRemoveAfter(list, 18) b. ListRemoveAfter(list, node 0) c. ListRemoveAfter(list, node 18) d. ListRemoveAfter(list, null)

a. ListRemoveAfter(list, 18)

Given the singly-linked list (18, 20, 27, 28, 30), which is the first node searched by ListSearch(list, 27)? a. Node 18 b. Node 20 c. Node 27 d. Node 28

a. Node 18

For a well-designed hash table, searching requires _____ on average. a. O(1) b. O(n) c. O(logn) d. O(n^2)

a. O(1)

Given the following singly-linked list, what is the tail pointer and the next pointer of the head node pointing to? a. The tail pointer is pointing to the last node and the next pointer to the first node. b. The tail pointer is pointing to the null node and the next pointer to null. c. The tail pointer is pointing to null and the next pointer to the head node. d. The tail pointer is pointing to the head node and the next pointer to null.

a. The tail pointer is pointing to the last node and the next pointer to the first node.

A hash Function computes a bucket index from an item's ______ a. Key b. Key and value c. Integer value d. neither or value

a. key

If a stack is implemented as a linked list, then a push will be a(n) _____ operation a. replace b. insert c. append d. prepend

a. replace

If myList is initially empty, what sequence of comments creates the list (75, 76, 68)? a. ListAppend(myList, node 75) ListAppend(myList, node 76) ListAppend(myList, node 68) b. ListPrepend(myList, node 75) ListPrepend(myList, node 76) ListPrepend(myList, node 68) c. ListPrepend(myList, node 75) ListInsert(myList, node 76) ListInsert(myList, node 68) d. ListInsert(myList, node 75) ListAppend(myList, node 76) ListAppend(myList, node 68)

a.) ListAppend(myList, node 75) ListAppend(myList, node 76) ListAppend(myList, node 68)

The process of providing only the essentials and hiding the details is known as _____. a. algorithm b. data structure c. abstraction d. optimization

c. abstraction

In the ListInsertAfter function for singly-linked lists, the curNode parameter points to _____ node. a. the head b. the tail c. any existing d. the middle

c. any existing

In a doubly-linked list with 2 dummy nodes, the list's _____. a. head pointer may be null b. tail pointer may be null c. head and tail pointer may point to the same node d. head node's next pointer may point to the list's tail node

c. head and tail pointer may point to the same node

If a hash table has 20 buckets and 12 elements, what will the load factor be? a) 0.8 b) 8 c) 1.2 d) 0.6

d) 0.6

given the deque 10,12,14,16(front is 10), what will the deque look after the following operation Push-front 2 Push-back 13 Push-front 8 Pop-front Pop- back Push- back 18 a) 2,10,12,14,16,13,18 b)8,10,12,14,16,13,18 c)8,10,12,14,16,18 d) 2,10,12,14,16,18

d) 2,10,12,14,16,18

If a stack is implemented as a linked list, then an empty stack will have. a) Non-null head and tail pointers b)A null head and a non-null tail pointer c)A non-null head and null tail pointer d)Null head and tail pointer.

d) Null head and tail pointer. A stack will be empty if the linked list won't have any node i.e., when the top pointer of the linked list will be null.

For an empty, singly-linked list with a dummy node, the list's _____. a. head is null b. tail is null c. head and tail point to the same, non-null node d. head and tail point to different, non-null nodes

head and tail point to the same, non-null node

When adding an item to an array-based list with an allocation size equal to the list length, a new array is generally allocated with _____ the current length.

twice

Identify the statement that is true of linked list traversal. a. A list traversal algorithm starts with the list's next node. b. A doubly-linked list does not support list traversal. c. A doubly linked list's reverse traversal starts with the list's tail node. d. A singly-linked list supports reverse traversal.

C. A doubly linked list's reverse traversal starts with the list's tail node.

In the ListInsertAfter function for singly-linked lists, the curNode parameter is ignored when _____. a. the list's head and tail pointers point to different nodes b. the newNode argument is also null c. the list has more than 2 items d. the list's head pointer is null

c. the list has more than 2 items

Which of the following statements is true with reference to searching? a) An algorithm is an outcome of a search after a program is executed. b) A linear search starts from the middle of the list to check all elements until the search key is found. c) Linear search will compare all elements if the search key is not present. d) Linear search is used only on sorted lists to find the required element.

c) Linear search will compare all elements if the search key is not present.

Which XXX completes the following algorithm for inserting a new node into a singly-linked list? ListInsertAfter(list, curNode, newNode) { if (list⇢head == null) list⇢head = newNodelist⇢tail = newNode else if (curNode == list⇢tail) list⇢tail⇢next = newNodelist⇢tail = newNode else XXX } a. newNode⇢next = curNode⇢nextcurNode⇢next = null b. newNode⇢next = nullcurNode⇢next = list⇢tail⇢next c. newNode⇢next = curNode⇢nextcurNode⇢next = newNode d. newNode⇢next = curNode⇢nextcurNode = newNode

c) newNode⇢next = curNode⇢nextcurNode⇢next = newNode

Given the list (75, 76, 68), identify the commands for the following operations. Insert item 80 at the end of the listRemove item 68Insert item 82 at the end of the listGet the total number of items in the list a) Append(list, 80) Append(list, 82) Remove(list, 68) GetLength(list) b) Append(list, 80) Remove(list, 68) Append(list, 82) GetLength(list) c) Append(list, 80, 82) Remove(list, 68) GetList(list) d) Append(list, 80) Insert(list, 82) Remove(list, 68) GetItem(list)

b) Append(list, 80) Remove(list, 68) Append(list, 82) GetLength(list)

Consider the following hash table, a first hash function of key % 5, and a second hash function of 10 - key % 10. Then, HashSearch(valsTable, 44) probes _____ buckets. x = empty after removal 0 | x | 1 | 11| 2 | | 3 | 33| 4 | x| 5 | 55 | 6 | 66 | 7 | | a) 1 b) 2 c) 3 d) 4

b) 2

Which of the following statements is correct? a. The queue ADT supports the insertion and deletion of items at the front and the back. b. The list ADT supports the printing of the list contents but the queue ADT does not. c. The queue ADT supports the removing of items from one end and the adding of items to the other end but the list ADT does not. d. The queue ADT supports the printing of the list contents but the list ADT does not.

b. The list ADT supports the printing of the list contents but the queue ADT does not.

Given the singly-linked list (88, 99), which node will be removed by the ListRemoveAfter(list, node 88) command? a. The head node b. The tail node c. No node will be removed. d. The list will be removed.

b. The tail node

ADTs allow programmers to _____. a. debug a program b. focus on higher-level operations as per a program's needs c. choose the runtime and memory usage of a program d. access underlying implementation of a program

b. focus on higher-level operations as per a program's needs

Which of the following is a valid reason for resizing a hash table? a. adding more than 1 item in a bucket b. load factor is greater than 0.5 c. load factor is less than 0.1 d. more than 5 items in a hash table

b. load factor is greater than 0.5 Load factor of hash table is the average number of keys stored in the hash table. Load factor = Number of elements in the table / Capacity (i.e. Number of buckets in hash table) Load factor of an empty hash table is 0. And load factor of full hash table is 1. 0 <= Load Factor <= 1. In quadratic probing, if the load factor exceeds 0.5 then it is must to expand the table. Hash table in quadratic probing can have load factor at most 0.5. Because if the table increase the load factor of 0.5 then the number of probes rises fastly and there can be penalty for this.

In a linked list, each node stores a _____ the next node. a. copy of b. pointer to c. child of d. memory of

b. pointer to

Appending an element in an array involves increasing the array's _____. a. data type b. size c. value d. item

b. size

For a decimal mid-square hash function, what is the bucket index for key = 240, N = 200, and R = 3? a) 176 b) 0 c) 160 d) 3

c) 160

Which collision resolution technique places the item in another empty bucket? a) Chaining b) Open hashing c) Open addressing d) Closed addressing

c) Open addressing

A recursive function calls _____. a) at least two more functions b) another function c) itself d) the main function

c) itself

Identify the correct algorithm to use for finding the insertion position of a new item in the linked list studentList. a. ListFindInsertionPosition(studentList, dataValue) { curNodeA = nullcurNodeB = studentList⇢head while (curNodeB == null and dataValue > curNodeB⇢data) curNodeA = curNodeBcurNodeB = curNodeB⇢next return curNodeA } b. ListFindInsertionPosition(studentList, dataValue) { curNodeA = nullcurNodeB = studentList⇢tail while (curNodeB != null and dataValue > curNodeB⇢data) curNodeA = curNodeBcurNodeB = curNodeA return curNodeA } c. ListFindInsertionPosition(studentList, dataValue) { curNodeB = nullcurNodeA = studentList⇢head while (curNodeB == null and dataValue < curNodeB⇢data) curNodeA = curNodeBcurNodeB = curNodeB⇢next return curNodeB } d. ListFindInsertionPosition(studentList, dataValue) {curNodeA = nullcurNodeB = studentList⇢headwhile (curNodeB != null and dataValue > curNodeB⇢data) {curNodeA = curNodeBcurNodeB = curNodeB⇢next}return curNodeA}

d. ListFindInsertionPosition(studentList, dataValue) {curNodeA = nullcurNodeB = studentList⇢headwhile (curNodeB != null and dataValue > curNodeB⇢data) {curNodeA = curNodeBcurNodeB = curNodeB⇢next}return curNodeA}

Given the singly-linked list (11, 33, 44, 66), identify the commands for inserting 22 and 55, such that the final list is (11, 22, 33, 44, 55, 66). a. ListInsertAfter(list, node 11, node 22) ListInsertAfter(list, node 44, node 55) b. ListInsertAfter(list, node 0, node 22) ListInsertAfter(list, node 3, node 55) c. ListInsertAfter(list, node 11, node 22, node 55) d. ListInsertAfter(list, node 22) ListInsertAfter(list, node 55)

d. ListInsertAfter(list, node 22) ListInsertAfter(list, node 55)

Given the singly-linked list (10, 20, 30, 40, 50, 60), what commands remove 10, 20, and 60, such that the final list is (30, 40, 50)? a. ListRemoveAfter(list, null) ListRemoveAfter(list, node 10) ListRemoveAfter(list, node 50) b. ListRemoveAfter(list, null) ListRemoveAfter(list, node 20) ListRemoveAfter(list, node 60) c. ListRemoveAfter(list, null) ListRemoveAfter(list, null) ListRemoveAfter(list, node 60) d. ListRemoveAfter(list, null) ListRemoveAfter(list, null) ListRemoveAfter(list, node 50)

d. ListRemoveAfter(list, null) ListRemoveAfter(list, null) ListRemoveAfter(list, node 50)

Which algorithm is best suited for a plagiarism check? a. Navigation b. Binary search c. Shortest path d. Longest common substring

d. Longest common substring

Given the singly-linked list (80, 81, 82, 83), what is returned from ListSearch(list, 84)? a. 1 b. Node 80 c. True d. Null

d. Null

Which of the following is an example of a linked list traversal operation? a. Insert a node at the beginning of the list b. Removing a node from the middle of the list c. Appending a node at the end of the list d. Printing the list

d. Printing the list

ListSearch visits _____ when searching for 83 in the singly-linked list (80, 81, 82, 83). a. only the first node b. only the last node c. only the first and last nodes d. all the nodes

d. all the nodes

Which XXX would replace the missing statement in the following algorithm to remove a node from the singly-linked list? ListRemoveAfter(list, curNode) { if (curNode is null && list⇢head is not null) { sucNode = list⇢head⇢nextlist⇢head = sucNode if (sucNode is null) XXX } else if (curNode⇢next is not null) { sucNode = curNode⇢next⇢nextcurNode⇢next = sucNode if (sucNode is null) list⇢tail = curNode } } a. list⇢head = sucNode b. sucNode = list⇢head⇢next c. list⇢tail = curNode d. list⇢tail = null

d. list⇢tail = null

Replace XXX in the following function header for doubly-linked list: ListInsertAfter(listName, currentNode, XXX) a. headNode b. tailNode c. middleNode d. newNode

d. newNode

Given the singly-linked list (10, 20, 30, 40, 50, 60), ListSearch(list, 30) points the current node pointer to _____ after checking node 20. a. node 10 b. node 40 c. node 20 d. node 30

d. node 30

Given the doubly-linked list students (Tom, Sam), what will be the second node in the list after the following operations? ListInsertAfter(students, list⇢tail, node Hal)ListInsertAfter(students, list⇢head, node Pam) a. Hal b. Tom c. Sam d. Pam

d. pam Explanation: the given commands will work as : ListInsertAfter(students, list⇢tail, node Hal) : it will insert "node Hal" after the last node. ListInsertAfter(students, list⇢head, node Pam) : will insert "node Pam" just after the first node.


Kaugnay na mga set ng pag-aaral

II Lecture Chapter 21 Fill in the Blank: Pathophysiology Related to Surgery pp 461

View Set

Insulation, ventilation, and interior

View Set

Beaufort 6 - Contact 7 - woordenschat

View Set

Finance 3000 Chapter 1 - Mizzou Hegger

View Set

3.2 Basic Machine Power Off - Basic Mill Operator

View Set

CSA+ CH4 Security Architecture 1/2

View Set

Government in America, Edwards: Chapter 1

View Set