CSCI 3333.3
Data Structures
Spring 2013
Homework #5
Due Date: March 20th (Wednesday)
Exercises:
(1) (10%) Ex 7.23, p343, text.
(2) (30%) Ex 7.17 (a), (b) and (e), p342, text. You may assume that N = 2k.
(3) (20%) Convert the following infix expression to prefix and postfix expressions.
(a) a+(b+c)*d/(e-f)/g
(b) c*d*(e+a-b)/(f-g-h)-i
Program:
(1) (40%) Consider the Lucas Number. Write a linear recursive algorithm to implement the Lucas number for any integer, postive or negative. You may use a helper function to speed up your algorithm. Implement your algorithm by accepting a command line integer and print out its Lucas number. For example:
..>java lucas 1
Lucas(1): 1.
..>java lucas 0
Lucas(0): 2.
..>java lucas -1
Lucas(-1): -1.
..>java lucas -3
Lucas(-3): -4.
..>java lucas -6
Lucas(-6): 18.
..>java lucas 3
Lucas(3): 4.
..>java lucas 6
Lucas(6): 18.
..>java lucas 12
Lucas(12): 322.
..>java lucas 18
Lucas(18): 5778.
Submission