Data Structures Midterm #2

¡Supera tus tareas y exámenes ahora con Quizwiz!

Consider an array of elements arr[5]= {5,4,3,2,1} , what are the steps of insertions done while doing insertion sort in the array. (A) 4 5 3 2 1 3 4 5 2 1 2 3 4 5 1 1 2 3 4 5 (B) 5 4 3 1 2 5 4 1 2 3 5 1 2 3 4 1 2 3 4 5 (C) 4 3 2 1 5 3 2 1 5 4 2 1 5 4 3 1 5 4 3 2 (D) 4 5 3 2 1 2 3 4 5 1 3 4 5 2 1 1 2 3 4 5

(A) 4 5 3 2 1 3 4 5 2 1 2 3 4 5 1 1 2 3 4 5

What are the correct intermediate steps of the following data set when it is being sorted with the Insertion sort?15,20,10,18 A. 15,20,10,18 -- 10,15,20,18 -- 10,15,18,20 -- 10,15,18,20 B. 15,18,10,20 -- 10,18,15,20 -- 10,15,18,20 -- 10,15,18,20 C. 15,10,20,18 -- 15,10,18,20 -- 10,15,18,20 D. 10, 20,15,18 -- 10,15,20,18 -- 10,15,18,20

A. 15,20,10,18 -- 10,15,20,18 -- 10,15,18,20 -- 10,15,18,20

Merge sort uses A. Divide-and-conquer B. Backtracking C. Heuristic approach D. Greedy approach

A. Divide-and-conquer

A selection sort algorithm sorts the list by which method? A. Finding the smallest element in the list and moving this to the beginning of the unsorted list B. Keeping a list of the smallest elements for later use when searching C. None of the above

A. Finding the smallest element in the list and moving this to the beginning of the unsorted list

Which algorithm would work best to sort data as it arrives, one piece at a time, perhaps from a network? A. Insertion sort B. Selection Sort C. Bubble Sort D. Merge Sort

A. Insertion sort

Merge sort works on the principle of divide-and-conquer A. TRUE B. FALSE

A. TRUE

On average, a sequential search algorithm would make N/2 number of comparisons for a list of size N. A. True B. Fals

A. True

The heap sort algorithm begins by converting the list into a heap, then sorting. A. True B. False

A. True

The insertion sort algorithm improves on the selection sort method by reducing the number of comparisons. A. True B. False

A. True

The merge sort algorithm differs from the quick sort only in how it partitions the list, which is to create two nearly equal sub lists. A. True B. False

A. True

The quick sort algorithm divides the list into two sub lists, then sorts each sub lists, and then combines both sub lists. A. True B. False

A. True

What is the key used in a search algorithm? A. Used in operations such as searching, sorting, inserting and deleting B. Used to encrypt the data C. Used in the compareTo() and equalsTo() operations

A. Used in operations such as searching, sorting, inserting and deleting

Consider the following lists of partially sorted numbers. The double bars represent the sort marker. How many comparisons and swaps are needed to sort the next number using Insertion Sort. [1 3 4 8 9 || 5 ] A. 2 comparisons, 3 swaps B. 3 comparisons, 2 swaps C. 4 comparisons, 3 swaps D. 3 comparisons, 4 swaps

B. 3 comparisons, 2 swaps

If one uses straight two-way merge sort algorithm to sort the following elements in ascending order: 20, 47, 15, 8, 9, 4, 40, 30, 12, 17 then the order of these elements after second pass of the algorithm is: A. 8, 9, 15, 20, 47, 4, 12, 17, 30, 40 B. 8, 15, 20, 47, 4, 9, 30, 40, 12, 17 C. 15, 20, 47, 4, 8, 9, 12, 30, 40, 17 D. 4, 8, 9, 15, 20, 47, 12, 17, 30, 40

B. 8, 15, 20, 47, 4, 9, 30, 40, 12, 17

A binary search algorithm can be best described as what? A. An instant lookup method B. A divide and conquer technique C. Start at the head, move through the list until found

B. A divide and conquer technique

Which search algorithm is best for a large list? A. Sequential search B. Binary search C. A for each loop

B. Binary Search

Consider a situation where swap operation is very costly. Which of the following sorting algorithms should be preferred so that the number of swap operations are minimized in general? A. Heap Sort B. Selection Sort C. Insertion Sort D. Merge sort

B. Selection Sort

What operation does the Insertion Sort use to move numbers from the unsorted section to the sorted section of the list? A. Finding the minimum value B. Swapping C. Finding out a pivot value D. None of the above

B. Swapping

The figure shown below is a 2-3 tree. What is the result of deleting 110 from the tree? a) b) c) d)

C

Consider the following lists of partially sorted numbers. The double bars represent the sort marker. How many comparisons and swaps are needed to sort the next number using Insertion Sort. [1 3 4 5 8 9 || 2] A. 5 comparisons, 4 swaps B. 4 comparisons, 5 swaps C. 6 comparisons, 5 swaps D. 5 comparisons, 6 swaps

C. 6 comparisons, 5 swaps

Searching and sorting algorithms are best implemented with which data structure? A. An array-based list B. A linked list C. Both above

C. Both above

The purpose of the bubble sorting algorithm is what? A. To speed up the search of an item in the list B. To sort the contents of the list C. Both choices above D. None of the above

C. Both choices above

The following best describes which algorithm? The elements are compared and swapped if the first is found to be greater than the second. A. Binary search algorithm B. Linear search algorithm C. Bubble sorting algorithm

C. Bubble sorting algorithm

What is the best sorting algorithm to use for the elements in array are more than 1 million in general? A. Merge sort. B. Bubble sort. C. Quick sort. D. Insertion sort.

C. Quick sort.

Which of the following is not true about comparison-based sorting algorithms? A. The minimum possible time complexity of a comparison-based sorting algorithm is O(nLogn) for a random input array B. Any comparison-based sorting algorithm can be made stable by using position as some criteria when two elements are compared C. Counting Sort is not a comparison-based sorting algorithm D. Heap Sort is not a comparison-based sorting algorithm.

D. Heap Sort is not a comparison-based sorting algorithm.

The below diagram represents what type of sorting algorithm? A. Insertion sort B. Bubble sort C. Selection sort D. Merge sort

D. Merge Sort

A selection sort algorithm sorts the list by which method? A. Finding the smallest element in the list and moving this to the beginning of the unsorted list B. keeping a list of the smallest elements for later use when searching C. none of the above

Finding the smallest element in the list and moving this to the beginning of the unsorted list

Select the appropriate code that performs bubble sort. a) for(int j=arr.length-1; j>=0; j--) { for(int k=0; k<j; k++) { if(arr[k] > arr[k+1]) { int temp = arr[k]; arr[k] = arr[k+1]; arr[k+1] = temp; }}} b) for(int j=arr.length-1; j>=0; j--) { for(int k=0; k<j; k++) { if(arr[k] < arr[k+1]) { int temp = arr[k]; arr[k] = arr[k+1]; arr[k+1] = temp; }}} c) for(int j=arr.length; j>=0; j--) { for(int k=0; k<j; k++) { if(arr[k] > arr[k+1]) { int temp = arr[k]; arr[k] = arr[k+1]; arr[k+1] = temp; }}} d) None of the mentioned

a) for(int j=arr.length-1; j>=0; j--) { for(int k=0; k<j; k++) { if(arr[k] > arr[k+1]) { int temp = arr[k]; arr[k] = arr[k+1]; arr[k+1] = temp; }}}

Select the appropriate code that performs selection sort. a) int min; for(int j=0; j<arr.length-1; j++) { min = j; for(int k=j+1; k<=arr.length-1; k++) { if(arr[k] < arr[min]) min = k; } int temp = arr[min]; arr[min] = arr[j]; arr[j] = temp; } b) int min; for(int j=0; j<arr.length-1; j++) { min = j; for(int k=j+1; k<=arr.length; k++) { if(arr[k] < arr[min]) min = k; } int temp = arr[min]; arr[min] = arr[j]; arr[j] = temp; } c) int min; for(int j=0; j<arr.length-1; j++) { min = j; for(int k=j+1; k<=arr.length-1; k++) { if(arr[k] > arr[min]) min = k; } int temp = arr[min]; arr[min] = arr[j]; arr[j] = temp; } Select the appropriate code that performs selection sort. d) int min; for(int j=0; j<arr.length-1; j++) { min = j; for(int k=j+1; k<=arr.length; k++) { if(arr[k] > arr[min]) min = k; } int temp = arr[min]; arr[min] = arr[j]; arr[j] = temp; }

a) int min; for(int j=0; j<arr.length-1; j++) { min = j; for(int k=j+1; k<=arr.length-1; k++) { if(arr[k] < arr[min]) min = k; } int temp = arr[min]; arr[min] = arr[j]; arr[j] = temp; }

You are given a knapsack that can carry a maximum weight of 60. There are 4 items with weights {20, 30, 40, 70} and values {70, 80, 90, 200}. What is the maximum value of the items you can carry using the knapsack? a) 160 b) 200 c) 170 d) 90

a) 160

Which of the following is false about 2-3 Trees? a) 2-3 tree requires less storage than the BST b) lookup in 2-3 tree is more efficient than in BST c) 2-3 tree is shallower than BST d) 2-3 tree is a balanced tree

a) 2-3 tree requires less storage than the BST

The given array is arr = {1,2,4,3}. Bubble sort is used to sort the array elements. How many iterations will be done to sort the array? a) 3 b) 2 c) 1 d) 0

a) 3

The given array is arr = {3,4,5,2,1}. The number of iterations in bubble sort and selection sort respectively are, a) 5 and 4 b) 4 and 5 c) 2 and 4 d) 2 and 5

a) 5 and 4

1. What is an external sorting algorithm? a) Algorithm that uses tape or disk during the sort b) Algorithm that uses main memory during the sort c) Algorithm that involves swapping d) Algorithm that are considered 'in place'

a) Algorithm that uses tape or disk during the sort

. 2-3 tree is a specific form of _________ a) B - tree b) B+ - tree c) AVL tree d) Heap

a) B - tree

What is an in-place sorting algorithm? a) It needs O(1) or O(logn) memory to create auxiliary locations b) The input is already sorted and in-place c) It requires additional storage d) None of the mentioned

a) It needs O(1) or O(logn) memory to create auxiliary location

What is the advantage of selection sort over other sorting techniques? a) It requires no additional storage space b) It is scalable c) It works best for inputs which are already sorted d) It is faster than any other sorting technique

a) It requires no additional storage space

A B-Tree used as an index for a large database table has four levels including the root node. If a new key is inserted in this index, then the maximum number of nodes that could be newly created in the process are: a. 5 b. 4 c. 3 d. 2

a. 5

The given array is arr = {1,2,3,4,5}. (bubble sort is implemented with a flag variable). The number of iterations in selection sort and bubble sort respectively are, a) 5 and 4 b) 1 and 4 c) 0 and 4 d) 4 and 1

b) 1 and 4

What is an internal sorting algorithm? a) Algorithm that uses tape or disk during the sort b) Algorithm that uses main memory during the sort c) Algorithm that involves swapping d) Algorithm that are considered 'in place'

b) Algorithm that uses main memory during the sort

When a top-down approach of dynamic programming is applied to a problem, it usually _____________ a) Decreases both, the time complexity and the space complexity b) Decreases the time complexity and increases the space complexity c) Increases the time complexity and decreases the space complexity d) Increases both, the time complexity and the space complexity

b) Decreases the time complexity and increases the space complexity

A greedy algorithm can be used to solve all the dynamic programming problems. a) True b) False

b) False

The 0-1 Knapsack problem can be solved using Greedy algorithm. a) True b) False

b) False

What is the disadvantage of selection sort? a) It requires auxiliary memory b) It is not scalable c) It can be used for small keys d) None of the mentioned

b) It is not scalable

If an optimal solution can be created for a problem by constructing optimal solutions for its subproblems, the problem possesses ____________ property. a) Overlapping subproblems b) Optimal substructure c) Memoization d) Greedy

b) Optimal substructure

You must sort 1 GB of data with only 100 MB of available main memory. Which sorting technique will be most appropriate? A. Heap sort B. Merge sort C. Quick sort D. Insertion sort

b. Merge Sort

Which of the following is the 2-3 tree? a) b) c) d)

c

A B-tree of order 4 is built from scratch by 10 successive insertions. What is the maximum number of nodes splitting operations that may take place? a) 3 b) 4 c) 5 d) 6

c) 5

What is the advantage of bubble sort over other sorting techniques? a) It is faster b) Consumes less memory c) Detects whether the input is already sorted d) All of the mentioned

c) Detects whether the input is already sorted

. If a problem can be solved by combining optimal solutions to non-overlapping problems, the strategy is called _____________ a) Dynamic programming b) Greedy c) Divide and conquer d) Recursion

c) Divide and conquer

In the following scenarios, when will you use selection sort? a) The input is already sorted b) A large file must be sorted c) Large values need to be sorted with small keys d) Small values need to be sorted with large keys

c) Large values need to be sorted with small keys

Which of the following problems should be solved using dynamic programming? a) Merge sort b) Binary search c) Longest common subsequence d) Quicksort

c) Longest common subsequence

In dynamic programming, the technique of storing the previously calculated values is called ___________ a) Saving value property b) Storing value property c) Memoization d) Mapping

c) Memoization

Which of the following is not true about the 2-3 tree? a) all leaves are at the same level b) it is perfectly balanced c) post order traversal yields elements in sorted order d) it is B-tree of order 3

c) post order traversal yields elements in sorted order

Which of the following methods can be used to solve the Knapsack problem? a) Brute force algorithm b) Recursion c) Dynamic programming d) All of the mentioned

d) All of the mentioned

Which of the following problems is NOT solved using dynamic programming? a) 0/1 knapsack problem b) Matrix chain multiplication problem c) Edit distance problem d) Fractional knapsack problem

d) Fractional knapsack problem


Conjuntos de estudio relacionados

Lewis 12th edition end of chapter questions: 66,67,68,69,12,15,56,26

View Set

Retirement Plans: Education and Health Savings Plans

View Set

Introduction to Functions Unit Test Review

View Set

EVR 1001 Exam 1 Study Guide - Chapter 2

View Set