Midterm - Data Structures and Algorithms

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

Identify the depth of node Q. Binary tree with root node A. A's left child is X and right child is Y. X's left child is P and right child is Q. 0 1 2 3

2

A list of 10 elements is to be sorted using insertion sort algorithm. How many times will the outer loop be executed? 10 1 9 2

9 3.4 N-1

Which is an abstract data type (ADT)? A list A string A boolean A float

A list 1.4: A list is a common ADT for holding ordered data

When the Java code below is executed, the first two elements swapped are ____. int[] numbers = { 15, 39, 77, 14 }; selectionSort(numbers); 15 and 39 77 and 14 39 and 77 15 and 14

15 and 14

What is the sequence of ordering for the nodes of the following BST? Binary tree with root node 250. 250's left child is 200 and right child is 300. 200's left child is 190 and right child is 210. 300's left child is 290 and right child is 310. 190 ⇢ 210 ⇢ 200 ⇢ 250 ⇢ 300 ⇢ 290 ⇢ 310 190 ⇢ 210 ⇢ 290 ⇢ 310 ⇢ 200 ⇢ 300 ⇢ 250 250 ⇢ 200 ⇢ 300 ⇢ 190 ⇢ 210 ⇢ 290 ⇢ 310 190 ⇢ 200 ⇢ 210 ⇢ 250 ⇢ 290 ⇢ 300 ⇢310

190 ⇢ 200 ⇢ 210 ⇢ 250 ⇢ 290 ⇢ 300 ⇢310 6.3.3: A BST may yield faster searches than a list.

Sort the following list into descending order.20.24, 20.12, 20.245, 20.025 20.245, 20.24, 20.12, 20.025 20.24, 20.245, 20.12, 20.025 20.025, 20.12, 20.24, 20.245 20.025, 20.12, 20.245, 20.24

20.245, 20.24, 20.12, 20.025 20.24 also means 20.240. There fore 20.245 is greater than 20.24 Just as we compare number before decimal points, the same way we should compare number after decimal points. Like 20.12 is greater than 20.025 Descending order means first the largest number will come, followed by second largest. The last would be the smallest element.

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) 23, 33 23, 30, 31, 33 34, 33 24, 33, 31, 30

23, 33

Given the following hash table and a hash function of key % 10, HashSearch(hashTable, 53) probes _____ buckets. 0 1 2 3

3

A 5-bucket hash table has the items 45, 56, and 67. The hash table's items will be positive integers. Which of the following is the correct way of representing the hash table? 0, 45, 56, 67, 0 45, 56, 67, 0, 0 -1, 45, 56, 67, 1 45, 56, 67, -1, -1

45, 56, 67, -1, -1 5.1 Empty cells

Which of the following is best represented by a graph? A file system on a computer The Undo command in a word processor A work scheduling operation A telephone network

A telephone network can connect with any other networks, same as a node in a graph can connect with any other node using an edge.

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

Linear search will compare all elements if the search key is not present. Binary search is used only on sorted lists. Linear search starts from the leftmost element and one by one compare elements of list with the element being searched.

Which XXX completes the BST search algorithm? BSTSearch(tree, key) { cur = tree⇢root while (cur is not null) if (key == cur⇢key) return cur else XXX cur = cur⇢left else cur = cur⇢right return null } if (key < cur⇢key) if (key > cur⇢key) if (key < cur⇢left⇢key) if (key > cur⇢right⇢key)

if (key < cur⇢key) 6.4.1: BST search algorithm.

In a tree representing a file system, _____. leaf nodes represent only empty directories leaf nodes represent only non-empty directories leaf nodes represent either files or empty directories leaf nodes represent only files

leaf nodes represent either files or empty directories 6.2.1: A file system is a hierarchy that can be represented by a tree.

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

key % 17

Which data type is best suited to store the names and grades of students? array graph record stack

record a structure which is used to store more than one information(variable) of some data so, we can use a record(struct) to store both name and grade of a student

Which of the following is not an example of sorting a list? Arranging patient records alphabetically Arranging employee details based on beginning dates Arranging student records neatly on a desk Arranging musical instruments based on the number of strings they have

Arranging student records neatly on a desk

What type of node is "English"? Binary tree with root node Students. Students's left child is Tom and right child is Mark. Tom's left child is English and right child is Math. Mark's left child is Science and right child is English. Science's left child is Practical.jpg and right child is Theory.doc. Root Parent Internal node Leaf

Leaf

In a computational problem for finding the highest salary of an employee in a company, what is the input? The list of employees' salaries The number of employees The highest salary The computation of the highest salary

The list of employees' salaries we need list of employees salary to find the highest salary by comparing each one of them. We don't need number of employees because we can get that number by finding the length of list. Also we don't need the highest salary and computation of the highest salary.

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

The tail node 88 99, and 88 is head and 99 is tail so, after node 88 is node 99

Which is an internal node? X Y P Q

X

Identify the ancestor(s) of node P. Binary tree with root node A. A's left child is X and right child is Y. X's left child is P and right child is Q. X X, A X, Y X, Y, A

X, Y, A

What values are stored in the list numList? numberList() { for (i = 0; i < 10; i++) { if (i % 2 == 0) { numList[i] = i } } } [1, 2, 3, 4, 5] [0, 2, 4, 6, 8] [2, 4, 6, 8, 10] [1, 3, 5, 7, 9]

[0, 2, 4, 6, 8]

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

any existing

A hash function uses an item's ___ to compute the item's bucket index. bucket key function location

key

In selection sort, the smallest element is selected and swapped with the _____ unsorted element. next middle leftmost rightmost

leftmost

In Java, the array { 36, 46, 71, 31, 88, 72 } can be used as input to _____. both the linearSearch() and binarySearch() methods only the linearSearch() method only the binarySearch() method neither the linearSearch() nor the binarySearch() method

only the linearSearch() method For binary search, we need a sorted array as the input, but since the given array is unsorted so can't use binary search on the array.

Which XXX completes the following algorithm? <code> HashSearch(hashTable, key) { bucket = Hash(key) bucketsProbed = 0 while ((hashTable[bucket] is not EmptySinceStart) and (bucketsProbed < N)) { if ((hashTable[bucket] is not Empty) and (hashTable[bucket].key == key)) { XXX } bucket = (bucket + 1) % N ++bucketsProbed } return null } </code> return hashTable[key] return hashTable[bucket] return bucket return key

return hashTable[bucket] 5.3.8: Search with linear probing.

During sorting the algorithm swaps _____. the first element with each element two elements at a time the first and middle elements all the elements

two elements at a time 3.1

The Java selectionSort() method swaps the smallest element in the _____ portion of the list. unsorted portion of the list with the largest element in the sorted sorted portion of the list with the first element in the unsorted unsorted portion of the list with the first element in the unsorted unsorted portion of the list with the largest element in the unsorted

unsorted portion of the list with the first element in the unsorted

What is the depth of the "Practical.jpg" node? Binary tree with root node Students. Students's left child is Tom and right child is Mark. Tom's left child is English and right child is Math. Mark's left child is Science and right child is English. Science's left child is Practical.jpg and right child is Theory.doc. 1 2 3 4

3

Consider the following hash table, and a hash function of key % 5. What would bucket 3's list be after the following operations? HashRemove(hashTable, 25) HashRemove(hashTable, 48) HashInsert(hashTable, item 53) 33, 53 68, 33, 53 68, 33, 48 68, 33, 48, 53

68, 33, 53

Given the list (11, 22, 25), which is the correct way to add 32 to the list in ascending order? InsertAfter(list, 25, 32) InsertAfter(list, 32) Prepend(list, 32, 25) Prepend(list, 32)

InsertAfter(list, 25, 32)

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

ListAppend(list, node 52) As ListPrepend as the name suggests it will insert 52 as start. And ListInsert will insert at the tail means in place of 48. and InsertAfter has the wrong syntax.

Which collision resolution technique places the item in another empty bucket? Chaining Open hashing Open addressing Closed addressing

Open addressing Collisions are dealt with by searching for another empty buckets within the hash table array itself in open addressing.

Which list is sorted into ascending order? Sally, Sam, Sandy, Samantha, Sal Ral, Reece, Rita, Ryan Don, Dan, Dale, Dana Alan, Andy, Al, Adam

Ral, Reece, Rita, Ryan

In the Java binarySearch() method, what code is used to compute the middle index? mid = high + low / 2; mid = high / 2 + low; mid = (high + low) / 2; mid = (double)(high + low) / 2.0;

mid = (high + low) / 2; 2.3.2: Binary search algorithm

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

pointer to

Given the list (xlsx, xls, xlr, txt, ods), what is the order of the elements after completing insertion sort's second outer loop iteration? xls, xlsx, xlr, txt, ods txt, xlr, xls, xlsx, ods xlr, xls, xlsx, txt, ods ods, txt, xlr, xls, xlsx

xlr, xls, xlsx, txt, ods Insertion Sort xlsx, xls, xlr, txt, ods ------- compare xlsx and xls ------ 1st loop iteration xls, xlsx, xlr, txt, ods ------- compare xls and xlr ------ 2nd loop iteration xlr, xls, xlsx, txt, ods txt, xlr, xls, xlsx, ods ods, txt, xlr, xls, xlsx <------- sorted

What is the parent of the "Theory.doc" node? Binary tree with root node Students. Students's left child is Tom and right child is Mark. Tom's left child is English and right child is Math. Mark's left child is Science and right child is English. Science's left child is Practical.jpg and right child is Theory.doc. Science Mark Students Tom

Science

the list's head pointer In a singly-linked list with 1 element, the tail pointer ____ and the next pointer of the head node ____. points to the last node, points to the first node is null, is null is null, points to the head node points to the head node, is null

points to the head node, is null

A constant time operation is independent of _____. the programming language the output of the code the input values of the code the hardware running the code

the input values of the code A constant time operation will take same amount of time to execute even if it is a small dataset or a huge one.

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

the list's head pointer is null

Sort the following list of video extensions using selection sort: mpg, mp4, mov, mkv, m4v. What is the order of the elements after the second swap? (m4v, mp4, mov, mkv, mpg) (m4v, mkv, mov, mp4, mpg) (mpg, mp4, mov, mkv, m4v) (mov, mkv, mpg, mp4, m4v)

(m4v, mkv, mov, mp4, mpg) Selection sort Original list is ['mpg', 'mp4', 'mov', 'mkv', 'm4v'] Iteration: 1 > Replace element mpg with minimum number of remaining list ['mpg', 'mp4', 'mov', 'mkv', 'm4v'] > Minimum element found is m4v. so, swap it with element at index 0 which is mpg > List after iteration 1 is ['m4v', 'mp4', 'mov', 'mkv', 'mpg'] Iteration: 2 > Replace element mp4 with minimum number of remaining list ['mp4', 'mov', 'mkv', 'mpg'] > Minimum element found is mkv. so, swap it with element at index 1 which is mp4 > List after iteration 2 is ['m4v', 'mkv', 'mov', 'mp4', 'mpg']

Identify the correct sequence of performing a binary search. 1. Binary search first checks the first element of the list. 2. If the search key is not found, the algorithm: 1. checks the middle element of the list or 2. checks the right sublist if the search key is greater than the middle element. 1. Binary search first checks the middle element of the list. 2. If the search key is not found, the algorithm: 1. checks the right sublist if the search key is less than the middle element or 2. checks the left sublist if the search key is greater than the middle element. 1. Binary search first checks the middle element of the list. 2. If the search key is not found, the algorithm: 1. checks the left sublist if the search key is less than the middle element or 2. checks the right sublist if the search key is greater than the middle element. 1. Binary search first checks the last element of the list. 2. If the search key is not found, the algorithm: 1. checks the first element of the list or 2. checks the right sublist if the search key is greater than the middle element.

1. Binary search first checks the middle element of the list. 2. If the search key is not found, the algorithm: 1. checks the left sublist if the search key is less than the middle element or 2. checks the right sublist if the search key is greater than the middle element. 2.2: checks the middle contact first. If the desired contact comes alphabetically before the middle contact, binary search will then search the first half and otherwise the last half.

Assume an ordered list containing the English alphabet. Using linear search, how many letters are checked to locate the letter "K"? 11 10 9 26

11

Given the following hash table, how many items are compared when searching for item 45 using the following search algorithm? HashSearch(hashTable, key) { bucketList = hashTable[Hash(key)] itemNode = ListSearch(bucketList, key) if (itemNode is not null) return itemNode⇢data else return null } 3 items: 25, 45 and 65 4 items: 47, 28, 25, and 45 2 items: 25 and 45 1 item: only 45

2 items: 25 and 45

In a sorted list of prime numbers, how long will it take to search for 29 if each comparison takes 2 µs? 22 µs 29 µs 10 µs 20 µs

20 µs 2,3,5,7,11,13,17,19,23,29 these are the prime numbers so there are 10 prime numbers and each comparison would take 2us so it will be 20us for all comparisons.

The array (67, 23, 32, 80, 53, 60) is to be sorted using selection sort. What is the order of the elements after the third swap? 23, 32, 53, 80, 67, 60 23, 32, 67, 53, 80, 60 23, 32, 53, 67, 80, 60 23, 32, 80, 53, 60, 67

23, 32, 53, 80, 67, 60 Selection sort Original list is [67, 23, 32, 80, 53, 60] Iteration: 1 > Replace element 67 with minimum number of remaining list [67, 23, 32, 80, 53, 60] > Minimum element found is 23. so, swap it with element at index 0 which is 67 > List after iteration 1 is [23, 67, 32, 80, 53, 60] Iteration: 2 > Replace element 67 with minimum number of remaining list [67, 32, 80, 53, 60] > Minimum element found is 32. so, swap it with element at index 1 which is 67 > List after iteration 2 is [23, 32, 67, 80, 53, 60] Iteration: 3 > Replace element 67 with minimum number of remaining list [67, 80, 53, 60] > Minimum element found is 53. so, swap it with element at index 2 which is 67 > List after iteration 3 is [23, 32, 53, 80, 67, 60] so, list after 3rd swap is (23, 32, 53, 80, 67, 60)

Identify the sequence of nodes that are visited to search for 150. Binary tree with root node 250. 250's left child is 200 and right child is 300. 200's left child is 190 and right child is 210. 300's left child is 290 and right child is 310. 250, 200, 190 250, 200, 190, 210 200, 190 190, 210, 290, 310

250, 200, 190

Consider the following hash table, and a hash function of key % 10. How many list items will be compared for the search operations? HashInsert(newTable, item 25) HashInsert(newTable, item 54) HashRemove(newTable, 27) HashInsert(newTable, item 84) HashInsert(newTable, item 83) HashSearch(newTable, 72) HashSearch(newTable, 77) HashSearch(newTable, 63) 2; 0; 2 2; 0; 3 1; 0; 3 2; 0; 1

2; 0; 1

If the Java linearSearch() method is called to search an array of 32 numbers, then at most _____ array numbers are compared against the search key. 6 32 36 1024

32

Assume an ordered list containing the English alphabet. Using binary search, how many letters are checked to locate the letter "K"? 11 26 9 4

4

What is the largest number of comparisons for searching the following BST? Binary tree with root node A. A's left child is X and right child is Y. X's left child is P and right child is Q. P's left child is F and right child is G. Q's left child is R and right child is S. 5 4 3 1

4

Consider a hash table with items 10, 31, 23, 54, 66, 88, and 9, and a hash function of key % 10. Which of the following items will result in a collision if the numbers are inserted in order? 55, 46, 77, 99, 93, 92, 97 55, 77, 99, 92 55, 77, 92, 97 46, 99, 93, 97 46, 77, 99, 93

46, 99, 93, 97 10-0 31-1 23-3 54-4 66-6 88-8 9-9 55-5 46-6 + 77-7 99-9 + 93-3 + 92-2 97-7 +

If the Java binarySearch() method is called to search a sorted array of 32 numbers, then at most _____ array numbers are compared against the search key. 6 32 36 1024

6

Consider a hash table named idTable that uses linear probing and a hash function of key % 10. What is printed after the following operations? HashInsert(idTable, item 45) HashInsert(idTable, item 67) HashInsert(idTable, item 76) HashInsert(idTable, item 78) HashInsert(idTable, item 79) HashInsert(idTable, item 92) HashInsert(idTable, item 87) Print HashSearch(idTable, 67) Print HashSearch(idTable, 77) Print HashSearch(idTable, 87) 67, 87 67, null, 87 67, false, 87 true, false, true

67, null, 87

A hash table named numTable uses a hash function of key % 10 and quadratic probing with c1 = 1 and c2 = 2. Into which bucket is item 44 inserted? HashInsert(numTable, item 1) HashInsert(numTable, item 12) HashInsert(numTable, item 23) HashInsert(numTable, item 34) HashInsert(numTable, item 44) 5 6 7 8

7

Which of the following lists is sorted? Ted, Tom, Thomas, Tim apple, orange, banana, pear 89, 79, 63, 22 1.01, 1.02, 1.1, 1.001

89, 79, 63, 22

Which of the following statements is true with reference to an algorithm's runtime? The runtime of an algorithm is independent of the speed of the processor. The runtime of an algorithm is analyzed in terms of nanoseconds. A single algorithm can execute more quickly on a faster processor. The runtime of an algorithm is independent of the input values.

A single algorithm can execute more quickly on a faster processor.

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

All NP-complete problems can be solved efficiently. 1.2: NP-complete problems are a set of problems for which no known efficient algorithm exists. NP-complete problems have the following characteristics: No efficient algorithm has been found to solve an NP-complete problem. No one has proven that an efficient algorithm to solve an NP-complete problem is impossible. If an efficient algorithm exists for one NP-complete problem, then all NP-complete problems can be solved efficiently.

The Java selectionSort() method's outer loop uses the variable i. What is true of list content with respect to i? All elements before i are in sorted order. All elements after i are in sorted order. The element at index i is the smallest in the list. i is greater than all elements in the list.

All elements before i are in sorted order. 3.3 The outer loop uses the variable i to hold the index position that will be sorted next in the array. The inner loop uses the variable j to examine all indices from i+1 to the end of the array. When the j loop finishes, the variable indexSmallest will store the index position of the smallest item in the array from i onward. The final step is to swap the values at position i and indexSmallest.

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

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

Identify the correct statement about binary space partitioning. Regions are always split down the middle either horizontal or vertical. Half the objects are eliminated each level while traversing down a BSP tree. BSP tree can be used to store all objects in a two-dimensional world. In animation only one region is analyzed at a time.

BSP tree can be used to store all objects in a two-dimensional world.

Which of the following statements is true with reference to searching algorithms? A linear search typically has a shorter runtime than a binary search. Binary search starts from the center of a sorted list. Linear search starts from the center of a sorted list. Binary search is used on unsorted lists to find the required element.

Binary search starts from the center of a sorted list.

Consider a hash table named marksTable that uses linear probing and a hash function of key % 5. What would be the location of the item 46? HashInsert(marksTable, item 49) HashInsert(marksTable, item 41) HashInsert(marksTable, item 42) HashInsert(marksTable, item 44) HashInsert(marksTable, item 46) Bucket 0 Bucket 1 Bucket 2 Bucket 3

Bucket 3

Identify the correct sequence for inserting an item in a linked list. Shift higher-indexed items. Create a list node for a new item. Assign a pointer to point to the new item. Shift higher-indexed items. Assign a pointer to point to a new item. Create a list node for the new item. Create a list node for a new item. Assign a pointer of the new item to point to the next item. Update the pointer of the previous node to point to the new node. Create a list node for a new item. Update the pointer of the previous node to point to the new node. Assign a pointer of the new item to point to the next item.

Create a list node for a new item. Assign a pointer of the new item to point to the next item. Update the pointer of the previous node to point to the new node. 1.1.2: To insert new item in a linked list, a list node for the new item is first created. Item B's next pointer is assigned to point to item C. Item A's next pointer is updated to point to item B. No shifting of other items was required.

A manufacturing plant has many ways to assemble a product. Which algorithm will be useful to find the quickest way? Shortest path Binary search Dijkstra's shortest path Longest common substring

Dijkstra's shortest path 1.2: Dijkstra's shortest path: Dijkstra's shortest path algorithm determines the shortest path from a start vertex to each vertex in a graph.

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

Every data structure has a specific algorithm to implement a certain operation.

Identify the type of the following binary tree. Binary tree with root node X. X's left child is P and right child is Q. P's left child is F and right child is G. Q's left child is R and right child is S. Not full, complete, not perfect Full, not complete, not perfect Full, complete, not perfect Full, complete, perfect

Full, complete, perfect

Identify the type of the following binary tree. Binary tree with root node A. A's left child is X and right child is Y. X's left child is P and right child is Q. P's left child is F and right child is G. Q's left child is R and right child is S. Not full, complete, not perfect Full, not complete, not perfect Full, complete, not perfect Full, complete, perfect

Full, not complete, not perfect

Identify the commands for the following list operations. Check that there are no items in a list Insert 10, 50, 30, 40, and 20 at the end of the list Arrange the items in ascending order IsEmpty(list) Prepend(list, 10) Prepend(list, 50) Prepend(list, 30) Prepend(list, 40) Prepend(list, 20) Sort(list) Search(list) Append(list, 10) Append(list, 50) Append(list, 30) Append(list, 40) Append(list, 20) Sort(list) IsEmpty(list) Append(list, 10) Append(list, 50) Append(list, 30) Append(list, 40) Append(list, 20) GetLength(list) IsEmpty(list) Append(list, 10) Append(list, 50) Append(list, 30) Append(list, 40) Append(list, 20) Sort(list)

IsEmpty(list) Append(list, 10) Append(list, 50) Append(list, 30) Append(list, 40) Append(list, 20) Sort(list)

Which of the following rules does a valid BST follow? Right subtree keys ≤ node's keys Left subtree keys ≥ node's keys Left subtree keys ≤ node's keys Right subtree keys ≤ left subtree keys

Left subtree keys ≤ node's keys 6.3 Binary search trees

Which of the following algorithms is correct for applying linear search to find the element findEle in a list StudentIDs? LinearSearch(StudentIDs, int listSize, int findEle) { for (ctr = 1; i < listSize; ctr++) { if (StudentIDs[ctr] == listSize) return ctr } } LinearSearch(StudentIDs, int listSize, int findEle) { for (ctr = 0; i < listSize; ++ctr) { if (StudentIDs[listSize] == ctr) return findEle } } LinearSearch(StudentIDs, int listSize, int findEle) { for (ctr = 0; i < listSize; ++ctr) { if (StudentIDs[ctr] == findEle) return ctr } } LinearSearch(StudentIDs, int listSize, int findEle) { for (ctr = 0; i < listSize; ++ctr) { if (StudentIDs[findEle] == ctr) return findEle } }

LinearSearch(StudentIDs, int listSize, int findEle) { for (ctr = 0; i < listSize; ++ctr) { if (StudentIDs[listSize] == ctr) return findEle } }

Which abstract data type (ADT) is most suitable to store a list of perishable products such that the product with the nearest expiry date is removed first? A deque A linked list A queue A priority queue

Priority Queue a queue where each item has a priority, and items with higher priority are closer to the front of the queue than items with lower priority.

If myList is initially empty, what sequence of operations creates the list (75, 76, 68)? ListAppend(myList, node 75) ListAppend(myList, node 76) ListAppend(myList, node 68) ListPrepend(myList, node 75) ListPrepend(myList, node 76) ListPrepend(myList, node 68) ListPrepend(myList, node 75) ListInsert(myList, node 76) ListInsert(myList, node 68) ListInsert(myList, node 75) ListAppend(myList, node 76) ListAppend(myList, node 68)

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

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). ListInsertAfter(list, node 11, node 22) ListInsertAfter(list, node 44, node 55) ListInsertAfter(list, node 0, node 22) ListInsertAfter(list, node 3, node 55) ListInsertAfter(list, node 11, node 22, node 55) ListInsertAfter(list, node 22) ListInsertAfter(list, node 55)

ListInsertAfter(list, node 11, node 22) ListInsertAfter(list, node 44, node 55)

Which is the correct code to prepend an item to a list? ListPrepend(list,newNode){if(list⇢head==null){list⇢head=newNodelist⇢tail=newNode}else{list⇢head⇢next=newNodelist⇢head=newNode}} ListPrepend(list,newNode){if(list⇢head==null){list⇢head=newNodelist⇢tail=newNode}else{newNode⇢next=list⇢taillist⇢tail=newNode}} ListPrepend(list,newNode){if(list⇢head==null){list⇢head=newNodelist⇢tail=newNode}else{newNode⇢next=list⇢headlist⇢head=newNode}} ListPrepend(list, newNode) { if (list⇢head == null) { list⇢head = newNode list⇢tail = newNode } else { list⇢tail⇢next = newNode list⇢tail = newNode } }

ListPrepend(list,newNode){if(list⇢head==null){list⇢head=newNodelist⇢tail=newNode}else{newNode⇢next=list⇢headlist⇢head=newNode}} 4.2.5: Singly-linked list: Prepending a node.

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

ListRemoveAfter(list, null) Null as there no node 84 in the list so, it will return Null.

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

Longest common substring 1.2: Longest common substring problem: A longest common substring algorithm determines the longest common substring that exists in two input strings.

Given the list (24, 36, 48), which is the correct way to add 12 at the start of the list? Append(list, 12) Prepend(list, 12) InsertBefore(list, 12) Append(list, 0, 12)

Prepend(list, 12)

Given the list (40, 42, 45, 46, 47), identify the commands for the following operations. Remove 45 Confirm that 45 is removed Remove(list, 45) IsEmpty(list, 45) Delete(list, 45) Search(list, 45) Remove(list, 45) Search(list, 45) Remove(list, 45) Sort(list, 45)

Remove(list, 45) Search(list, 45)

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 = newNode list⇢tail = newNode } else if (curNode == list⇢tail) { list⇢tail⇢next = newNode list⇢tail = newNode } else { XXX } } newNode⇢next = curNode⇢next curNode⇢next = null newNode⇢next = null curNode⇢next = list⇢tail⇢next newNode⇢next = curNode⇢next curNode⇢next = newNode newNode⇢next = curNode⇢next curNode⇢next = newNode

newNode⇢next = curNode⇢next curNode⇢next = newNode 4.3.1: Singly-linked list: Insert nodes.

Consider a hash table named numTable that uses linear probing and a hash function of key % 5. What is the status of bucket 4 after the following operations? HashInsert(numTable, item 24) HashInsert(numTable, item 33) HashInsert(numTable, item 51) HashInsert(numTable, item 44) HashInsert(numTable, item 52) HashRemove(numTable, 44) HashInsert(numTable, item 50) empty-since-start empty-after-removal occupied removed from table

occupied 24-4 33-3 51-1 44-5 52-2 5-empty after removal 50-0

Which XXX will complete the algorithm to separate numberList into two lists (even and odd) using an array? MathematicalFunction(numberList) { Create evenNumberList array Create oddNumberList array for (i = 0; i < numberList⇢length; ++i) { XXX { ArrayAppend(evenNumberList, numberList[i]) } else { ArrayAppend(oddNumberList,numberList[i]) } SortAscending(evenNumberList) SortAscending(oddNumberList) } for (i = 0; i < evenNumberList⇢length; ++i) { Display evenNumberList[i] } for (i = 0; i < oddNumberList⇢length; ++i) { Display oddNumberList[i] } } if (numberList[i] % 1 == 1) if (numberList[i] % 2 == 1) if (numberList[i] % 1 == 0) if (numberList[i] % 2 == 0)

if (numberList[i] % 2 == 0) this will help separate even numbers in a list and else will have the odd numbers in the list.

Which XXX completes the Java selectionSort() method? void selectionSort(int[] numbers) { for (int i = 0; i < numbers.length - 1; i++) { // Find index of smallest remaining element int indexSmallest = i; for (int j = i + 1; j < numbers.length; j++) { XXX { indexSmallest = j; } } // Swap numbers[i] and numbers[indexSmallest] int temp = numbers[i]; numbers[i] = numbers[indexSmallest]; numbers[indexSmallest] = temp; } } if (numbers[i] < numbers[j]) if (numbers[j] < numbers[indexSmallest]) if (j < index_smallest) if (numbers[index_smallest] < numbers[i])

if (numbers[j] < numbers[indexSmallest]) 3.3.1 for (int j = i + 1; j < numbers.length; j++) { if (numbers[j] < numbers[indexSmallest]) { indexSmallest = j; } }

A stack abstract data type (ADT) is implemented using a(n) _____ data structure. array linked list heap binary search tree

linked list 1.4.1: CHART Stack A stack is an ADT in which items are only inserted on or removed from the top of a stack. Linked list

Which XXX should replace the missing statement in the selection sort algorithm given below? SelectionSort(list, listSize) { for (ctr1 = 0; ctr1 < listSize - 1; ++ctr1) { mimIndex = ctr1 for (ctr2 = ctr1 + 1; ctr2 < listSize; ++ctr2) { if (list[ctr2] < list[mimIndex]) { mimIndex = ctr2 } } temp = list[ctr1] XXX list[mimIndex] = temp } } list[mimIndex] = list[ctr2] list[ctr1] = list[mimIndex] list[ctr2] = list[mimIndex] list[mimIndex] = list[ctr1]

list[ctr1] = list[mimIndex] Here after the minimum element is found, the next thing to do is to swap the two number.

Which XXX completes the Java linearSearch method? int linearSearch(int[] numbers, int key) { for (int i = 0; i < numbers.length; i++) { if (numbers[i] == key) { XXX } } return -1; // not found } return numbers[i]; return numbers[key]; return i; return key;

return i; 2.3.1: Linear search algorithm.

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

size 1.3.1: when we append a value to the array then the size of the array increases.

Which XXX completes the binary search algorithm? BinarySearch(numbers, numbersSize, key) { mid = 0 low = 0 high = numbersSize - 1 XXX { mid = (high + low) / 2 if (numbers[mid] < key) { low = mid + 1 } else if (numbers[mid] > key) { high = mid - 1 } else { return mid } } return -1 } while (high >= low) if (high >= low) while (high <= low) if (high <= low)

while (high >= low) 2.3.2: Binary search algorithm


Set pelajaran terkait

Chapter 7: NC laws and rules pertinent to insurance

View Set

NU372 EAQ Evolve Elsevier: HESI Prep Immunologic System and Infectious Disease

View Set

Introduction to International Business-Ch 5

View Set

Monotheism: Zoroastrianism, Judaism, Christianity, Islam

View Set

A&P LAB: Ex. 30: Blood Vessel Identification - MAJOR ARTERIES OF THE PELVIS & LOWER EXTREMITIES

View Set

ACT Videos (Bathing and Grooming

View Set

Google Analytics - General Knowledge

View Set