1 / 9

CS 112 - Fall 2012 , Lab 01

CS 112 - Fall 2012 , Lab 01. Haohan Zhu. Using Piazza. http://www.piazza.com/bu/fall2012/cs112a1 Any question related to the course. Using WebSubmit. http://cs-websubmit.bu.edu/main.py?courseid=cs112 Submit all assignments via WebSubmit. Lab Sections and Office Hours. Attendence

Download Presentation

CS 112 - Fall 2012 , Lab 01

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS 112 - Fall 2012, Lab 01 Haohan Zhu

  2. CS 112 - Fall 2012, Lab 01 Using Piazza • http://www.piazza.com/bu/fall2012/cs112a1 • Any question related to the course

  3. CS 112 - Fall 2012, Lab 01 Using WebSubmit • http://cs-websubmit.bu.edu/main.py?courseid=cs112 • Submit all assignments via WebSubmit

  4. CS 112 - Fall 2012, Lab 01 Lab Sections and Office Hours • Attendence • Office Hours: • Tuesday. 5-6:30 p.m. • Wednesday. 3-4:30 p.m. • Tutoring Hour: • http://www.bu.edu/cs/resources/tutoring/

  5. CS 112 - Fall 2012, Lab 01 Stack and Function • Stack: Last In First Out (LIFO) • Function F3 F3 Call Return F2 F2 F2 F2 Call Return F1 F1 F1 F1 F1 F1

  6. CS 112 - Fall 2012, Lab 01 Recursive Function • Same function, Different variables Base Case F1 F1 Call Return F1 F1 F1 F1 Call Return F1 F1 F1 F1 F1 F1

  7. CS 112 - Fall 2012, Lab 01 Recursive Function • 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.

  8. CS 112 - Fall 2012, Lab 01 Practice • 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

  9. CS 112 - Fall 2012, Lab 01 Practice • 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.nanoTime()

More Related