A list is ordered from smaller to largest when a sort is
called. Which sort would take the shortest time to execute?

Answers were Sorted based on User's Feedback



A list is ordered from smaller to largest when a sort is called. Which sort would take the shortest..

Answer / rohit

Bubble sort with a flag variable to check if comparisons
occur or not. If it is already sorted then in just 1
iteration it will show that the array is sorted which is
not possible in any other sort.THUS JUST 1 ITERATIION IS
REQUIRED IN THIS CASE.

Is This Answer Correct ?    27 Yes 2 No

A list is ordered from smaller to largest when a sort is called. Which sort would take the shortest..

Answer / punit

insertion sort.
all the above answer r wrong.

Is This Answer Correct ?    9 Yes 6 No

A list is ordered from smaller to largest when a sort is called. Which sort would take the shortest..

Answer / sathyanarayana

Yes, its insertion sort. For a sorted array, it takes just
O(n) time. iTs mere traversal of an array as it is already
sorted. In the case of quick sort, it boils down to O(n^2)
in the case of sorted array.

Is This Answer Correct ?    5 Yes 3 No

A list is ordered from smaller to largest when a sort is called. Which sort would take the shortest..

Answer / sathya

Insertion sort works with an efficiency of O(n) if the array
is already sorted. Hence, this algo can be used.

Is This Answer Correct ?    3 Yes 1 No

A list is ordered from smaller to largest when a sort is called. Which sort would take the shortest..

Answer / tarun

bubble sort in the best case

Is This Answer Correct ?    2 Yes 0 No

A list is ordered from smaller to largest when a sort is called. Which sort would take the shortest..

Answer / varma

insertion sort works efficiently on sorted lists.....

Is This Answer Correct ?    2 Yes 1 No

A list is ordered from smaller to largest when a sort is called. Which sort would take the shortest..

Answer / zeeshan

insertion sort shows best case behaviour when list is
already sorted.....

Is This Answer Correct ?    2 Yes 1 No

A list is ordered from smaller to largest when a sort is called. Which sort would take the shortest..

Answer / swetha

insertion sort is best one because it takes less time fot sorted array of elements.......

Is This Answer Correct ?    1 Yes 1 No

A list is ordered from smaller to largest when a sort is called. Which sort would take the shortest..

Answer / ronak & sandip

In this case, both insertion and bubble sort will work exactly same as the time complexity of both method is O(n). But you have to mention one condition to check any swap has been made inside or not...if no swap has been made, it will come out of loop after executing it n times.

Is This Answer Correct ?    1 Yes 1 No

A list is ordered from smaller to largest when a sort is called. Which sort would take the shortest..

Answer / soumitra biswas

modified bubble sort with flag.As the array is already sorted
there will be no swapping in first pass,so no comparison
will take place after first pass and program stops executing.
time complexity =0(n).

Is This Answer Correct ?    1 Yes 1 No

Post New Answer

More Data Structures Interview Questions

How to sort 1 million floating point numbers?

0 Answers  


What type of memory allocation is referred for Linked lists?

0 Answers  


What are the non linear data structure?

0 Answers  


Why linked list is required?

0 Answers  


How do you increase the capacity of an arraylist?

0 Answers  


what is the biggest advantage of linked lists?

0 Answers  


Write an algorithm for inserting and deleting an element from doubly linked list?

0 Answers  


What is the best case complexity of quicksort?

0 Answers  


What is mergesort and hashtable?

0 Answers  


What data structure does a binary tree degenerate?

0 Answers  


What is the difference between arraylist and array?

0 Answers  


When will we get ArrayStoreException?

0 Answers  


Categories