WEBVTT 00:00:00.569 --> 00:00:06.308 Ã¯Â»Â¿Student W.Q. Feng asked when do you use a recursive definition versus a 'while' loop? 00:00:06.308 --> 00:00:12.211 So this is a good question and in terms of being able to solve a problem, 00:00:12.211 --> 00:00:15.954 anything you can do with recursion you can also do with a 'while' loop. 00:00:15.954 --> 00:00:18.299 Anything you can do with a 'while' loop you could also do with recursion. 00:00:18.299 --> 00:00:20.476 So any problem you can solve either way. 00:00:20.476 --> 00:00:23.668 Usually solving it with a 'while' loop would be more efficient 00:00:23.668 --> 00:00:26.676 because you donÃ¢ÂÂt have the overhead of all the extra procedure calls. 00:00:26.676 --> 00:00:30.456 Often solving it with recursion is a simpler and more elegant solution. 00:00:30.456 --> 00:00:34.757 So depending on whatÃ¢ÂÂs more important, oftentimes the tradeoff 00:00:34.757 --> 00:00:38.127 is much better where the simpler elegant solution 00:00:38.127 --> 00:00:41.049 that performance difference you probably couldnÃ¢ÂÂt even measure 00:00:41.049 --> 00:00:43.778 unless you were timing really carefully for really large inputs, 00:00:43.778 --> 00:00:45.247 you wouldnÃ¢ÂÂt notice the difference. 00:00:45.247 --> 00:00:48.115 So itÃ¢ÂÂs more important to get the solution correct and have it 00:00:48.115 --> 00:00:51.329 in code thatÃ¢ÂÂs easier for you to write and easier for other people to understand, 00:00:51.329 --> 00:00:54.350 in many problems the recursive solution 00:00:54.350 --> 00:00:57.859 really lends itself to that. ItÃ¢ÂÂs much shorter than the iterative solution would be 00:00:57.859 --> 00:01:00.190 and itÃ¢ÂÂs easier to understand and follow. 00:01:00.190 --> 00:01:04.331 In places where performance matters and we saw this with the Fibonacci example 00:01:04.331 --> 00:01:07.503 that if you end up blowing up the number of calls in a way 00:01:07.503 --> 00:01:09.595 that makes it too slow to do recursively, 00:01:09.595 --> 00:01:13.368 you might prefer a more complicated solution that involves a 'while' loop and avoids the recursive calls.