DS&A Final CSCI 2-82

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

In selection sort, the smallest element is selected and swapped with the _____ unsorted element. a) next b) middle c) leftmost d) rightmost

c) leftmost

Which data type is best suited to store the names and grades of students? a) array b) graph c) record d) stack

c) record

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? a) 23, 32, 53, 80, 67, 60 b) 23, 32, 67, 53, 80, 60 c) 23, 32, 53, 67, 80, 60 d) 23, 32, 80, 53, 60, 67

a) 23, 32, 53, 80, 67, 60

Which abstract data type (ADT) is best suited to store the names of all currently available smartphone models? a) A set b) An array c) A linked list d) A stack

a) A set

Which list cannot be sorted using the standard Radix sort algorithm? a) (45.1, -65.6, 89.8, -34.5, 23.3) b) (44, 789, 5678, 90, 1) c) (-67, -89, -34, -10, -65) d) (1, 22, 333, 4444, 55555)

a) (45.1, -65.6, 89.8, -34.5, 23.3)

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

a) 11

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

b) Prepend(list, 12)

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

c) Tom

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

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

b) [0, 2, 4, 6, 8]

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

b) linked list

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

Identify the constant time operation. a) while (x > y) x = x + 1 b) x = array[option] temp = array[option + 1] c) for (i = 0; i < length; i++) sum += i d) string str1string str2string str3 = concat(str1, str2)

b) x = array[option] temp = array[option + 1]

What is the merge sort algorithm's runtime? a)o(logN) b)o(N) c)o(N*logN) d)o(N^2)

c)o(N*logN)

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

d) 4

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

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.

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

_____ returns but does not remove the item at the front of the deque. a) PeekFront(deque) b) PushFront(deque) c) PopFront(deque) d) PeekBack(deque)

a) PeekFront(deque)

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

a) The list of employees' salaries

What will be the value of sum at the end of main() with the provided input?Input: 1 2 3 public static int readNum() { Scanner scnr = new Scanner(System.in); return scnr.nextInt(); } public static void main(String [] args) { int sum = readNum() + readNum() + readNum(); } a) Unpredictable b) 3 c) 6 d) 123

a) Unpredictable

An algorithm's _____ is the scenario where the algorithm does the minimum possible number of operations. a) best case b) best time c) average case d) worst case

a) best case

Consider a hash table, a hash function of key % 10. Which of the following programmer-defined constants for quadratic probing cannot be used in a quadratic probing equation? a) c1 = 1 and c2 = 0 b) c1 = 5 and c2 = 1 c) c1 = 1 and c2 = 5 d) c1 = 10 and c2 = 10

a) c1 = 1 and c2 = 0

Consider a hash table with keys 10, 20, 30, 40, 50, and 60. Which hash function produces the fewest collisions? a) key % 50 b) key % 6 c) key % 10 d) key % 5

a) key % 50

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

The frequency() method is supposed to return the number of occurrences of target within the array.Identify the location of any errors. public static int frequency(int[] nums, int target) { int index = 0; int count = 0; for(index : nums.length) if(nums[index] == target) ++count; return count; } a) The code has no errors b) Only the method signature has an error c) Only the method body has errors d) Both the method signature and body have errors

a) The code has no errors

Which is not a good use of a perfect size array? a) university student IDs b) names of the week c) names of the months d) names of marker colors in a box of 8

a) university student IDs

Given the list (27, 40, 15, 25, 10, 19, 30), what are the new partitioned lists if the pivot is 25? a) (19, 27, 30, 40) and (10, 15, 25) b) (10, 15, 19, 25) and (27, 30, 40) c) (27, 40, 15, 25) and (10, 19, 30) d) (25, 10, 19, 30) and (27, 40, 15)

b) (10, 15, 19, 25) and (27, 30, 40)

Given the list (62, 45, 29, 32, 25, 10, 75), what is the list after sorting by the 1's digit? a) (62, 45, 29, 32, 25, 10, 75) b) (10, 62, 32, 45, 25, 75, 29) c) (10, 32, 62, 25, 45, 75, 29) d) (10, 25, 29, 32, 45, 62, 75)

b) (10, 62, 32, 45, 25, 75, 29)

Given the number list (2, 12, 8, 19, 5, 30), identify the merged list in merge sort after the completion of the second level. a) (2, 12, 8) and (5, 19, 30) b) (2, 8, 12) and (5, 19, 30) c) (2, 5, 8) and (12, 19, 30) d) (2, 12, 8) and (19, 5, 30)

b) (2, 8, 12) and (5, 19, 30)

Using double hashing, how is the index determined when inserting item 20?hash1(key) = key % 11hash2(key) = 5 - key % 5and a hash table with a size of 10 a) (20 % 11 + 1 * (5 - 20 % 5)) % 10 b) (20 % 11 + 0 * (5 - 20 % 5)) % 10 c) (20 % 11 + 0 * (5 - 20 % 5)) % 11 d) (20 % 11 + 1 * (5 - 20 % 5)) % 11

b) (20 % 11 + 0 * (5 - 20 % 5)) % 10

Which is true regarding how methods work? a) After a method returns, its local variables keep their values, which serve as their initial values the next time the method is called b) A method's local variables are discarded upon a method's return; each new call creates new local variables in memory c) A return address indicates the value returned by the method d) If a method returns a variable, the method stores the variable's value until the method is called again

b) A method's local variables are discarded upon a method's return; each new call creates new local variables in memory

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

b) Binary search starts from the center of a sorted list.

Which of the following is an example of a recursive function? a) MySalaryCalculator(tempSal) {if (tempSal <= 500)return -1elsetempSal = tempSal + 1000} b) MySalaryCalulator(tempSal) {if (tempSal <= 500)return -1elseMySalaryCalculator(tempSal - 500)} c) MySalaryCalculator(tempSal) {if (tempSal <= 500)return -1elseprint(tempSal)} d) MySalaryCalculator(tempSal) {if (tempSal >= 500)return -1elsetempSal = tempSal + 1000}

b) MySalaryCalulator(tempSal) {if (tempSal <= 500)return -1elseMySalaryCalculator(tempSal - 500)}

Which of the following is a fast sorting algorithm? a) Selection sort b) Quicksort c) Shell sort d) Insertion sort

b) Quicksort

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

b) Ral, Reece, Rita, Ryan

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.

How does using findMax() improve the code? public static int findMax(int val1, int val2) { int max; if(val1 > val2) max = val1; else max = val2; return max; } public static void main(String args[]) { int max1; int max2; int max3; max1 = findMax(15, 7); max2 = findMax(100, 101); max3 = findMax(20, 30); } a) Using findMax() makes main() run faster b) Using findMax() decreases redundant code c) Using findMax() reduces the number of variables d) Using findMax() does not improve the code

b) Using findMax() decreases redundant code

The lower bound of an algorithm's runtime complexity is _____. a) ≥ the best case b) ≤ the best case c) ≤ the worst case d) ≥ the worst case

b) ≤ the best case

Which XXX completes this method that adds a note to an oversized array of notes? public static void addNote(String[] allNotes, int numNotes, String newNote) { allNotes[numNotes] = newNote; XXX } a) --numNotes; b) ++numNotes; c) no additional statement needed d) ++allNotes;

b) ++numNotes;

The Big O notation for an algorithm with exactly 50 constant time operations is _____. a) O(50) b)O(1) c)O(50N) d)50 * O(1)

b) O(1)

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

c) 1. Binary search first checks the middle element of the list. 2. If the search key is not found, the algorithm: i. checks the left sublist if the search key is less than the middle element or ii. checks the right sublist if the search key is greater than the middle element.

Given the list (7, 23, 12, 8, 5, 6), what is the order of the elements after the third insertion sort swap? a) 7, 23, 12, 8, 5, 6 b) 7, 12, 23, 8, 5, 6 c) 7, 8, 12, 23, 5, 6 d) 5, 7, 8, 12, 23, 6

c) 7, 8, 12, 23, 5, 6

Which of the following is correct for a list ADT? a) A list can be implemented in a programming language only using the LinkedList ADT. b) A list can print or remove an element only from the beginning of the list. c) An element can be found and removed from the end of the list. d) A list's behavior is similar to that of a queue.

c) An element can be found and removed from the end of the list.

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

c) Arranging student records neatly on a desk

What is the likely purpose of someMethod() based on the signature?int someMethod(int[] nums) a) Create a new array b) Modify the array contents c) Calculate a value based on the array contents d) Make a copy of the array

c) Calculate a value based on the array contents

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

c) Dijkstra's shortest path

What is the output for the call displayTime(15, 24, 65)? public static void displayTime(int hr, int min, int sec) { if(hr < 1 || hr > 12) { System.out.print("Error: hour "); hr = 1; } if(min < 1 || min > 59) { System.out.print("Error: minute "); min = 1; } if(sec < 1 || sec > 59) { System.out.print("Error: second "); sec = 1; } System.out.println(hr + ":" + min + ":" + sec); } a) 15:24:65 b) 1:24:1 c) Error: hour Error: second 1:24:1 d) Error: second 1:24:1

c) Error: hour Error: second 1:24:1

Which of the following is a constant time operation? a) Finding the minimum value in an unsorted array b) Finding the occurrence of a string in a sorted array c) Finding the sum of two numbers input by the user d) Concatenating two strings entered by the user

c) Finding the sum of two numbers input by the user

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

Given a singly-linked list with a dummy node, the operation ListRemoveAfter(list, list⇢head) causes the _____ to be removed from the list. a) dummy node b) last item c) first item d) middle item

c) first item

What is the runtime complexity notation for the following algorithm?LowNum(listOfAgeGroups, listSize, myAge) { for (ctr = 0; ctr < listSize; ++ctr) if (listOfAgeGroups[ctr] == myAge) return ctr; } a. o(n^2) b. o(1) c. o(n) d. o(n * logn)

c. o(n)

How many additional recursive partitioning levels are required for a list of 64 elements compared to a list of 8 elements? a) 9 b) 8 c) 6 d) 3

d) 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? a) 0, 45, 56, 67, 0 b) 45, 56, 67, 0, 0 c) -1, 45, 56, 67, 1 d) 45, 56, 67, -1, -1

d) 45, 56, 67, -1, -1

A direct access hash table has items 51, 53, 54, and 56. The table must have a minimum of _____ buckets. a) 4 b) 5 c) 56 d) 57

d) 57

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

d) A telephone network

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

Which of the following is the fastest algorithm to sort a string? a) Selection sort b) Insertion sort c) Shell sort d) Merge sort

d) Merge sort

Select the true statement. a) A benefit of methods is to increase redundant code b) A key reason for including methods is to make main() run faster c) Method stubs can not be compiled d) Method stubs are temporary placeholders used during development

d) Method stubs are temporary placeholders used during development

An algorithm that uses a constant number k of integer variables to find a number list's minimum value has space complexity S(N) = _____ and auxiliary space complexity S(N) = _____. a) k, k b) N, N c) k, N d) N, k

d) N, k

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

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 non-null tail pointer c) a non-null head and null tail pointer d) null head and tail pointers

d) null head and tail pointers

Which XXX removes the first item in an oversize array? public static int removeFirstItem(String[] shoppingList, int listSize) { int i; for(i = 0; i < listSize-1; ++i) XXX if(listSize > 0) --listSize; return listSize; } a) shoppingList[i+1] = shoppingList[i]; b) shoppingList[i] = shoppingList[i-1]; c) --shoppingList[i]; d) shoppingList[i] = shoppingList[i+1];

d) shoppingList[i] = shoppingList[i+1];

What is output? public static void changeRainfall(double [] dailyRain){ dailyRain[0] = 0.1; } public static void main(String args[]){ double [] rainValues = new double[2]; rainValues[0] = 2.9; rainValues[1] = 1.3; changeRainfall(rainValues); System.out.println(rainValues); } a) 2.9 b) 1.3 c) 0.1 d) an array reference

d) an array reference


Kaugnay na mga set ng pag-aaral

Chapter 7 Macro review (Homework Mindtap)

View Set

Human Anatomy Bio 260 Chapter 6 test

View Set

Physiological Adaptation: Remediation

View Set