Skip to main content

All Questions

Tagged with
1 vote
2 answers
1k views

Calling recursive method in a loop - Backtracking

I'm confused about a matter that I've been unable to figure out. I'm doing some leetcode problems. In backtracking problems, sometimes we use loop within our recursive method to call the recursion but ...
Umer Farooq's user avatar
0 votes
5 answers
498 views

How to deail with a hypothetical situation in which a pub/sub cycle gets into an unending recursive loop?

Let me explain what I mean. Imagine A subs to event b. In such case A pubs event a. B subs to event a. In this case B subs b. This is a full-blown circle. How does a pub/sub cycle deal with such ...
Aurlito's user avatar
  • 27
-1 votes
1 answer
1k views

What happens when loops are compiled or interpreted?

I have came across a concept in recursion which says that when loops are compiled or interpreted then they get converted to recursive functions. If it is true how it takes place ?
Ashwani Sharma's user avatar
2 votes
2 answers
3k views

Efficiency considerations: nested loop vs recursion

I would consider myself an intermediate Python programmer. One of my recent challenges was creating a list of all possible solutions to a given Countdown problem. Without getting into too much detail,...
IliaK's user avatar
  • 23
46 votes
11 answers
31k views

Is a while loop intrinsically a recursion?

I wondered whether a while loop is intrinsically a recursion? I think it is because a while loop can be seen as a function that calls itself at the end. If it is not recursion, then what is the ...
badbye's user avatar
  • 585
-2 votes
1 answer
277 views

For loop and recursion for a new shell in C [closed]

I code a new shell in C, that could be done in several ways: Flex/bison, finite state machine, abstract syntax tree or just a tokenizer in C. Now I've written a for-loop that changes the condition of ...
Niklas Rosencrantz's user avatar
130 votes
11 answers
38k views

Is there anything that can be done with recursion that can't be done with loops?

There are times where using recursion is better than using a loop, and times where using a loop is better than using recursion. Choosing the "right" one can save resources and/or result in fewer lines ...
Pikamander2's user avatar
  • 1,269
0 votes
1 answer
147 views

Recursion, iteration, and ...? [closed]

Here are three common code structures that apply a function multiple times: foo(x) { if basecase(x) return k else return foo(g(x)) } uses recursion. for i in 0..10 { n *= bar(i) } uses ...
Alex Celeste's user avatar
39 votes
2 answers
84k views

General way to convert a loop (while/for) to recursion or from a recursion to a loop?

This problem is mainly focusing on the algorithm, maybe something abstract and more academic. The example is offering a thought, I wanna a generic way, so example is only used as to make us more ...
xqMogvKW's user avatar
  • 543