-6

Which algorithm is fastest if an array is already sorted? Insertsort, Quicksort, or Mergesort?

//needmorecharactersformorecharactersneedmorecharacters

1
  • 2
    try searching. you'll love it. Commented Feb 12, 2016 at 2:27

1 Answer 1

0

bubble-sort with checking. like this....

for i = 1..n-1
  bool changed = false
  for j <- i+1..n
    if a[i] > a[j] then
      swap (a[i], a[j])
      changed = true
  if changed is false then
    break
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.