Lec7 - Click to edit Master subtitle style Sundar B Recursion and Iteration Function calls and Call Stack Modularity vs Efficiency Tail Calls and

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Click to edit Master subtitle style 2/7/11 Sundar B. Recursion and Iteration Function calls and Call Stack- Modularity vs. Efficiency Tail Calls and Tail Call Elimination- Tail Recursion Divide-and-Conquer- Recursive vs. Iterative Implementations 11 2/7/11 Sundar B. 2/7/11 Sundar B. Space Complexity and Time Complexity Relation between the time taken by a program to run and the space used by it is not simple. Each program is allocated Virtual Memory space (i.e. set of logical addresses) These addresses are partially stored in RAM (primary memory) and partially stored in disk (secondary memory) Typical ratio of raw access times: 100ns for RAM to 10ms for disk (i.e. 1 / 105) In an OS with efficient buffering, I/O scheduling, and disk cache typical ratio of access times can be made 1 / 103 2/7/11 22 Sundar B. 2/7/11 Sundar B. Modularity vs. Efficiency We structure our program into procedures (or functions) to make it modular: and modularity brings in ease of maintenance and reuse. Once a procedure is defined it can be used – i.e. called – as many times as needed and its implementation can be changed without affecting its use On the other hand, each procedure call has an implementation overhead 2/7/11 33 Sundar B. 2/7/11 Sundar B. Procedure calls and call stack 2/7/11 44 Sundar B. Consider the following program: int PI = 3; int a(int n) { return PI*n*n; } int t(int n) { return a(n) + a(2*n); } void main() { int x = t(5); print(x); return 1; } Order of Call / Return: ---> main ---> t ---> a1 <------> a2 <--- <--- <--- Returns are reverse order of calls – LIFO order 2/7/11 Sundar B....
View Full Document

This note was uploaded on 02/07/2011 for the course CS 123 taught by Professor Murali during the Spring '11 term at Birla Institute of Technology & Science, Pilani - Hyderabad.

Page1 / 15

Lec7 - Click to edit Master subtitle style Sundar B Recursion and Iteration Function calls and Call Stack Modularity vs Efficiency Tail Calls and

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online