Cs70 Homework Solutions


CS 70, Fall 2003
Discrete Mathematics for Computer Science

  David Wagner (daw@cs, 765 Soda Hall, 642-2758)

  Amir Kamil (kamil@cs, 566 Soda Hall)

  Tu-Th, 3:30-5:00, 3106 Etcheverry

  101. F 9:00-10:00, 310 Soda
  102. F 10:00-11:00, 310 Soda
  Section notes are available.

Office Hours:
  Wagner: Mon 4:00-5:00, Tue 1:00-2:00 in 765 Soda.
  Kamil: Mon 3:00-4:00, Wed 2:30-4:30, at 751 Soda (alcove).


Course Overview

The goal of this course is to introduce students to ideas and techniques from discrete mathematics that are widely used in Computer Science. The course aims to present these ideas "in action"; each one will be geared towards a specific significant application. Thus, students will see the purpose of the techniques at the same time as learning about them.

Broadly speaking the material is similar to that in Math 55; however, Math 55 covers a wider range of topics in less depth and with fewer applications , and is less closely tailored to Computer Science. You should take this course as an alternative to Math 55 if you are intending to major in Computer Science and if you found the more conceptual parts of CS 61A enjoyable and relatively straightforward.

List of course topics:

  • Propositions and Proofs
  • Mathematical Induction and Recursion 
  • Propositional Logic: automated proof and problem-solving
  • Arithmetic Algorithms: gcd, primality testing, the RSA cryptosystem
  • Polynomials and their Applications: error-correcting codes, secret sharing
  • Probability and Probabilistic Algorithms: load balancing, probabilistic constructions, conditional probability, Bayesian inference
  • Diagonalization and Uncomputability

Assignments and Exams

All homeworks are due on Thursday at 3:30 p.m. in the drop box labeled "CS 70" in 283 Soda. Deadlines will be enforced strictly. Late homework will be accepted only in extraordinary circumstances, and may in any case be penalized. The lowest homework grade will be dropped.


Old exams from previous semesters are available.


The following schedule is tentative and subject to change.

1August 26Overview; intro to logic Notes [ps][pdf].
[Rosen 1.1, 1.2]
2August 28Propositional logic; quantifiers [Rosen 1.3-1.5]
3September 2Induction Notes [ps][pdf].
[Rosen 3.3]
4September 4Strong induction Notes [ps][pdf].
[Rosen 3.3]
5September 9Structural induction Notes [ps][pdf].
[Rosen 3.4]
6September 11Proofs about algorithms Notes [ps][pdf].
[Rosen 3.5]
7September 16Stable marriagesExternal notes
8September 18Cake cutting Notes (in outline form): [txt].
9September 23Algebraic algorithms Notes [ps][pdf].
[Rosen 2.1]
10September 25Number theory (continuing from same notes as last time). [Rosen 2.4,2.5]
11September 30Midterm review Notes (in outline form): [txt].
October 2Midterm 1  
12October 7Primality testing Notes [ps][pdf].
[Rosen 2.6]
13October 9RSA Notes [ps][pdf]. Also [ps][pdf](revised 10/9). [Rosen 2.6]
14October 14Fingerprints, ECC, Secret Sharing Notes [ps][pdf].
15October 16Basics of counting Notes [txt].
[Rosen 4.1-4.4]
16October 21Basic probability Notes [ps][pdf].
[Rosen 5.1, 5.2]
17October 23Conditional probability Notes [ps][pdf].
[Rosen 5.1, 5.2]
18October 28Midterm review  
October 30Midterm 2  
19November 4How to lie with statisics  
20November 6Hashing Notes [ps][pdf].
November 11No class!  
21November 13Random variables, expected values Notes [ps][pdf].
[Rosen 5.3]
22November 18Variance Notes [ps][pdf].
[Rosen 5.3]
23November 20Polling Notes [ps][pdf].
24November 25"Bits on forehead"  
November 27No class! Have a great Thanksgivings Day holiday!
25December 2Countability, diagonalization, computability  
26December 4Halting problem, Godel's theorem, P vs. NP A relevant essay [ps][pdf]

Extra optional reading:


Unfortunately, there is no book that adequately covers all the material in this course at the right level. We will provide lecture notes for most of the lectures. The book Discrete Mathematics and its Applications, 5th Edition (Kenneth H. Rosen, McGraw-Hill, Inc., New York, 2003) is recommended.

Note that you should not view the availability of lecture notes as a substitute for attending class: our discussion in class may deviate somewhat from the written material, and you should take your own notes as well.


You must have taken CS 61A, Math 1A and Math 1B (or equivalents). If you struggled with any of these courses, you should probably take Math 55 instead of CS 70 as CS 70 is likely to be more conceptual in nature. If you are in any doubt about your preparation for the class, please come and talk to any one of us as soon as possible.

Grading Summary

Grading will be on an absolute scale. (However, the instructor reserves the right to add extra points to your grade at the end of the class, in extreme cases.)
  • 30% for the homeworks.
  • 20% for Midterm I (Thu, Oct 2, held in class).
  • 20% for Midterm II (Thu, Oct 30, held in class).
  • 30% for the Final Exam (Wednesday, December 17, 12:30-3:30pm).

The grading standard is available and has been fixed at the beginning of the course.

The homeworks will be graded by the course reader; depending on the time available, we reserve the right to grade some of the problems in more detail than others, and to award correspondingly more credit for them. Thus, if you turn in incomplete homeworks you are gambling on your grade.


Collaboration on homeworks is welcome and warmly encouraged. You may work in groups of at most three people; however, you must always write up the solutions on your own. Similarly, you may use references to help solve homework problems, but you must write up the solution on your own and cite your sources. You may not share written work or programs with anyone else. You may not receive help on homework assignments from students who have taken the course in previous years, and you may not review homework solutions from previous years.

You will be asked to acknowledge all help you received from others. This will not be used to penalize you, nor will it affect your grade in any way. Rather, is intended only for your own protection.

In writing up your homework you are allowed to consult any book, paper, or published material. If you do so, you are required to cite your source(s). Simply copying a proof is not sufficient; you are expected to write it up in your own words, and you must be able to explain it if you are asked to do so. Your proofs may refer to course material and to homeworks from earlier in the semester. Except for this, all results you use must be proved explicitly.

Copying solutions or code, in whole or in part, from other students or any other source without acknowledgment constitutes cheating. Any student found to be cheating in this class will automatically receive an F grade and will also be referred to the Office of Student Conduct.

We believe that most students can distinguish between helping other students and cheating. Explaining the meaning of a question, discussing a way of approaching a solution, or collaboratively exploring how to solve a problem within your group is an interaction that we encourage. On the other hand, you should never read another student's solution or partial solution, nor have it in your possession, either electronically or on paper. You should write your homework solution strictly by yourself. You must explicitly acknowledge everyone who you have worked with or who has given you any significant ideas about the homework. Not only is this good scholarly conduct, it also protects you from accusations of theft of your colleagues' ideas.

Presenting another person's work as your own constitutes cheating, whether that person is a friend, an unknown student in this class or a previous semester's class, a solution set from a previous semester of this course, or an anonymous person on the Web who happens to have solved the problem you've been asked to solve. Everything you turn in must be your own doing, and it is your responsibility to make it clear to the graders that it really is your own work. The following activities are specifically forbidden in all graded course work:

  • Possession (or theft) of another student's solution or partial solution in any form (electronic, handwritten, or printed).
  • Giving a solution or partial solution to another student, even with the explicit understanding that it will not be copied.
  • Working together with anyone outside your homework group to develop a solution that is subsequently turned in (either by you or by the other person).
  • Looking up solution sets from previous semesters and presenting that solution, or any part of it, as your own.
Academic dishonesty has no place in a university; it wastes our time and yours, and it is unfair to the majority of students.

In our experience, nobody begins the semester with the intention of cheating. Students who cheat do so because they fall behind gradually and then panic. Some students get into this situation because they are afraid of an unpleasant conversation with a professor if they admit to not understanding something. We would much rather deal with your misunderstanding early than deal with its consequences later. Even if you are convinced that you are the only person in the class that doesn't understand the material, and that it is entirely your fault for having fallen behind, please overcome your feeling of guilt and ask for help as soon as you need it. Remember that the other students in the class are working under similar constraints--they are taking multiple classes and are often holding down outside employment. Don't hesitate to ask us for help--helping you learn the material is what we're paid to do, after all!

Contact information

If you have a question, your best option is to post a message to the newsgroup. The staff (instructor and TAs) will check the newsgroup regularly, and if you use the newsgroup, other students will be able to help you too. When using the newsgroup, please do not post answers to homework questions before the homework is due.

If your question is personal or not of interest to other students, you may send email to . Email to cs70@cory is forwarded to the instructor and all TAs. We prefer that you use the cs70@cory address, rather than emailing directly the instructor and/or your TA. If you wish to talk with one of us individually, you are welcome to come to our office hours. If the office hours are not convenient, you may make an appointment with any of us by email. There are about 50 of you to every one of us, so please reserve email for the questions you can't get answered in office hours, in discussion sections, or through the newsgroup.

The instructor and TAs will post announcements, clarifications, hints, etc. to this website and to the class newsgroup. Hence you should read the newsgroup regularly whether you post questions to it or not. If you've never done this before, there is online information about how to access UCB newsgroups (see also here for more).

We always welcome any feedback on what we could be doing better. If you would like to send anonymous comments or criticisms, please feel free to use an anonymous remailer to send us email without revealing your identity, like this one.

Accounts and grading software

Some of you may already have named accounts for the lab machines from Instructional Facilities. Lab machines may be found in 2nd floor Soda. If you do not already have an instructional account, go to a Unix machine in 273 Soda and login as 'newacct' (password: 'newacct'). You should receive a 'named' account. You can also read the online instructions.

After you have obtained your account, you will need to register with our grading software. See these instructions.


In addition to office hours for the class instructors, HKN (the Eta Kappa Nu honor society) offers free drop-in tutoring every weekday 10am-4pm in 345 Soda. Contact them for more information.

Mail inquiries to.

CS 70
Discrete Mathematics
for Computer Science

 Prof. Luca Trevisan

Spring 2007
Tuesdays and Thursdays  3:30-5:00pm, 
2 LeConte



- [ News ] - [ Course information ] - [ Homework ] - [ Lecture notes ] - [ Vahab's sections ] - [ Alex's section ] -


5/18The final exam is today, Friday 5/18, 12:30pm-3:30pm. The exam is at 105 Northgate. Here's how to get from Soda to 105 Northgate directly:

Follow the green arrow. The green X marks the location of the room; the red zone is the CITRIS construction site:

5/12An extra review session will be held on Thursday, May 17th, 3-6pm. This is specifically designed for those who can not come to the Sunday's review session or have last minute questions. Location: 306 Soda Hall.
5/11Final review problems have been posted ([ PS ] [ PDF ]). The review session will work best if you attempt to solve each of them before the review session. These problems are not exhaustive — a particular topic not getting covered here does not mean that it will be completely absent from the final.
5/11All homework solutions (1-12) are now posted below.

Sun 05/06Mon 05/07Tue 05/08Wed 05/09Thu 05/10Fri 05/11Sat 05/12
 1-2p - Vahab's regular OH, 511 Soda

3-4p - Alex's regular OH, 511 Soda

3:30p-5p - Last lecture, 2 LeConte5p - HW12 due, 283 Soda

4:30p-7:30p - Last supplementary section, 320 Soda

Sun 05/13Mon 05/14Tue 05/15Wed 05/16Thu 05/17Fri 05/18Sat 05/19
5-8p - Final exam review session, 306 Soda; Review problems - [ PS ] [ PDF ]   2p-4p - Luca's extra OH, 679 Soda

3p-6p - Extra review session (Vahab). Location: 306 Soda

8:30p-10p - Alex's extra OH, Cafe Milano

12:30p-3:30p - FINAL EXAM in 105 Northgate; you may use up to three hand-written 8.5"x11" pages of notes summer
5/7Homework 12 has been updated to clarify the wording of problem 1(b). The deadline for homework 12 has been extended to Wednesday 05/09, at 5pm.
5/3Homework 12 (the last homework!) has been posted, and will be due on Tuesday 05/08.
5/3Notes for Lecture 27. Corrected typo in Notes for Lecture 24
5/3Notes for Lecture 26
4/28Homework 11 posted. It will be due on Thursday, May 3rd. You can use the normal c.d.f. calculator for some of the problems.
4/24No class and no office hours on Thursday April 26 because of the faculty retreat
4/24For the rest of the semester, I (Alex) will run an extra, non-required "supplementary section" on Wednesdays, 4:30pm-6pm. The first one will be tomorrow, Wed 04/25, in 320 Soda. I will not prepare a specific plan for the sections, so bring your own questions. One rule — no questions about the current homework. Anything else goes.
4/19Notes for lectures 23 and 24 are posted
Homework 10 posted.
4/12Homework 9 posted.
4/10Midterm 2 is today, in-class. You may use 2 pages of notes. The midterm will cover all of the material through last Tuesday's lecture (variance), with an emphasis on material presented after the the first midterm.
4/9Quick solutions to the midterm review problems have been posted: [PDF]
4/6Some midterm review problems have been posted: [PDF]; more might be posted later.
4/4Homework 7 and 8 solutions have been posted.
4/3Reminder: Midterm 2 will be in class next Tuesday, 4/10. There will be a review session on Monday, 4/9, 4pm-6pm, 306 Soda. Review problems will be posted shortly.
3/22Homework 8 posted (will be due after spring break)
3/21Notes for lectures 18 and 19 posted
3/15HW7 is posted.
3/13Posted notes for lecture 16
3/12Posted notes for lecture 15
3/8Posted HW6 below; note that, for this week only, it will be due on Wednesday, March 14, at 2:30pm
3/7Posted notes for lecture 14
3/5HW5 has been graded and may be picked up from the box outside 581 Soda (along with other homeworks that weren't picked up in section)
3/4Vahab's office hour is moved from Monday 1-2 pm to Tuesday 11am-12pm for the last minute questions. Location: 511 Soda.
3/3Additional office hours before the midterm:
Prof. Trevisan - Monday (03/05), 4:30pm-5:30pm, 679 Soda.
Alex - Monday (03/05), 10am-11:30am, 611 Soda.
3/2Solutions to all of the homeworks up to now are now posted below
3/2More midterm review problems are now available. Please look through all the problems in parts 1 and 2 of the review handout, try to solve the ones that you feel you need review on the most, and bring all your questions to the midterm review session tonight.
Midterm review, part 2: [PS] [PDF]
Midterm review, part 1: [PS] [PDF] (fixed bugs in problem 2)
A recap of topics we've covered thus far: [PS] [PDF]
3/1Reminder: Midterm 1 will be in-class on Tuesday 3/6. The midterm will be closed-lecture-notes, but you may bring a 8.5"x11" sheet of notes (single-sided).
3/1There'll be a midterm review session tomorrow (Friday, 03/02) in 306 Soda from 5pm until 7pm (we may stay around until 8pm if there's enough demand)
2/28Some midterm review problems have been posted: [PS] [PDF]; more will be posted later
2/27If you still don't have enough people in your group for the secret sharing exercise on HW5, you may use the shares for "Alice", "Bob", and "Charlie" (SIDs 10000001, 10000002, and 10000003, respectively).
2/22 Graded homeworks get passed out in discussion sections. If you don't pick yours up in section, it will be in a box outside Alex's office (581 Soda).
2/22 Notes for lectures 9 and 11 re-posted with better-quality pictures. Notes for lecture 12 posted
2/20 Posted notes for lecture 11
2/16 Alex's office hours for Monday 02/19 (President's Day) will be 10pm-11pm at Cafe Milano (on Bancroft across from Sproul Hall) instead of the usual 3-4pm slot in Soda.
2/14 Posted Homework 4
2/8Midterm dates posted below


  • Course overview: prerequisites, grading, etc
  • Instructor: Luca Trevisan. Email: luca@eecs. Office hours: Thursday 2-3pm, 679 Soda
  • TAs
  • Exams:
    • Midterm 1: Tuesday, March 6, in class. (20% of grade)
    • Midterm 2: Tuesday, April 10, in class. (20% of grade)
    • Final exam: Exam Group 20 - Friday, May 18, 1230-330P, 105 Northgate (25% of grade)
Textbook: The lecture notes are the main reference. The following textbook is also recommended for further reading
  • Discrete Mathematics and its Applications, by Kenneth H. Rosen, McGraw-Hill, Inc., New York.
  • You do not need to buy the latest edition.



Homeworks are due in the CS70 drop box in 283 Soda at 2:30pm on Tuesdays. Graded homeworks are returned in section; homeworks not picked up in section will be in a box outside 581 Soda.
  • Homework 1 [PS] [PDF] / Out: Jan 23, Due: Jan 30 / Solution: [PS] [PDF]
  • Homework 2 [PS] [PDF] / Out: Jan 30, Updated: Feb 4, Due: Feb 6 / Solution: [PS] [PDF]
  • Homework 3 [PS] [PDF] / Out: Feb 7, Due: Feb 13 / Solution: [PS] [PDF]
  • Homework 4 [PS] [PDF] / Out: Feb 14, Due: Feb 20 / Solution: [PS] [PDF]
  • Homework 5 [PS] [PDF] / Out: Feb 22, Due: Feb 27 / Solution: [PS] [PDF]
  • Homework 6 [PS] [PDF] / Out: Mar 8, Due: Mar 14 / Solution: [PS] [PDF]
  • Homework 7 [PS] [PDF] / Out: Mar 15, Due: Mar 20 / Solution: [PS] [PDF]
  • Homework 8 [PS] [PDF] / Out: Mar 22, Due: Apr 3 / Solution: [PS] [PDF]
  • Homework 9 [PS] [PDF] / Out: Apr 12, Due: Apr 17 / Solution: [PS] [PDF]
  • Homework 10 [PS] [PDF] / Out: Apr 19, Due: Apr 24 / Solution: [PS] [PDF]
  • Homework 11 [PS] [PDF] / Out: Apr 28, Due: May 3 / Solution: [PS] [PDF]
  • Homework 12 [PS] [PDF] / Out: May 3, Updated: May 6, Due: May 9 / Solution: [PS] [PDF]


  1. Jan 16, Lecture 1. Contents of the course. Boolean operations. [notes]. Rosen 1.1
  2. Jan 18, Lecture 2. Proof techniques (contrapositive, contradiction, cases). [notes]. Rosen 1.2-1.7
  3. Jan 23. Lecture 3. Mathematical induction. [notes]
  4. Jan 25. Lecture 4. Strong induction. [notes]
  5. Jan 30. Lecture 5. The stable matching problem. [notes]
  6. Feb 1. Lecture 6. More on the stable matching algorithms. Modular arithmetic. [notes]
  7. Feb 6. Lecture 7. Euclid's GCD algorithm. [notes - same as for lecture 6]
  8. Feb 8. Lecture 8. Finding inverses — the extended GCD algorithm. [notes - same as for lecture 6]
  9. Feb 13. Lecture 9. Polynomials. [notes]
  10. Feb 15 Lecture 10. Secret Sharing. [notes - same as for lecture 9]
  11. Feb 20. Lecture 11. Error-correcting codes. [notes]
  12. Feb 22. Lecture 12. Introduction to graphs. [notes]
  13. Feb 27. Lecture 13. Necessary and sufficient conditions for a graph to have an Eulerian tour or path. [notes - same as for lecture 12]
  14. Mar 1. Lecture 14. The hypercube. Hamiltonian cycles and paths. [notes]
    Mar 6. Midterm 1
  15. Mar 8. Lecture 15. Introduction to counting. [notes]
  16. Mar 13. Lecture 16. Inclusion-exclusion formula. Introduction to probability. [notes]
  17. Mar 15 Lecture 17. The Monty Hall problem. Conditional probabilities and independence. [notes - see notes for previous class and next class]
  18. Mar 20. Lecture 18. Mutual independence. Computing the probability of the union and intersection of events. [notes]
  19. Mar 22. Lecture 19. Random variables and expectation. [notes]
  20. Apr 3. Lecture 20. Independence of random variables, variance, standard deviation, concentration around the expectation. [notes]
  21. Apr 5. Lecture 21. The binomial distribution and the Poisson distribution. [Notes]
    Apr 10. Midterm 2
  22. Apr 12. Lecture 22. The geometric distribution and the coupon collector's problem. [Notes]
  23. Apr 17. Lecture 23. I.i.d. random variables and the law of large numbers. [notes]
  24. Apr 19. Lecture 24. Continuous random variables and the Normal distribution. [notes]
  25. Apr 24. Lecture 25. The central limit theorem. [same notes as lecture 24]
    Apr 26 No lecture
  26. May 1. Lecture 26. The Chernoff bound. Lying with statistics. [notes]
  27. May 3. Lecture 27. Infinity and diagonalization. [notes]

tentative schedule

Lectures 15-17 (March 8-15): counting and basic probability

Lectures 18-19 (March 20-22): conditional probability

Lectures 20-22 (April 3-12): expectation, linearity of expectation, variance, concentration of probability

April 10: Midterm 2. Syllabus: lectures 1-20

Lectures 23-25 (April 17-24): IID random variables, Chernoff bounds, and applications

Lectures 26-29 (April 26-May 8): infinity, diagonalization and halting problem

One thought on “Cs70 Homework Solutions

Leave a Reply

Your email address will not be published. Required fields are marked *