# Thread: Understanding recursion

1. ## Understanding recursion

I was reading an article on how to convert decimal numbers to binary numbers and the author wrote two programs to solve this problem. In one of the programs he used a "reverse" function to reverse the array containing the binary number because the binary number was generated backwards. In the other program he used a recursive algorithm and there was no need for the reverse function. Why is that? Can someone explain what happens in this case? Thanks.

2. Sometimes a recursive function is easier to implement than an iterative one.

3. I'd like to know the details about the recursive function and why it generates the binary number correctly without the reverse function...

4. It probably calls itself over and over again until the end of the number, and then generates it in reverse . . . .

5. Best way to figure these sort of things out is to go through a few examples with a pencil and piece of paper. That'll quickly show you why one solution comes out reversed, and the other one not.

Popular pages Recent additions