DS&AD Midterm II

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

. 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]

3 comparisons, 2 swaps

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

What is the disadvantage of selection sort?

it is not scalable

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.

4 5 3 2 1 3 4 5 2 1 2 3 4 5 1 1 2 3 4 5

. 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:

5

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?

5

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 Insertion Sort. [1 3 4 5 8 9 || 2]

6 comparisons, 5 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:

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

Bubble Sort Algorithm

A

Select the appropriate code that performs selection sort.

A

A binary search algorithm can be best described as what?

A divide and conquer technique

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

Which of the following methods can be used to solve the Knapsack problem?

All of the mentioned

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

Array-based list and linked list (both)

Merge sort uses

Divide and Conquer

2-3 tree is a specific form of _________

B - tree

Which search algorithm is best for a large list?

Binary Search

The purpose of the bubble sorting algorithm is what?

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.

Bubble sorting algorithm

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

C

Which of the following is the 2-3 tree?

C

When a top-down approach of dynamic programming is applied to a problem, it usually _____________

Decreases the time complexity and increases the space complexity

Which of the following problems is NOT solved using dynamic programming?

Fractional knapsack problem

Which of the following is not true about comparison-based sorting algorithms?

Heap Sort is not a comparison-based sorting algorithm.

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

It requires no additional storage

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 advantage of bubble sort over other sorting techniques?

It detects whether an input is already sorted.

What is an in-place sorting algorithm?

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

Which of the following problems should be solved using dynamic programming?

Longest common subsequence

In dynamic programming, the technique of storing the previously calculated values is called ___________

Memorization

. The below diagram represents what type of sorting algorithm? A. Insertion sort

Merge sort

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

Merge sort

If an optimal solution can be created for a problem by constructing optimal solutions for its subproblems, the problem possesses ____________ property.

Optimal substructure

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

Quick sort

Which of the following is not true about the 2-3 tree?

post order traversal yields elements in sorted order

If a problem can be solved by combining optimal solutions to non-overlapping problems, the strategy is called _____________

Divide and conquer

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

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

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

1 and 4

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?

160

Which of the following is false about 2-3 Trees?

2-3 tree requires less storage than the BST

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

3

A greedy algorithm can be used to solve all the dynamic programming problems.

False

The 0-1 Knapsack problem can be solved using Greedy algorithm. True or False?

False

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

True

The heap sort algorithm begins by converting the list into a heap, then sorting.

True

The insertion sort algorithm improves on the selection sort method by reducing the number of comparisons.

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.

True

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

True

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

Large values need to be sorted with small keys.

What is the key used in a search algorithm?

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

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

Merge sort works on the principle of divide-and-conquer

True


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

Physical and Chemical Weathering

View Set

Bio lab wk 5 - nervous system pt. 1 : brain + skull anatomy

View Set

Property and Casualty- Commercial

View Set