CS661 - Algorithms, UVa


Algorithms Q and A

CS661 Students: questions and answers regarding the Algorithms class and course materials 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


Some people asked what the state-of-the-art is in algorithms and CS theory research. The best way to see the latest in algorithms research is to look at the most recent papers published at the top algorithms & theory conferences and journals:

Most of the citations in the Web pages above do not include the full text / PDF of the actual paper, but if you do a Google search for the paper's title (and/or author list), you'll very quickly find the full text / PDF of the actual paper (usually located off of the author's home page).

To do specific topic searches for CS papers, the best online bibliographic search resource is Citeseer, a very elaborate CS publications data mining and search system, which ranks the papers by the number of citations (i.e., how many other papers refer to a given paper), so the most relevant papers tend to be listed first (like Google does). It also provides the PDF/PS to most of the papers there (over 100,000 CS papers in all). Highly recommended! (and its amazing that Citeseer is actually free service!)

Keep in mind that the sources listed above contain thousands of very interesting papers (as well as hundred of thousands of other papers), so you can spend a lifetime on these sites and still not read it all. So please don't get lost or discouraged by this mountain of knowledge.

If you want a more gentle introduction to recent algorithms and theory research, I recommend starting with the Cormen et al. class textbook (especially the "advanced topics" chapters) and tracking down the original papers mentioned in the "Chapter Notes" at the end of each chapter, and also looking at more recent papers published in those same conferences and journals, etc.)


Some of the puns in the Cormen algorithms textbook are explained in http://mitpress.mit.edu/algorit hms/profjokes.html - Enjoy! :)
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;
  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 and Emails of everyone in the class, as well as the overhead slides and class handouts, are all available on the CS661 class Web site.


The homeworks (and their due dates) are posted on the CS661 class Web site.
Some people will finish their projects very early in the semester. You may demo your project (with the TA) at your convenience. What you should turn in as your project submission is outlined on page 13 of the puzzle project. Even if you are doing a project other than the puzzle solver, you should still turn in similar materials, namely:
  1. A discussion of what was implemented and how it works (i.e., an explanation of your algorithms, solution scheme, search strategies, optimizations, implementation hurdles, etc.);
  2. Some screen-shots, showing snapshots of your program's execution;
  3. A complete hardcopy listing of your code and documentation;
  4. A pointer to the on-line ready-to-run code (or a diskette/CD with same);
  5. Output from runs on several inputs that exercise your code thoroughly;
  6. For each run, please report the CPU run time (put these in one table).
  7. An actual real-time demonstration of your project running. (Please arrange with the TA an appointment to demo your project.)

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 book about infinities do you recommend?

A: The book that I recommend on the subject of 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 also available for sale at Amazon.com

Its fascinating stuff - enjoy!


Q and A regarding the project


Q: Are there alternate project ideas that we may pursue instead of the puzzle project?

A: Aside from the puzzle project, you can pick other projects too. Please narrow down your interests to a few topics, and lets chat about it sometime and I'll help you converge on a single specific topic.


Q: Where can I purchase some of those puzzles depicted in the project handout?

A: Here are some good puzzles and games Web stores.


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/puzzles only have solutions if the pieces are allowed to be flipped (so please implement flipping as an option in your project).
Some people ask 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'm not 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 or more 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: 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/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.


General technical Q and A


Some folks are asking me where they can find more information about randomness, probability, game theory, information theory, etc.

You can read more about such topics at the following subpage of the CS661 Web site:

http://www.cs.virginia.edu/~robins/CS_readings.html

For example, one point that I clarified recently w.r.t. midterm questions is the following. For sequence of coin flips (however long), every combination of H/T is possible. And the probability that an *infinite* sequence of *only* Heads will occur is *exactly* zero. But note that just because the probability of an event is *zero*, this *does not* mean that it is *impossible* for it to actually happen. For example, if you ask someone to (uniformly) pick an arbitrary real number between 3 and 4, the probability of them picking the real number Pi is mathematically equal to exactly zero, but this of course won't prevent a person from actually picking Pi in response to that query. Probability is sometime counter-intuitive like that, but there is no mathematical contradiction here.

Regarding what is "random" and how is it defined in various contexts, a good place to start reading about it is:

http://en.wikipedia.org/wiki/Randomness

In general, I strongly encourage all of you to read all the articles in http://www.cs.virginia.edu/~robins/CS_readings.html.

This set of articles is an informal easy-reading introduction to various important subareas of CS, theory, algorithms, and mathematics, and touches on their mutual interactions, as well as their relationships to other areas of science (e.g., physics, biology, etc.).

Reading such general-interest articles is a very important aspect of your Jedi :) training as computer scientists and researchers. Such readings will serve to expand your horizons, rid your mind of various biases and misconceptions, and its also a lot of fun! :)


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: 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 homework number 1


Q: When are the homeworks due?

The due dates for the homeworks are posted on the CS661 course Web site. Homeworks will be collected in class (and graded as explained at the beginning of the course). Some exam (midterm and final) questions will come directly from the homeworks, so you are strongly advised to solve *all* the homework problems. I highly encourage you to work in groups on the homeworks. To facilitate the formation of study groups, the names/photos and Emails of the people in the class are available on the CS661 course Web site.


Q and A regarding homework number 2


Q: For the last problem of homework 2 where you ask for a self-printing program (i.e., quine), can I use a blank program?

A: While a blank program may compile in some languages, it won't in C, where the shortest syntactically correct program is "main(){}". Also, a general self-printing program will be able to accommodate an arbitrary amount of "payload" in its source code (like computer viruses do), while a blank program is not scalable. So "nice try", :) but see if you can come up with a non-blank solution (say in C or C++).


Q: Can the quine be written in any programming language?

Yes, you can use any programming language. But trivial solutions such as a blank program, or a BASIC program that just says "LIST" are not acceptable, as they do not capture the intent of this question. (Note also that the basic program "LIST" accesses the source code file in the process of listing the program source code, which contradicts one of the basic restrictions in the statement of this question, namely that no files may be accessed during execution.) Remember that this is an algorithmic question, not a cheap programming trick.


Q and A regarding homework number 3


Q and A regarding homework number 4


Q and A regarding homework number 5


Q and A regarding the midterm exam


Q: In question 3, is the input array sorted?

A: No, the input array is not sorted.


Q: For question 6, do we need to find the shortest path between two given pair of nodes, or between all pairs of nodes?

A: Between a *given* pair of nodes (and that pair is given as part of the input).


Q: Does question 6 ask to find a shortest path between two nodes with a minimum number of edges AND minimum weight?

A: A shortest path may not be unique - i.e., there could be *many* shortest paths, all having the same minimum weight. So among these, we are asked to find one with a *least* number of edges.


Q: For the questions related to weighted graphs, can we assume that the edge weights are all positive?

A: Yes, all graph edge weights are positive.


Q: For the last question, if two solutions exist, should we report both?

A: The problem asks for "a solution" to be reported, if one exists. So if you report two solutions, if one exists (and a second one exists also), that's fine.


Q and A regarding the final exam


Return to Gabriel Robins' home page


EMail to robins@cs.virginia.edu