Quiz 4 Data Structures

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

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?

4

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

4 5 3 2 1 3 4 5 2 1 2 3 4 5 1 1 2 3 4 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,

4 and 1

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

5 and 4

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 the insertion sort. [1 3 4 5 8 9 || 2]

6 comparisons, 5 swaps

What is an internal sorting algorithm?

Algorithm that uses main memory during the sort

What is an external sorting algorithm?

Algorithm that uses tape or disk during the sort

Searching and sorting algorithms are best implemented with which data structure?

An array-based list and A linked list (BOTH ANSWERS)

The following best describes which algorithm? The elements are compared and swapped if the first is found to be greater than the second.

Bubble sorting algorithm

What is the advantage of bubble sort over other sorting techniques?

Detects whether the input is already sorted

Merge sort uses

Divide-and-conquer

A selection sort algorithm sorts the list by which method?

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?

Insertion Sort

What is the disadvantage of selection sort?

It is not scalable

What is an in-place sorting algorithm?

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

What is the advantage of selection sort over other sorting techniques?

It requires no additional storage space

The below diagram represents what type of sorting algorithm? (imagine photo)

Merge sort

What is the best sorting algorithm to use for the elements in array are more than 1 million in general?

Quick sort.

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?

Selection Sort

What operation does the Insertion Sort use to move numbers from the unsorted section to the sorted section of the list?

Swapping

(T/F) Merge sort works on the principle of divide-and-conquer

True

(T/F) The heap sort algorithm begins by converting the list into a heap, then sorting.

True

(T/F) 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.

True

(T/F) The quick sort algorithm divides the list into two sub lists, then sorts each sub lists, and then combines both sub lists.

True

What is the key used in a search algorithm?

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

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:

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

A binary search algorithm can be best described as what?

A divide and conquer technique

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

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 the insertion sort. [1 3 4 8 9 || 5

3 comparisons, 2 swaps

Which search algorithm is best for a large list?

Binary search

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.

In the following scenarios, when will you use selection sort?

Large values need to be sorted with small keys

You must sort 1 GB of data with only 100 MB of available main memory. Which sorting technique will be most appropriate?

Merge sort

The purpose of the bubble sorting algorithm is what?

To speed up the search of an item in the list and To sort the contents of the list (Both choices above)

(T/F) On average, a sequential search algorithm would make N/2 number of comparisons for a list of size N.

True

(T/F) The insertion sort algorithm improves on the selection sort method by reducing the number of comparisons.

True

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; } 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; }

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; } } }


संबंधित स्टडी सेट्स

Words to Watch for in Essay Questions

View Set

Greenlight Insurance Licensing Exam

View Set

Practice Questions for Econ Exam 2

View Set

Property II Midterm - Private Land Use Planning

View Set

XCEL Chapter 11 - Laws and Rules

View Set