Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Document preview thumbnail
Preview 1 out of 2 pages
Class notes

CSC108 Worksheet Sorting

Document preview thumbnail
Preview 1 out of 2 pages

Computer Science CSC108 Worksheet Sorting

Content preview

CSC108H Fall 2022 Worksheet: Insertion Sort Analysis


1. Insertion Sort: Worst Case
(a) In the list below, 4 passes of the insertion sort algorithm have been completed, and the double bar
separates the sorted part of the list from the unsorted part. The item at index i is missing. Fill in
the missing item with a value that will cause insert(L, i) to perform the most number of steps.
(As a reminder, this is called the worst case.)
i

L 3 4 6 6 3 1 5

(b) When insert(L, i) is executed on the example list, how many times does the while loop iterate?




(c) When insert(L, i) is called on the example list, how many assignment statements are executed?




(d) In general, in the worst case, on pass i of insertion sort, how many times does the while loop iterate?
(Your answer should be a formula that involves i.)




(e) In general, in the worst case, on pass i of insertion sort, how many assignment statements are
executed? (Again, your answer should be a formula that involves i.)




(f) In terms of i, in the worst case, does function insert have constant running time, linear running
time, quadratic running time, or some other running time?

(a) constant (b) linear (c) quadratic (d) something else

(g) In function insertion_sort, the first time that function insert is called, i is 0; the second time, i
is 1; and so on. What value does i have the last time that function insert is called?




(h) For the call insertion_sort(L), in the worst case, write a formula expressing how many compar-
isons are made during all the calls to insert.




(i) In the worst case, does insertion_sort have constant running time, linear running time, quadratic
running time, or some other running time?

(a) constant (b) linear (c) quadratic (d) something else

Document information

Uploaded on
December 14, 2022
Number of pages
2
Written in
2022/2023
Type
Class notes
Professor(s)
N/a
Contains
12
CA$12.10

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Sold
2
Followers
1
Items
25
Last sold
3 year ago



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions