Amazingly, the algorithm for a breadth-first search is identical to the algorithm for a depth-first search, with the frontier changed from a stack to a queue. (link)
The depth-first search algorithm relies on a data structure known as a stack. (link)
We could break the recursive case into three steps:
Move the upper n-1 discs from tower A to B (the temporary tower), using C as the step in between.
Move the single lowest disc from A to C.
Move the n-1 discs from tower B to C, using A as the step in between. (link)
If the bits of two numbers are combined using XOR, a helpful property is that the product can be recombined with either of the operands to produce the other operand: C = A ^ B A = C ^ B B = C ^ A (link)
Vikram: [1, 0 => 1. So 0, 0 => 1 and 1,1=>0 lly 0,1 => 1 0,0 => 0. Cleary 0,0 => 0 and 0,0 =>0 1,1=>0. So 0,1 => 1
]
The two bits are composed together in the variable lastBits. lastBits is made by shifting the first bit back one place, and then ORing (| operator) the result with the second bit. When a value is shifted, using the << operator, the space left behind is replaced with 0s. An OR says, “If either of these bits are a 1, put a 1.” Therefor ORing secondBit with a 0 will always just result in the value of secondBit. L (link)
Memoization is a technique in which you store the results of computational tasks when they are completed so that when you need them again, you can look them up instead of needing to compute them a second (or millionth) time (see figure 1.4). (link)
The reason for the infinite recursion is that we never specified a base case. In a recursive function, a base case serves as a stopping point. (link)