This preview shows pages 1–5. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Discrete Math in Computer Science Ken Bogart Dept. of Mathematics Dartmouth College Cliff Stein Dept. of Computer Science Dartmouth College June 23, 2002 2 This is a working draft of a textbook for a discrete mathematics course. This course is designed to be taken by computer science students. The prerequisites are first semester calculus (Math 3) and the introductory computer science course (CS 5). The class is meant to be taken concurrently with or after the second computer science course, Data Structures and Computer Programming (CS 15). This class is a prerequite to Algorithms (CS 25) and it is recommended that it be taken before all CS courses other than 5 and 15. c Copyright Kenneth P. Bogart and Cliff Stein 2002 Chapter 1 Counting 1.1 Basic Counting About the course In these notes, student activities alternate with explanations and extensions of the point of the activities. The best way to use these notes is to try to master the student activity before beginning the explanation that follows. The activities are largely meant to be done in groups in class; thus for activities done out of class we recommend trying to form a group of students to work together. The reason that the class and these notes are designed in this way is to help students develop their own habits of mathematical thought. There is considerable evidence that students who are actively discovering what they are learning remember it far longer and are more likely to be able to use it out of the context in which it was learned. Students are much more likely to ask questions until they understand a subject when they are working in a small group with peers rather than in a larger class with an instructor. There is also evidence that explaining ideas to someone else helps us organize these ideas in our own minds. However, different people learn differently. Also the amount of material in discrete mathematics that is desirable for computer science students to learn is much more than can be covered in an academic term if all learning is to be done through small group interaction. For these reasons about half of each section of these notes is devoted to student activities, and half to explanation and extension of the lessons of these activities. Analyzing loops 1.11 The loop below is part of an implementation of selection sort to sort a list of items chosen from an ordered set (numbers, alphabet characters, words, etc.) into increasing order. for i = 1 to n for j = i + 1 to n if ( A ( i ) &gt; A ( j )) exchange A ( i ) and A ( j ) 3 4 CHAPTER 1. COUNTING How many times is the comparison A(i) &gt; A(j) made? The Sum Principle In Exercise 1.11, the segment of code for j = i + 1 to n if ( A ( i ) &gt; A ( j )) exchange A ( i ) and A ( j ) is executed n times, once for each value of i between 1 and n inclusive. The first time, it makes n 1 comparisons. The second time, it makes n 2 comparisons. The i th time, it makes n i comparisons. Thus the total number of comparisons is ( n...
View
Full
Document
 Summer '08
 GALLIER
 Computer Science

Click to edit the document details