Notifications Mark All Read

No New notification

June 23, 2019

Question 1

Quick Sort

Radix

Bubble

Selection

Good Job!

Oops!

Quick sort performs the worst if arranged in alphabetic/ ascending order. Quicksort is a well-known sorting algorithm that, on average, makes O(n log n) comparisons to sort n items. However, in the worst case, it makes O(n2) comparisons.

Please login to submit your explanation

You can access this section after

Start

Question 2

log(n) + 1

2*log n

n

(n+1)/2

The time complexity or O(n) of Binary search is log n (base 2) as the "domain" halves after each comparison, so if you half a million 21 times you will reach 1 answer which will be the number you need. Example: for 4 numbers in a binary search we will need at most 3 i.e log 4(base 2) + 1 = 3. for 8 numbers in a binary search we will need at most 4 i.e. log 8 +1 =4 for 15 numbers in a binary search we will need at most 4 i.e log 15 + 1 = 4.

Question 3

4

5

2

8

First Pass: ( 5 1 4 2 8 ) –> ( 1 5 4 2 8 ), Here, algorithm compares the first two elements, and swaps since 5 > 1. ( 1 5 4 2 8 ) –> ( 1 4 5 2 8 ), Swap since 5 > 4 ( 1 4 5 2 8 ) –> ( 1 4 2 5 8 ), Swap since 5 > 2 ( 1 4 2 5 8 ) –> ( 1 4 2 5 8 ), Now, since these elements are already in order (8 > 5), algorithm does not swap them. Second Pass: ( 1 4 2 5 8 ) –> ( 1 4 2 5 8 ) ( 1 4 2 5 8 ) –> ( 1 2 4 5 8 ), Swap since 4 > 2 ( 1 2 4 5 8 ) –> ( 1 2 4 5 8 ) ( 1 2 4 5 8 ) –> ( 1 2 4 5 8 ) Now, the array is already sorted, but our algorithm does not know if it is completed. The algorithm needs one whole pass without any swap to know it is sorted. Third Pass: ( 1 2 4 5 8 ) –> ( 1 2 4 5 8 ) ( 1 2 4 5 8 ) –> ( 1 2 4 5 8 ) ( 1 2 4 5 8 ) –> ( 1 2 4 5 8 ) ( 1 2 4 5 8 ) –> ( 1 2 4 5 8 )

Question 4

22

12

25

64

arr[] = 64 25 12 22 11 // Find the minimum element in arr[0...4] // and place it at beginning 11 25 12 22 64 // Find the minimum element in arr[1...4] // and place it at beginning of arr[1...4] 11 12 25 22 64 // Find the minimum element in arr[2...4] // and place it at beginning of arr[2...4] 11 12 22 25 64

Question 5

Beginning from a node, each adjacent node is fully explored before traversing the next adjacent node

Beginning from adjacent node, each adjacent node is fully explored before traversing the next adjacent node

Beginning from a node, nodes are traversed in cyclical order

none of these

The Breadth First Search explores every node once and puts that node in queue and then it takes out nodes from the queue and explores it's neighbors.

Question 6

Shell

Heap

Quick

Bubble sort is slowest among the given sorting techniques. More about compelxity - https://prepinsta.com/time-complexities-placements/

Question 7

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

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

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

A

B

C

D

Bubble sort, also referred to as comparison sort, is a simple sorting algorithm that repeatedly goes through the list, compares adjacent elements and swaps them if they are in the wrong order. This is the most simplest algorithm and inefficient at the same time

Question 8

It is faster

Consumes less memory

Detects whether the input is already sorted

All of the mentioned

Question 9

1

In first iteration 4 and 3 will swap after that array become sorted so in next iteration no swap will occur hence, we will come out from the nested for loop.

Question 10

Insertion sort

Selection sort

Heap sort

None

Selection sort makes O(n) swaps which is minimum among all sorting algorithms mentioned above.

Please login to report

Login/Signup to comment

Get Hiring Updates right in your inbox from PrepInsta

Login/Signup to comment