public void reverse(Stack st)
{
int m = (int)st.Pop();
if (st.Count != 1)
reverse(st);
Push(st , m);
}
public void Push(Stack st , int a)
{
int m = (int)st.Pop();
if (st.Count != 0)
Push(st , a);
else
st.Push(a);
st.Push(m);
}
Sure, recursion can always be substituted with using a stack.
yes
Yes. It is possible to provide a solution to the diamond-square algorithm using Java and recursion.
Read the part in your programming manual/text book about recursion. The short answer while easy does not tell you anything about the power or dangers of recursion. It is the power and dangers of recursion that is important because once understood you can use recursion to good effect without running out of stack space.
yes,cursor implementation possible in priority queue.
Sure, recursion can always be substituted with using a stack.
yes
Yes. It is possible to provide a solution to the diamond-square algorithm using Java and recursion.
stack abstract datatype
Read the part in your programming manual/text book about recursion. The short answer while easy does not tell you anything about the power or dangers of recursion. It is the power and dangers of recursion that is important because once understood you can use recursion to good effect without running out of stack space.
Tail recursion is a special type of recursion where the recursive call is the last operation in the function. This allows for optimization by reusing the same stack frame for each recursive call, leading to better efficiency and performance. In contrast, regular recursion may require storing multiple stack frames, which can lead to higher memory usage and potentially slower execution.
Stack is not a way to perform quicksort, it is a tool used to implement recursion.
Read the part in your programming manual/text book about recursion. The short answer while easy does not tell you anything about the power or dangers of recursion. It is the power and dangers of recursion that is important because once understood you can use recursion to good effect without running out of stack space.
To implement a queue using stacks efficiently, you can use two stacks. One stack is used for enqueueing elements, and the other stack is used for dequeueing elements. When dequeueing, if the dequeue stack is empty, you can transfer elements from the enqueue stack to the dequeue stack to maintain the order of elements. This approach allows for efficient implementation of a queue using stacks.
Heap is a data-structure, it cannot implement anything. On the other hand, it is true that: 1. Recursive routines might use heap. 2. You can use dynamic memory allocation (heap), to implement a stack; and use the stack to implement recursion.
yes,cursor implementation possible in priority queue.
You overcome limitations of the stack in polygon filling, or in any other algorithm, far that matter, but using an iterative technique, rather than a recursive technique. Recursion is quite useful, and can simplify algorithm design. Polygon filling, however, is a class of algorithm can potentially have a very deep recursion depth. This causes stress on the stack, hence the need for iteration.