Class Notes (839,242)
Canada (511,223)
CMPT 225 (60)
John Edgar (28)
Lecture 4

CMPT 225 Week 4 Lecture 1

2 Pages
67 Views

Department
Computing Science
Course Code
CMPT 225
Professor
John Edgar

This preview shows 80% of the first page. Sign up to view the full 2 pages of the document.
Description
Tail recursion - recursive call is last statement of algorithm - also passing along result so far (essentially), final result of recursive call is final result of the function - just says return the result of calling the factorial function - no multiplying it by anything, for example - build up answer as you go down through recursive calls, rather than up - easy to convert to iterative functions. In fact, even done automatically by some compilers. Recursion can still be used as a problem solving technique even if you don't implement with recursion in the end. Recursion trees can be used to trace through recursive calls. Recursion similar to induction Recursion solves problem; induction proves property Can use induction to prove your recursive solution before you implement it. Linked Lists are recursive data structures - defined in terms of themselves Can traverse lists recursively Short circuit evaluation Useful for reference structures if (front == NULL || s < front->data) { ... } If the first is true, don't bother making the second comparison (because OR is already true) Helpful because if it checked that second statement, we would get an error Can also do with AND, if first is false it won't bother checking second Finding the right insertion point: while (p->next != NULL && p->next->data < s) { p = p->next } Need to look forward, or we'd get ahead of ourselves. There is no way for us to go backwards, so we can't insert in the right position. Once you've got the Node you want to do something with, you've gone too far. (especiall
More Less
Unlock Document

Only 80% of the first page are available for preview. Some parts have been intentionally blurred.

Unlock Document
You're Reading a Preview

Unlock to view full version

Unlock Document

Log In


OR

Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


OR

By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.


Submit