CS202 - Discrete Math, UVa


CS202 Q and A

CS202 Students: questions and answers regarding the CS202 Discrete Math class material will be accumulated in this file throughout the semester. Please browse through it often. Thanks, - Gabe
The questions in this file are organized by the following categories; you may peruse this file sequentially, or jump directly to the category of your choice by clicking on one of the following links:

General administrative Q and A


Here are some requests / comments from the TA regarding homeworks:

1. Please put a section number and a (book) problem number on each solution, so we can find it easier in your homework (don't just use 1, 2, 3, ...)

2. Write on the first page a list of all the problems that you *did not* solve, so the grader does not have to search through all of the pages trying to find solutions that are not there.

3. Please write legibly, or better yet, use a text editor to write the solutions - this makes it easier to grade (and also easier for you to edit, catch mistakes, and correct glitches).

4. Staple or clip the homework pages (no loose pages please).

5. Please solve the problems correctly, as correct solutions are easier to grade. :)

6. The Mon & Wed TA office hours will be 2:30-3:30 (several students said they would prefer that time, as it conflicts less with their schedules).


Q: The due date for problem set 1 says monday February 4, but this is a wednesday and we don't have class on that day. Could you please tell me if it is really February 4th or something else?

A: You are right - I changed it to Tues Feb 3 (and you get an extra credit point for catching this error! :) )


Q: Are problem sets going to be handed in for grading, and about how many problem sets do you think we will have throuout the semester.

A: Yes, problem sets will be turned in and graded (although not all the individual problems on each set will necessarily all be graded - I'll pick a random half of the the problems on each assignment, and we'll grade those only; I'll discuss this grading strategy in more detail in class). I anticipate that there will be about 4 or 5 assigned problem sets total in this class.


Q: In regards to the extra credit that will be awarded to projects turned in early, what is the due date for the project? When does the project have to be turned in by to receive the extra credit?

A: The project is due on the (first) day of the final exam. One extra credit point will be given per each day that the project is turned in early.


Q: Do you have any criteria which type of questions should be directed to you and which type to the TA's?

A: The algorithm to get your questions answered is pretty simple:

  1. First, use the textbook, or check the handouts, or look in this Q&A file;
  2. If your question still isn't answered, ask other people from the class (if convenient);
  3. If your question still isn't answered, ask the TA's;
  4. If your question still isn't answered, ask me;
  5. Go to step (1)

Of course if you have a special reason to skip one of these levels of help, that's fine also, but lets try to stick to the above protocol.

Note that rule (2) is designed to encourage brainstorming among you, which is highly encouraged.


Q: If I am unable to attend a class, how can I obtain a copy of that day's notes?

A: Just contact anyone in the class, and photocopy it from them. The names/Emails/phones of everyone in the class are available from the class Web page. The overhead slides and class handouts are available on the CS202 class Web site.


Q: What software can I use to type in some mathematics/symbols/notation such as the summation sign, the subset sign, etc.?

A: I use MS Word, which does a reasonable job (all my handouts/slides are done in MS Word). Another option is LaTex, which is a very powerful typesetting system, but this is overkill for many things; I use this for technical papers and camera-ready publications. LaTex is based on TeX, Don Knuth's famous typesetting system.


Q: When we get extra credit points in class, what does that go toward?

A: Well, I will first compute the course grades without *any* extra-credit (according to the breakdown discussed in the syllabus). Then, I will factor in the extra-credit, which will raise up the course grades of some people. So, two things are therefore true here:

a) this scheme is fair, in the sense that extra-credit could help you, but *not* having extra-credit will *not* hurt you (since the class grades are first computed *without* the extra-credit, and don't drop afterwards)

b) the more extra-credit you have, the higher your course grade will be.

The reason I use this extra-credit scheme is to encourage people to be more pro-active and participate more; this makes the learning process much more interesting, effective, and exciting.

Also, extra-credit problems encourages many people to think more, be resourceful, come prepared (and not be late) to class, remain alert, etc.

I hope this scheme is acceptable to everyone (it has worked very well for everyone in the past).


Q and A regarding the handouts/slides


Q: What was the name of the book you referenced in CS202 class today?

A: The book that I mentioned in class today about infinities is the next-to-last reference in the class handout which discusses some aspects of infinities, among other things. The book is:

Rucker, R., Infinity and the Mind: the Science and Philosophy of the Infinite , Harvester Press, 1982.

This book is available at Amazon.com

Its fascinating stuff - enjoy!


On page 22, "parentasis" should be "parenthesis"
On page 77, "existance" should be "existence"

A: Thanks for finding these errors; I gave you two extra credit points for finding these typos.


Q and A regarding the project


In some of the tiling puzzle files, not all of the tiles are necessary to cover the board, just some subset of them. This is OK, and your program should solve such cases correctly.
Here are a few helpful hints RE the project:

* There is no need to try all permutations of all the pieces; clearly each puzzle can be solved by placing the pieces in a fixed permutation order (as long as each piece is placed into the right spot on the board). If your code goes through all piece permutations (and then tries all possible position combinations for each permutation), it runs in time N! longer than it needs to (where N is the number of pieces). This means it would run in months or years of CPU time instead of just seconds (!)

* Instead of picking a random or arbitrary permutation, have your code try to place the pieces on the board in the order of their decreasing size. To see why this is a much more efficient strategy, consider the following example, of five pieces to tile an 8x8 board:


  ######     # 
  ######
  ########   #
  ########    
  ########   #
  ########   
  ########   #
  ########   

If you start by placing the four 1x1 pieces first, there are 64-choose-4 ways to place them (which is a number in the millions), but most of these choices will lead to an infeasibility when trying to place the last large 5th piece. On the other hand, if you place the large (60-square) piece first, the other four small pieces will immediately fall into place, saving you a lot of time. So this (extreme) example illustrates why it is often more efficient to place the larger pieces first (basically because this will lead to infeasibiliy or dead ends sooner, which in turn prunes the search tree more aggressively, and therefore reduce the overall run time).

There are many other kinds of optimizations that you can implement, and some of them will help reduce the runtime tremendously.


People have asked what are reasonable run times for the various puzzles, so here is an example: some projects demoed in the past can find one solution for the "checkerboard" puzzle in less than one (1) second of CPU time, and all eleven (11) non-isomorphic solutions to this puzzle within about seven (7) CPU seconds.
Some of the puzzles in http://www.cs.virginia.edu/~robins/cs202/puzzles only have solutions if the pieces are allowed to be flipped (so please implemnent flipping as an option in your project).
Some people asked about partial credit for projects that don't work; this is a tough issue, since one can claim that "a blank sheet of paper is an operating system that doesn't work". Please try hard to make your code do something useful (recall that the project was handed out on first day of classes, that I mentioned many times that the bulk of the work on this project should not be postponed to the last week of classes, note that this advice is also printed in bold underlined font on page 8 of the project description handout, etc.) I wasn't kidding about all this - its just the "voice of experience". On the positive side, I am happy to report that in the past some teams finished this project up to six weeks ahead of the deadline, which is great!
Q: I know that each piece in the puzzle can be rotated any direction, but can the pieces be flipped (mirrored)? In other words, is the only representation of puzzle pieces, some rotation of how they appear in the file? Can some puzzles have their pieces flipped (mirrored) and some not?

A: Make the "flipping-allowed" a global user-selectable flag that applies to all the pieces. All pieces can be rotated though.


Q: For the puzzle solver final project, seeing as how there is no humanly way of verifying how many solutions there are to a given puzzle of even a smallish-moderate size, can you give us the number of solutions to a given tile puzzle?

A: Good point. For most of those puzzles, they are new (at least to me), and so I don't know the total number of solutions myself. But as some of the projects are being turned in, a consensus will form w.r.t. this data, and then we'll know the number of solutions for each puzzle.


Q: For CS 201 we were to implement a menu class that used the EzWindows API. Would it be alright if we used that for our GUI for the project, or would you consider it an honor violation to use code developed in another class to create our GUI.

A: That is fine with me.


Q: Is there a specific range of ASCII characters that the colors in the input file will be limited to, e.g. the letters and numbers?

A: You may assume that only keyboard characters will be used (i.e., letters, numbers, and special characters).


Q: Is the intent of the project to be able to reconstruct any 8x8 chess board given the pieces, OR to reconstruct ANY puzzle of any size given its pieces?

A: Your code should be able to solve ANY puzzle; and in particular, it should be able to solve the 8x8 puzzles that are specified in the project description, among others.


Q: Will the input file contain the pieces separated by periods?

A: No, pieces will be randomly scattered in the files, separated by blanks (as in the puzzle instances at http://www.cs.virginia.edu/~robins/cs202/puzzles/)


Q: How are we supposed to time our programs? Is there some C++ timing function that we could use? Or is it simply a stopwatch deal?

A: Most systems have a timing command, that takes another command as an argument and returns the CPU time used during its execution (on UNIX systems it is the time(1) command).


Q: What is the maximum color allowed for the puzzle pieces?

A: Lets agree that the maximum number of allowed colors is 50 (so these may be denoted in the input file by all the digits (0-9), the letters (a-z), and a few printable special characters (basically all the keyboard characters).


Q: What is the max width in the input file?

A: Lets agree that no input file will be more than 80 characters wide.


Q: In class you mentioned a few times that the puzzle assignment was only a suggestion for our term project. Does this mean that we could come up with some other possibilities and present them to you, as other options for things to do?

A: Yes, that is an option, as long as such an alternate project is relevant to the class material, is non-trivial in scope, etc. Please feel free to make a list of a few possible project topics, and we can then review these topics together and decide on which one would be most appropriate.


Q: I have a question regarding your use of the term isomorphism in term project assignment. The document states: "Make sure that your code finds and reports all the non-isomorphic solutions of a given instance (instead of finding only one of the solutions). Note that rotated / reflected versions of the same solution do not count as distinct from one another." I can think of several ways to interpret this (and the solutions it will eliminate), but I am not sure which is the correct interpretation. My interpretations (in descending order of strictness):

1) Label every "point" in the solution (I use point to mean an individual piece of a tile, ie. one colored part, is there a better name for this?) in the solution with the "shape" of the piece it came from, and eliminate all solutions that are rotated/reflected versions of one another (reflections are only possible if the pieces are allowed to be reflected I believe). This eliminates all basic rotations/reflections as well as solutions where two identically shaped pieces are interchanged. Also eliminates solutions where a piece is rotated/reflected but preserves shape.

2) Same as above but label every point with the actual piece it came from, and eliminate. This eliminates rotations/reflections but allows two identically shaped pieces that are interchanged to be separate solutions. Also eliminates solutions where a piece is rotated/reflected but preserves shape.

3) Label every point with the piece and in-piece coordinates it came from, and eliminate. Eliminates basic rotations/reflections but allows two identically shaped pieces to be interchanged, and isomorphic rotations of an individual piece to count as separate solutions.

I appreciate the clarification.

A: What I had in mind is to eliminate entire solution ensembles that are rotations or reflections of other solutions. And if two pieces are identical, then swapping them does not create yet another solution. Finally, if a piece is identical to its reflection/flip (modulo rotation), then flipping it doesn't count as another solution either. So ideally your program should only generate the basic "interesting" *distinct* solutions (and any rotations, reflections, identical-piece-swapping, and identical-flipped-piece derivative solutions can always be easily generated from those basic ones). So this sounds like your number (1) scenario.


General technical Q and A


Q: What is a way in which the rationals can be mapped 1-to-1 with the naturals?

A: You can do this by putting the rationals in a table (with cell (a,b) representing the rational number a/b), and then using dovetailing to establish the 1-to-1 correspondence.


Q: I just want to clarify, a 1-to-1 correspondence was established between all the reals and the reals strictly between 0 and 1 (with the semicircle and line diagram in class) so therefore the set of reals isn't bigger than the set of reals between 0 and 1.

A: That's correct - these two sets have the same cardinality.


Q: Is it possible to dovetail in 3 dimensions?

A: Yes; in fact, you can dovetail in *any* finite number of dimensions. For example, in 3D, imagine a small sphere centered at the origin, slowly expanding out in size; now, just number using integers all the lattice points (i.e., all (a,b,c) with a,b,c all being integers) that the sphere intersects as it slowly inflates (if it intersects several lattice points simultaneously, number these in arbitrary order). This shows that the set of all ordered triplets is countable.


Q and A regarding home work number 1


Q: In the homework in section 1.4 #12, in some of the questions can the unique existence quantifier be used or are we only allowed to express it using the "for all" and "there exist" quantifiers.

A: You can use the "Unique Existance" quantifier (unless the problem states explicitly that you should not use it).


Q: On Rosen, p. 38 (Fifth Edition), can you explain why they formulated it as "for all x (P(x) -> Q(x))" and not as "for all x (P(x) ^ Q(x))"?

A: Remember that the "Universe" of values for X is the set of "all creatures", so "for all x (P(x) ^ Q(x))" means "every creature is a lion AND fierce", while "for all x (P(x) -> Q(x))" means "every creature that is a lion, IS also fierce", or equivalently, "all lions are fierce" (and non-lions are not necessarily fierce).


Q: In Homework #1, there are several questions in section 1.2 regarding a collection of logical operators being functionally complete (#38). What does it mean for a collection to be functionally complete, and how do you prove this?

A: A set of Boolean functions is "functionally complete" if any other Boolean function can be represented as a composition of functions in this set. For example the set of functions {AND, OR, NOT} is functionally complete, since any of the other 2^(2^2)=16 Boolean functions over two variables can be represented as a combination of these three basic building blocks. Proving functional completeness *from scratch* for a set of functions is tedious (e.g., you can list out the many truth tables); a shorter proof may involve showing that a set of functions already known to be functionally complete can be fully represented using combinations of functions from unknown set in question.


Q: I have the Fourth edition of the CS202 text book, and if it is not too much trouble I was wondering if you could send me the problem numbers for the Fourth Edition.

A: A few of the problems on the homework sets do not appear in the Forth Edition. So I would recommend that you get the Fifth Edition (some errors/typos are always corrected from one edition to the next). Alternatively, you can xerox the problem set pages from, the Fifth Edition and work from those copied pages. (I would recommend just getting the latest book though - its simpler and that way you'll have the most up-to-date version; books are one of the best investments a person can make in my opinion). Also, consider that the second semester of Discrete Math CS302 uses the same textbook, so if you plan to take CS302, you'll need this book anyway.


Q and A regarding homework number 2


Q: For the second problem set in cs 202, section 1.8, problem 60 part f, there is a open ceiling bracket and it is closed by a floor bracket. Is this a valid symbol or is it a typo? Is that an extra credit mistake?

A: Yes, it is a typo; it should be f(x) = floor(x/2) + ceiling(x/2) (so it is an open ceiling bracket followed by a closed ceiling bracket). And yes, this is worth an extra credit point - thanks for catching this!


Q: Is there a one-to-one correspondence between I x I and I?

A: Yes.


Q: Is there a one-to-one correspondence between R x R and R?

A: Yes.


Q: Is there a 1-to-1 correspondence between the unit interval [0,1] and R x R ?

A: Yes.


Q: Can any real number be defined as the *limit* point of a sequence of rationals?

A: Yes. In fact, a real number can also be defined as a *sum* of an infinite number of rationals (but not as the sum of a finite number of rationals, which is always rational).


Q and A regarding homework number 3


Q and A regarding the midterm exam


Q: f is big-O of g means f is the upper bound of g right?

A: No, f(x) = O(g(x)) means f is upper-bounded by g.


Q: For problem number 3: if we could figure out a way to write all the polynomials in a table and show how they can be counted, would that be sufficient for a proof?

A: Yes.


Q: In problem 3, is n a fixed natural number, or do we have to count all the polynomials for n = 1, 2, 3, ... and so on, and can n be arbitrary large?

A: n can be any natural number, and all values of n are possible and must be accounted for.


Q: Is c only positive rationals or can it be both positive and negative rationals?

A: The c's can be either positive or negative rationals.


Q: In Q2, when you mention O() do you mean big-O?

A: Yes.


Q: Could you give an example of mutually relatively prime numbers?

A: 5, 10, and 13 are mutually relatively prime, since not *all* three of them have a factor in common (although two of them, 5 and 10, do).


Q: On question 3, n is a (finite) natural number, so there are only a finite number of terms in any given polynomial, correct?

A: yes.


Q: In question #5, is the greatest common divisor the same thing as the greatest common factor?

A: Yes.


Q: In problem #2, can f(x) and g(x) be negative?

A: Yes.


Q and A regarding the final exam


Q: Can an infinite matrix have just a finite number of rows, but an infinite number of columns, or vice versa?

A: Yes. (Good question!)


Q: What is an infinite matrix and an infinite boolean matrix?

A: It is a matrix where at least one of the two dimensions is not finite. A Boolean matrix is one where every matrix entry is at either 0 or 1.


I'm a little worried about some of the exam-related questions, that I have been receiving: many of them attempt to trivialize an exam problem by making false assumptions or introducing non-existent constraints. Inquiries like that fall squarely in the "nice try" category, and I would not insult your intelligence by asking you such trivial questions/variations. Advice: please watch your tendency to look for an "easy way out" of problems by making invalid assumptions. This is a good general rule to live by. Thanks, :) - Gabe
Q: On problem 2, can we say that no one knows anyone else, so that means there are at least two people who know the same number of people in the group, notably they know 0 people in the group?

A: That's only a very specific type of group. You also have to address the infinity of other types of groups.


Q: Does the time complexity of the algorithms matter?

A: Yes. A lower time complexity is worth more points.


Q: On problem 7, we are only looking at the dimension of the matrices, right?

A: No. If two matrices differ by even one entry, they are distinct.


Q: For problem 3, the non-equivalent ways N people can be seated around the table, what do you mean?

A: Two seatings are equivalent if one is a rotation of the other; otherwise, they are non-equivalent.


Q: For questions 7 and 8, does a set of matrices include all of the entries in the matrices, or are the matrices themselves considered distinct entities?

A: Each element of the set is an MxN matrix.


Q: Are we allowed to use homework solution handouts in our proofs?

A: Yes.


Q: For problem 3, do the people have to be seated uniformly around the table or can we squeeze ten people on one half of the table and leave 1 person on the other half?

A: The people are seated uniformly around the table (and there is no distinguished "half" of the table).


Q: In the bipartite problem, do we know which other vertices each node is adjacent to, or do we have to figure this out in the algorithm?

A: You are given the matrix in some standard representation (e.g., a long list of vertex pairs). Everything else you require, you need to compute from this input data.


Q: On the table seating problem, I was wondering if N has to be greater than 1, or if N can be 1.

A: Solve this problem for all N, including 1.


Q: In Question 2, is the set of people finite?

A: Yes.


Q: When you say that rotations are equivalent, does that mean if everyone moved one seat over, that would be equivalent?

A: Yes.


Q: On the final are we allowed to use properties that we proved for homework as theorems so that we don't have to prove them again?

A: Yes (but also give a sentence or two summarizing why that is a true statement, not necessarily a complete proof).


Q: What is the number of chairs around the table?

A: The number of chairs is the same as the number of people, namely N.


Q: Can the chairs be moved around?

A: No.


Q: Is rolling 2 with the first die and 4 with the second die equivalent to rolling a 4 with the first and a 2 with the second?

A: In both cases the sum is 6, but these are two distinct events.


Q: Does "one of the smallest-weight edges in the graph" only apply to graphs where there are 2 or more edges with equally smallest weight?

A: No, this applies to all weighted graphs; if the smallest-weight edge is unique, then "one of" (this singleton set) refers to that particular edge.


Q: We are allowed to use any textbook and book that we can find (i.e. in the library) for the final, correct?

A: Yes.


Q: For question #8, can an infinite boolean matrix have duplicate entries? And is 000 an identical entry to 0, or 00?

A: Each entry in a Boolean matrix is either a 0 or a 1 (and nothing else).


Q: For question #7, when you say "all possible sizes" does this mean that the set of all finite rectangular matrices is infinite?

A: For each pair of natural numbers M and N, all possible matrices of size MxN are in this set, so obviously this is an infinite set.


Q: Can a 3-by-1 matrix be equivalent to a 1-by-3 matrix?

A: No, matrices of different dimensions are by definition different.


Q: In problem 2, does a person "know" himself / herself?

A: No, self-"know" does not count here.


Q: In problem 2, does "there are two people..." mean "there are at least two people..." ?

A: Yes.


Q: In problem 4, is it a regular die with six faces?

A: Yes.


Q: Does that rolling a six with one die means you roll a die and get the number six?

A: Yes.


Q: Does "a total of six" means the sum of two dice?

A: Yes.


Return to Gabriel Robins' home page


EMail to robins@cs.virginia.edu