100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
CSC108 Worksheet Sorting CA$11.82
Add to cart

Class notes

CSC108 Worksheet Sorting

 2 views  0 purchase

CSC108 Worksheet Sorting

Preview 1 out of 2  pages

  • December 14, 2022
  • 2
  • 2022/2023
  • Class notes
  • N/a
  • 10
All documents for this subject (4)
avatar-seller
yudasu
CSC108H Fall 2022 Worksheet: Selection Sort Analysis


1. In the list below, i passes of the selection sort algorithm have been completed, and the double bar separates
the sorted part of the list from the unsorted part.
i

L sorted unsorted


(a) get_index_of_smallest(L, i) works by comparing pairs of items from the unsorted section. If
there are n items in L, when get_index_of_smallest(L, i) is executed, how many pairs of items
are compared? (Your answer should be a formula involving n and i.)

But our loop actually
guesses distancebtwn starts at it 1 so

in i and of iterations is
n


(b) For function get_index_of_smallest(L, i), is there a worst case and a best case?
N Cait 17
i 1 it runs n n 1 1 timesO
best case n
o 1
timetimes
worst case i o it runs n
n t times
(c) In terms of the number of items in the unsorted section, does get_index_of_smallest have constant
running time, linear running time, quadratic running time, or some other running time?

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

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


I n I in the last iteration


(e) For the call selection_sort(L), write a formula expressing how many comparisons are made
during all the calls to get_index_of_smallest.

i o n fi n 1 comparisons
i I n CI ti n 2 comparisons
i 2 n 2 1 2 3 comparisons fomin


n 1 ti comparisons
ENGIE
is n 1 n

sum 0 1 2 t n 3 ca 2 Ca D
(f) In terms of the length of the list, does selection_sort have constant running time, linear running
time, quadratic running time, or some other running time?

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

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller yudasu. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for CA$11.82. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

53022 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
CA$11.82
  • (0)
Add to cart
Added