CS 112 Fall 2012 Lab 01 Haohan Zhu
CS 112 - Fall 2012, Lab 01 Haohan Zhu
CS 112 - Fall 2012, Lab 01 11/3/2020 Using Piazza Boston University Slideshow Title Goes Here § http: //www. piazza. com/bu/fall 2012/cs 112 a 1 § Any question related to the course 2
CS 112 - Fall 2012, Lab 01 11/3/2020 Using Web. Submit Boston University Slideshow Title Goes Here § http: //cs-websubmit. bu. edu/main. py? courseid=cs 112 § Submit all assignments via Web. Submit 3
CS 112 - Fall 2012, Lab 01 11/3/2020 Lab Sections and Office Hours Boston University Slideshow Title Goes Here § Attendence § Office Hours: § Tuesday. 5 -6: 30 p. m. § Wednesday. 3 -4: 30 p. m. § Tutoring Hour: § http: //www. bu. edu/cs/resources/tutoring/ 4
CS 112 - Fall 2012, Lab 01 11/3/2020 Stack and Function Boston University Slideshow Title Goes Here § Stack: Last In First Out (LIFO) § Function F 3 Call F 2 Return F 2 Call F 1 Return F 1 F 1 5
CS 112 - Fall 2012, Lab 01 11/3/2020 Recursive Function Boston University Slideshow Title Goes Here § Same function, Different variables Base Case F 1 F 1 Call F 1 F 1 Return F 1 F 1 6
CS 112 - Fall 2012, Lab 01 11/3/2020 Recursive Function Boston University Slideshow Title Goes Here § Base Case (what to do with trivial inputs) § Terminating Conditions § Most logical errors occur at ‘Base Case’ § Not only one base case, maybe many cases § Recursive Call (how to solve the problem) § Most difficult part to design a recursive function § Understand which variables are changing, and which are constant. 7
CS 112 - Fall 2012, Lab 01 11/3/2020 Practice Boston University Slideshow Title Goes Here § Implementing Exponentiation § Write a function to recursively compute the function f(x, n) = x^n § Compare your results with the built‐in java function Math. pow(x, n) § n is a non-negative integer 8
CS 112 - Fall 2012, Lab 01 11/3/2020 Practice Boston University Slideshow Title Goes Here § Consider f(x, n) = x^(n/2) * x^(n/2) § What do you need to do if n is odd? § Count number of recursive calls § Count time by using: System. nano. Time() 9
- Slides: 9