



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
A lab guide for students in the csci 204 course at bucknell university. It covers the topic of recursion, with emacs editing tips and practice problems. Students are expected to write recursive programs, understand the logic of existing recursive functions, and modify a java program to list all files in a directory and its sub-directories recursively.
Typology: Lab Reports
1 / 7
This page cannot be seen from the preview
Don't miss anything!
Introduction to Computer Science II Bucknell University Computer Science Department http://www.eg.bucknell.edu/~csci204/
© c February 7, 2007
**1. Objectives
Section 3: Practice With Recursion 4
Since the subject of today’s lab is recursion, here is an emacs tip related to recursion. emacs has a command that will solve the Towers of Hanoi problem. Issue the command M-x hanoi
and emacs will solve the problem with 3 disks. If you want to change the number of disks, use a numeric argument. You can specify a numeric argument by typing C-u followed by the digits of the argument. If you type
C-u 5 M-x hanoi emacs will solve the problem with 5 disks. Most emacs commands will accept a numeric argument. For example, you can move down 25 lines in a file by typing C-u 25 C-n. You can put 70 stars across a page by typing C-u 70 *.
Copy the programs Factorial.java and TestFactorial.java from the ~csci204/2007-spring/student/labs/lab04 directory into your lab directory. Compile and run TestFactorial.java. Observe the behavior of the program. Read the program Factorial.java and understand the logic of the program. Then answer the following questions in your handin file.
Section 3: Practice With Recursion 5
if (n == 1) return 1; will the final result change? Why?
Recursive algorithms are natural for solutions to problems with hierarchical structure. Such a problem is listing all the files in a directory and all of its sub directories. Since the Unix file system is hierarchical, we should immediately think of using a recursive approach.
Section 4: Hand In 7
ls -R ~csci204/2007-spring/student/labs/lab where the -R option recursively lists subdirectories encountered.
Note: All code you write must be appropriately commented. UML, Javadoc, and other software documents are not necessary for this lab. Please save all answers and code to one handin.java file and print it using a2ps -s 2 or some other double-sided print command. The file redirect command from lab03 may be helpful when creating the handin.java file.