selter hkelter
selter hkelter

Reputation: 11

what is minimum number of operations required to sort an array if:-

In each operation we can either push an element to the end of the array or at the beginning of it for example an array 3 2 5 1 4 6 would take 4 steps. after first operation 2 3 5 1 4 6 after second operation 1 2 3 5 4 6 after third operation 2 3 1 4 6 5 after fourth operation 1 2 3 4 5 6

Upvotes: 0

Views: 299

Answers (1)

V555
V555

Reputation: 21

I think in the best case, the array is already sorted - 0 operations needed. In the worst case, its sorted already, but in the opposite order (eg 6 5 4 3 2 1), you gonna need number of elements-1 operations.

Upvotes: 2

Related Questions