CS141 Lab 1

Class Webpage:  http://www.cs.ucr.edu/~jiang/141-homepage.html

For the labs of the first week:

  1. Commonly used linux commands (ls, cp, mkdir, mv, rm, emacs...)
  2. Makefile
  3. argc, argv command line parameters.    
    • e.g. file (right-click your mouse, then choose "save link as..."):  arg.cc
  4. Discuss debugging: gdb (ddd is a graphic interface to gdb) and simple commamds  
(setting a break, tracing step by step etc)
Here is a more complete tutorial on gdb

Take a look at the programming material from:

GNU Emacs Reference Card (pdf, 80 KB)

1. through linux "time" command: $ time  YourProgramName
2. using the following codes in C++: mytime.cc  Makefile

To see how it works, download files (right-click your mouse, then choose "save link as..."):
 link.h  link.cc   main.cc   Makefile

(Please see comments in the files for explanations.)

1. Write an efficient algorithm (in pseudo-code) for computing f(x) = x^{62} (i.e. x to the power of 62) by using the repeated squaring technique.
2. Does your algorithm use 9 multiplications?
3. (optional, for keen students) Can you do it in 8 multiplications?
4. (optional, for keen students) Can you generalize your algorithm to f(x) = x^n for any n? Can you implement your algorithm as a C++ code?
    TA: Explain the repeated squaring technique. Keep track of which students completed the exercise.