Skip to main content
ICT
Lesson AB24 - Recursive Array Programming
 
Main Previous Next
Title Page >  
Summary >  
Lesson A1 >  
Lesson A2 >  
Lesson A3 >  
Lesson A4 >  
Lesson A5 >  
Lesson A6 >  
Lesson A7 >  
Lesson A8 >  
Lesson A9 >  
Lesson A10 >  
Lesson A11 >  
Lesson A12 >  
Lesson A13 >  
Lesson A14 >  
Lesson A15 >  
Lesson A16 >  
Lesson A17 >  
Lesson A18 >  
Lesson A19 >  
Lesson A20 >  
Lesson A21 >  
Lesson A22 >  
Lesson AB23 >  
Lesson AB24 >  
Lesson AB25 >  
Lesson AB26 >  
Lesson AB27 >  
Lesson AB28 >  
Lesson AB29 >  
Lesson AB30 >  
Lesson AB31 >  
Lesson AB32 >  
Lesson AB33 >  
Vocabulary >  
 

B. Developing the Recursive Solution page 4 of 7

  1. In developing a recursive solution, consider the base cases first. What situation(s) cause the recursive method to exit?

    1. We have arrived at a location that is off the data structure. It is important to catch this situation first to avoid an array indexing error.

    2. Encountering a '*' character means that we have run into a wall. The algorithm should stop.

    3. Encountering a location we have already visited should cause the algorithm to stop.

    4. Arriving at a location that has a row or column value equal to 1 or MAXROW or MAXCOL means that we have found an exit point.

  2. The general case of encountering a blank space requires the following steps:

    1. Change the character value from the blank space to the '!' character.

    2. Check to see if you are at an exit point. If so, print the maze with a trail of '!' markers to the exit point.

    3. If you are not at an exit point, make 4 recursive calls to check all 4 directions, feeding the new coordinates of the 4 neighboring cells.

  3. When an exit point is found, print only the successful trail of '!' marks that leads to an exit. As a result, it is necessary for each recursive call to work with a copy of the array. Why is this? If a reference to the original array is passed with each recursive call, the placement of '!' marks would be permanent in the data structure.

 

Main Previous Next
Contact
 © ICT 2006, All Rights Reserved.