
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.

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

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

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

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.