loop-recursive-program

loop-recursive-program - What happen then Using Recursive...

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

View Full Document Right Arrow Icon
A Short Guide of Loop and Recursive Programming IS 620
Background image of page 1

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

View Full DocumentRight Arrow Icon
Example of Hw 6 Find someone’s manager and higher level managers (i.e., manager’s managers). Jeff Alic e Bob Eric
Background image of page 2
Using Recursive Programming To solve a complex problem, we can first solve one step of the problem, and then the remaining steps can be represented as a similar but smaller problem We can use the same program to solve the smaller problem (recursive) Jeff Alic e Bob Eric E.g., Print_Manager_Recursive(‘Jeff’) will print out Jeff’s manager and higher level managers We just need to print out Jeff’s manager Alice, and Alice’s manager and higher level mangers. i.e., first print out Jeff’s manager by calling get_manager(‘jeff’) Then call Print_Manager_Recursive(‘Alice’)
Background image of page 3

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

View Full DocumentRight Arrow Icon
Using Recursive Programming The recursion continues automatically Jeff Alic e Bob Eric Similarly, Print_manager_recursive(‘Alice’) will call Get_manager(‘Bob’) And Print_manager_recursive(‘Bob’) Next, Print_manager_recursive(‘Bob’) will call Get_manager(‘Eric’) and Print_manager_recursive(‘Eric’)
Background image of page 4
Background image of page 5

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

View Full DocumentRight Arrow Icon
Background image of page 6
Background image of page 7

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

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

Unformatted text preview: What happen then? Using Recursive Programming • Finally need to check stop condition Jeff Alic e Bob Eric Print_manager_recursive(‘Eric’) Get_manager(‘Eric’) will return null So we stop Standard Format of Recursive Programming create or replace procedure print_managers_recursive(ename varchar) is v manages.employee_name%type; begin v := get_manager(ename);-- one step further if v is not null then -- check for stop condition Converting Recursive Programs into Loops • Some times a recursive program can be converted into loops • The loop repeatedly makes progress to solve the problem. • The loop also checks for stop condition • Usually we also need to update loop variable, which is similar to update input parameter for recursive program Standard Format of Recursive Programming create or replace procedure print_managers_recu rsive(ename varchar) is v manages.employee_ name%type; begin create or replace procedure print_managers_re cursive(ename varchar) is v1 manages.employee _name%type; v2...
View Full Document

This note was uploaded on 02/28/2012 for the course IS 620 taught by Professor Chen,z during the Spring '08 term at UMBC.

Page1 / 8

loop-recursive-program - What happen then Using Recursive...

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

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