Comp 182

Homework Assignments

Spring Semester 2015

 

HW #1                                                                                    due: Tuesday 15 Sept 2015 @ the end of class

Putnam                       

Given the following method,

 

                                                   int fib( int n )

                                                   {

                                                       If (( n == 1) || ( n == 2)) return 1;

                                                       else return fib ( n – 1) + fib ( n – 2 )

                                                   }                   

 

Write the code and test it for n = 5, 7, 9 and

record the answers for each of the values.

 

a)    Modify the code as shown below,

 

                                                   int fib( int n )

                                                   {

                                                      {

                                                           static boolean level = True;

                                                           static int k = 0;

                                                           if level == True

                                                           { System.out.println ( “fib( “ + n + “) at level “ + k + ” ); “ );   

                                                             // which should print  fib( 5 ) at level 0 “ for the first call.

                                                              level  = False;

                                                              k++;

                                                           }

                                                           else if  ( level == False )

                                                           { System.out.print ( “fib( “ + n + “) at level “ + k + ” ); +  “ );   

                                                              Level = True;

                                                           }

                                                       )

                                                       If (( n == 1) || ( n == 2)) return 1;

                                                       else return fib ( n – 1) + fib ( n – 2 )

                                                   }                   

 

b)   Implement the code and run it for n = 5, 7, 9, 10, 20, - 5 and

record the answers for each of the values.

c)    Specify the preconditions and postconditions  

for the fib method as defined above.

  Use the level numbers and the printed statements

                                                 “fib( “ + n + “) at level “ + k + ” +  “ “fib( “ + n + “) at level “ + k + ” ); “ );  i.e.,

                                                                        fib( 5 ) at level 0 “

                                                                        fib( 4) at level 1 +  fib( 3 ) at level 1 “

                                                              to construct a tree which traces the entire Fibonacci computation. 

 

SUBMIT

                                                                                                      i.        A printed copy of the code as specified in a above.

                                                                                                    ii.        A printed copy of the input values and their associated output values as documented in b above,.

                                                                                                   iii.        A precondition and postcondition report as specified in c above.

                                                                                                   iv.        A computer generated tree for n = 10

 

 

 


HW #2                                                                                    due: Tuesday 15 Sept 2015 @ the end of class

Putnam                    

 

a)    Read page 148 (A Recursive void Method: Writing a String Backward) to page159

b)   Implement the code for writeBackwards2 and execute it for “Putnam”, “Bryncethin” and Your name.

c)    Describe in detail what the writeBackwards2 code does for the submitted values.

d)   Describe in meticulous detail how the writeBackwards2 code produces the given output.

 

SUBMIT

                                                                                                      i.        A printed copy of the code as specified in b above.

                                                                                                    ii.        A report based on c above.

                                                                                                   iii.        A very meticulous report that refers in detail to the code as specified in b above.

 

 

 

 

 

 

 

 

 

 


Archive Spring 2015

DO NOT USE

 

 

 


                                                                       

HW #3                                                                                                due: Wednesday, 13 May 2015 @ JD1600A 10am after Final Exam

Prichard Carrano               pages    exercises 

                                                           

 

HW #4                                                                                                due: Wednesday, 13 May 2015 @ JD1600A 10am after Final Exam

Prichard Carrano               pages            exercises                                         

                                                303-304         1, 2, 4, 10

 

HW #5                                                                                                due: Wednesday, 13 May 2015 @ JD1600A 10am after Final Exam

            Prichard Carrano               pages            exercises

                                                            341-342         9, 10, 13, 14

 

HW #6                                                                                                due: Wednesday, 13 May 2015 @ JD1600A 10am after Final Exam        

Prichard Carrano               pages            exercises

                                                            396-398         7, 15

                                                                                   

HW #7                                                                                                due: Wednesday, 13 May 2015 @ JD1600A 10am after Final Exam        

Prichard Carrano               pages            exercises

                                                            447- 448        7, 8                 

 

HW #8                                                                                                due: Wednesday, 13 May 2015 @ JD1600A 10am after Final Exam

            Prichard Carrano               pages            exercises

                                                            554-556         1, 4, 5, 7, 11, 12, 13,

18, 20

 

 


 

 

 

 

 

 

 


Spring Semester 2014

 

HW #1                                                                                                                        due: 26/27 Feb ‘14

Prichard Carrano               pages 127 - 128   exercises 1, 4

                                                pages 190 - 193     exercises 6, 7, 12, and 18.

For exercise 18, design & implement all parts a, b, c, d & e.

Write recursive methods for the recurrence formulations in parts b & c. Execute program and provide requested answers.

 

HW #2                                                                                                                        due:    10/11 Mar ‘14                              

Prichard Carrano               pages 304 - 305       exercises 7, 8, 13, 14  

 

HW #3                                                                                                                        due: 14/15 April 2014

Prichard Carrano               page 399                   manually trace exercise 18

leaving an audit trail of all changes

                                                pages 400 – 401      implement program 6, i.e., the Calculator

                                                page 447                   manually trace exercise 7

                                                            page 450                   program 1 implement both the

·         circular linked list and the

·         linked list with a head and a tail reference

then

·         run both queues with identical input data streams and compare the output streams to make sure that they both produce the same results

·         compare the code statements to determine which implementation is

o   easier to write

o   easier to understand

o   more efficient

·         write a short report concerning the two implementations

 

 

Preparation for the Final Exam

 

HW #4            due: 13/14 May 2014

Prichard Carrano               pages 634 – 640      exercises 7, 10 give examples, 11, 12, 15, 19  

 

HW #5            due: 13/14 May 2014                                                                                                                                             

            Prichard Carrano               pages 554 – 557      exercises 4, 5, 8, 11, 12, 13, 18, 27                                                                                   

HW #6            due: 13/14 May 2014                                                                                                                                             

                                    Prichard Carrano               pages 446 – 449      exercises1, 2, 12

 

HW #7            due: 13/14 May 2014                                                                                                                                             

Prichard Carrano               pages 395 -- 400     exercises 7, 9, 14, 15

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

HW #8                                                                                    due:

 

HW #9                                                                                    due:

 

HW #10                                                                                  due:

 

HW #11                                                                                  due:

 

HW #12                                                                                  due: