in generalthoughonce you get the hang of recursive callsthey are more natural than the explicit scheduling lists they automateand are generally preferred unless you need to traverse structure in specialized ways some programsfor exampleperform bestfirst search that requires an explicit search queue ordered by relevance or other criteria if you think of web crawler that scores pages visited by contentthe applications may start to become clearer cyclespathsand stack limits as isthese programs suffice for our examplebut larger recursive applications can sometimes require bit more infrastructure than shown herethey may need to avoid cycles or repeatsrecord paths taken for later useand expand stack space when using recursive calls instead of explicit queues or stacks for instanceneither the recursive call nor the explicit queue/stack examples in this section do anything about avoiding cycles--visiting location already visited that' not required herebecause we're traversing strictly hierarchical list object trees if data can be cyclic graphthoughboth these schemes will failthe recursive call version will fall into an infinite recursive loop (and may run out of call-stack space)and the others will fall into simple infinite loopsre-adding the same items to their lists (and may or may not run out of general memorysome programs also need to avoid repeated processing for state reached more than onceeven if that wouldn' lead to loop to do betterthe recursive call version could simply keep and pass setdictionaryor list of states visited so far and check for repeats as it goes we will use this scheme in later recursive examples in this bookif state not in visitedvisited add(stateproceed add(state) [state]=trueor append(statethe nonrecursive alternatives could similarly avoid adding states already visited with code like the following note that checking for duplicates already on the items list would avoid scheduling state twicebut would not prevent revisiting state traversed earlier and hence removed from that listvisited add(frontproceed items extend([ for in front if not in visited]this model doesn' quite apply to this section' use case that simply adds numbers in listsbut larger applications will be able to identify repeated states-- url of previ advanced function topics