UMBC CMSC202, Computer Science II, Spring 1998,
Sections 0101, 0102, 0103, 0104 and Honors
Thursday February 12, 1998
Assigned Reading:
- A Book on C: 8.15
- Programming Abstractions in C: 7.5-7.6
Handouts (available on-line):
Project 2
Topics Covered:
- Announcements:
- Section 0104 is open and meets on Wednesday 10:00 - 10:50 in
ACIV Room 151.
- Note that the TAs office hours
have been posted.
- The Help Center
is open.
- Reminder that cheating will not be tolerated in this course.
- Review for Exam 1 will take place during recitation, not
lecture.
- Admonition that learning how to read technical documentation
(e.g., the man pages) is an integral part of learning how
to program.
- Merge Sort can be implemented without using recursion.
However, the iterative program
is much more complicated than the recursive version.
Somewhat surprisingly, we also discover that this iterative
implementation of the Merge Sort is a bit slower
than the recursive version (sample
runs). Hence, using recursion results in cleaner code
and sometimes faster code as well.
- Quicksort is another
divide-and-conquer algorithm for the sorting problem. One
difference between Quicksort and Merge Sort is that the
partition() function is used to divide the array
into two parts such that all the numbers in the first half
are smaller than the numbers in the second half. This
eliminates the need for the merge() function used
in merge sort. Testing the
Quicksort function shows that the running times are
a bit faster than Merge Sort (sample
runs).
- Graphing the running times of
Merge Sort versus Quicksort reveals that the running times
are approximately proportional to n log n, where n is the
number of items to be sorted.
-
We can tweak the Quicksort and Merge Sort programs for
somewhat better performance. We
tweaked Merge Sort by
calling insertion sort for arrays with fewer than 20 numbers
instead of recursively calling Merge Sort. For small arrays,
insertion sort can be faster than Merge Sort. The
sample runs show
approximately 15% improvement in the running times
compared to the previous version
of Merge Sort.
- Similarly, we tweaked
Quicksort to achieve a slight improvement in the
running times compared
to the previous running times.
- We discussed Project 2.
Last Modified:
22 Jul 2024 11:27:45 EDT
by
Richard Chang
Back up
to Spring 1998 CMSC 202 Section Homepage