...
- 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 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 Block |
---|
random
is a function in the Scheme library, but it is not a mathematical function, since the output is not determined by the input. HTML |
</ol>
Now, make sure you know how to use
...
time
...
- .
...
...
- Time
...
isort
...
- on a list of 200 elements.
...
- Run the exact same expression again a couple times.
...
- Note that the time varies some.
...
- We typically deal with such variation by taking the
...
- average of several runs.
...
- The variation is caused by a number of low-level hardware
...
- phenomena that are beyond the scope of this course (see
...
- ELEC 220 and
...
- COMP
...
- 221).
...
- Continue timing, filling in the following chart.
...
- When you're done, compare results with other pairs in the lab.
input size
200
1000
5000
isort
up
up
up
down
down
down
rand
rand
rand
qsort
up
up
up
down
down
down
rand
rand
rand
...
| 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
...