Hello Turtlers, One of the most difficult topics in CS is the idea of recursion. Teachers spend a considerable amount of effort to make it clear for students. Harvey devoted in his CSLS many pages and different approaches and metaphors for explaining recursion. In addition, I use the following tiny program, to visualize on the screen how recursion works. The key is the use of colors. Each color reptesents its level of depth: blue denotes depth 1, green denotes level 2 etc., according to the single-index colors used in UCBLogo. To run the program in MSWLogo say, e.g., DRAW 60 5; the first number is the size, the second number is the maximal depth. ======================== to draw :size :level if :level<1[stop] repeat 3[pattern rt 120] end to pattern setucbpc :level ; (1) bk :size fd :size pu fd :size pd ; (2) draw :size/2 :level-1 pu bk :size pd end ======================== Remarks: (1) For UCBLogo replace SETUCBPC by SETPC. (2) To visualize step-by-step how the image is built up, replace this remark by ERN RC. Now, after each stage, Logo stops and waits for the next key press. Watch carefully to see what goes "behind the curtains". You can also TRACE the program. Enjoy it, [[Yehuda]]
Global SchoolNet Foundation -
Linking Kids Around the World!
Copyright GSN - All Rights Reserved
- Comments
& Questions
Visit GSN's
Global
Schoolhouse for more exciting learning resources!
Search our Site
-
Home