Answer to Question #145524 in Python for Nhlanhla

Question #145524
Consider the following snippets of code. Then, identify and describe the sorting algorithm used.

num scores[5] = 90,85,65,95,75

sort()
x = 1
while x < SIZE
temp = scores[x]
y = x – 1
while y >= 0 AND scores[y]>temp
scores[y+1] = scores[y]
y = y – 1
endwhile
scores[y+1] = temp
x = x + 1
endwhile return
1
Expert's answer
2020-11-24T16:42:11-0500

Insertion sort iterates, consuming one input element each repetition, and grows a sorted output list. At each iteration, insertion sort removes one element from the input data. If is is smaller than the largest value in the sorted list, it finds the correct position within the sorted list, shifts all the larger values up to make a space, and inserts into that correct position. It repeats until no input elements remain.


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS