Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. We need some data to use for our timing experiments. Write a function up: nat -> (list-of nat) which constructs a list of naturals starting with 0 in ascending order or retrieve it from a previous lab. For example, (up 7) returns (list 0 1 2 3 4 5 6). You can probably write it faster using build-list that you can retrieve it. Similarly, write a function down: nat -> (list-of nat) that constructs a list of naturals ending in 0 in descending order. For example, (nums-down 7) returns (list 6 5 4 3 2 1 0).

    Now write a function
    Code Block
    rands
    Wiki Markup
     that constructs a list of random numbers in the range from {{0}} to {{32767}}. To create a single random number in the range from {{0}} to {{_n_}}, compute {{(random _n+1_)}}.  For larger numbers in the range {{\[0, 32768)}}, try:
    Code Block
    (define max-rand 32768)
    (random max-rand)         ; random is built-in
    
    Note: Code Blockrandom is a function in the Scheme library, but it is not a mathematical function, since the output is not determined by the input.
    HTML
    </li>
    HTML</ol>

    Now, make sure you know how to use

...

  1. time

...

  1. .

...

HTML
<ol>
HTML
<li>

...

  1. Time

...

  1. isort

...

  1. on a list of 200 elements.

...

HTML
</li>
HTML
<li>
  1. Run the exact same expression again a couple times.

...

  1. Note that the time varies some.

...

  1. We typically deal with such variation by taking the

...

  1. average of several runs.

...

  1. The variation is caused by a number of low-level hardware

...

  1. phenomena that are beyond the scope of this course (see

...

  1. ELEC 220 and

...

  1. COMP

...

  1. 221).
HTML
</li>
HTML
</ol>

...

  1. Continue timing, filling in the following chart.

...

  1. When you're done, compare results with other pairs in the lab.
HTML
<table border=1>
HTML
<tr>
HTML
<td>
HTML
</td>

HTML
<th colspan=6>

input size

HTML
</th>
HTML
</tr>
HTML
<tr>
HTML
<td>
HTML
</td>

HTML
<th colspan=2>

200

HTML
</th>

HTML
<th colspan=2>

1000

HTML
</th>

HTML
<th colspan=2>

5000

HTML
</th>
HTML
</tr>
HTML
<tr>

HTML
<th rowspan=3>

isort

HTML
</th>

HTML
<td>

up

HTML
</td>

HTML
<td width=60>

 

HTML
</td>

HTML
<td>

up

HTML
</td>

HTML
<td width=60>

 

HTML
</td>

HTML
<td>

up

HTML
</td>

HTML
<td width=60>

 

HTML
</td>
HTML
</tr>
HTML
<tr>

HTML
<td>

down

HTML
</td>

HTML
<td width=60>

 

HTML
</td>

HTML
<td>

down

HTML
</td>

HTML
<td width=60>

 

HTML
</td>

HTML
<td>

down

HTML
</td>

HTML
<td width=60>

 

HTML
</td>
HTML
</tr>
HTML
<tr>

HTML
<td>

rand

HTML
</td>

HTML
<td width=60>

 

HTML
</td>

HTML
<td>

rand

HTML
</td>

HTML
<td width=60>

 

HTML
</td>

HTML
<td>

rand

HTML
</td>

HTML
<td width=60>

 

HTML
</td>
HTML
</tr>
HTML
<tr>

HTML
<th rowspan=3>

qsort

HTML
</th>

HTML
<td>

up

HTML
</td>

HTML
<td width=60>

 

HTML
</td>

HTML
<td>

up

HTML
</td>

HTML
<td width=60>

 

HTML
</td>

HTML
<td>

up

HTML
</td>

HTML
<td width=60>

 

HTML
</td>
HTML
</tr>
HTML
<tr>

HTML
<td>

down

HTML
</td>

HTML
<td width=60>

 

HTML
</td>

HTML
<td>

down

HTML
</td>

HTML
<td width=60>

 

HTML
</td>

HTML
<td>

down

HTML
</td>

HTML
<td width=60>

 

HTML
</td>
HTML
</tr>
HTML
<tr>

HTML
<td>

rand

HTML
</td>

HTML
<td width=60>

 

HTML
</td>

HTML
<td>

rand

HTML
</td>

HTML
<td width=60>

 

HTML
</td>

HTML
<td>

rand

HTML
</td>

HTML
<td width=60>

 

HTML
</td>
HTML
</tr>
HTML
</table>
HTML
</td>
HTML
</tr>

...

 

input size

 

 

 

 

 

200

 

1000

 

5000

 

 

up

 

up

 

up

 

isort

down

 

down

 

down

 

 

rand

 

rand

 

rand

 

...

COMP 280
introduces concepts of how these algorithms behave in general.
The punchline is that we can say that both insertion sort and
quicksort on lists are "_O(n

...