(Latest Revision: 03/05/2001)
Week 04 Notes for CS 2500, Section 002 -- Spring 2001
CS 2500, Section 002, Tuesday, March 06, 2001
- Look at Upcoming Schedule
- Class starts at 09:40. I take roll at 09:50
- Announcement(s)
- Program #2 is due next week, on Wednesday, Mar 14
- Quiz coming up next week, on Thursday, Mar 15
- We finish chapter 2 (recursion) in Carrano this week, and read
about C++ in the appendix.
- In Andersen we read about files.
- When mailing: do mail -v -s "subject", not mail -s -v "subject"
-
- Let's discuss what the inputs and outputs are of the proposed functions
in program #1. Also, what are the preconditions and postconditions?
- Additional discussion of recursion: Write out a "tree" to show how
inefficient it is to calculate (n choose k) with recursion. Also look at
programs nChoose?.cpp. Run them out of the Examples directory to
illustrate how much extra work it can take to compute (n choose k) with
poor use of recursion.
- Discussion of new programming assignment: Asg #02
- Go over the contents of file "gcdAsg"
- Note that the theorem quoted in the assignment is a rule that we
can use to create a recursive algorithm for computing a gcd.
- For example: gcd(m,n) could perform these steps:
- Print message telling what m and n are.
- if m > n, then interchange m and n
- if now m divides n then return m (How do we check whether m
divides n?)
- otherwise return gcd(n%m,m)
-
-
-
CS 2500, Section 002, Thursday, March 08, 2001
- Look at Upcoming Schedule
- Class starts at 09:40. I take roll at 09:50
- Announcement(s)
- Discuss testing requirements for program #2
- Discuss the "Four Questions for Constructing Recursive Solutions"
- How can you define the problem in terms of a smaller problem of
the same type?
- How does each recursive call diminish the size of the problem?
- What instance of the problem can serve as the base case?
- As the problem size diminishes, will you reach the base case?
-
- Discuss structs, classes, arrays of structs, structs containing arrays,
etc.
- Consider the array-based list class (files ListA.h, ListA.cpp,
useList.cpp) as an example of a struct containing an array. Note that
the element type can also be a complex data structure.
- Discuss virtues of abstract data typing and modular code.
- Easier to design correctly
- Easier to change implementations
- protects integrity of data from users
- Easier to re-use code
- Look at the
data structures talk