The implementation algorithm whose amortized complexity is O (1) to implement queue using two stacks is given as follows: Algorithm for Enqueue: Enqueue(element): //Push the element in the stack 1. S1.push(element) Algorithm for Dequeue: Dequeue(): //Check the condition that stack 2 is empty or not. //If it is empty then execute do part otherwise go //to the else part. if S2.isEmpty() then //Execute the while loop till the //size of stack 1 is greater than 1. while S1.size() > 1 do //Pop the element from stack 1 and // store it in the variable element. element = S1.pop() //And push the popped element // of stack 1 to the stack 2. S2.push(element) //Pop the element form stack 1 and //store it in the variable element. element = S1.pop() //Return the element. return element //The else part. else //Pop the element form stack 2 and //store it in the variable element. element = S2.pop() //Return the element. return element Where, S1 and S2 represent stack 1 and stack 2 respectively. Explanation: 1 + 1 + 1 + … + n Thus, for the dequeue operation the amortized complexity is O (1). Solution The implementation algorithm whose amortized complexity is O (1) to implement queue using two stacks is given as follows: Algorithm for Enqueue: Enqueue(element): //Push the element in the stack 1. S1.push(element) Algorithm for Dequeue: Dequeue(): //Check the condition that stack 2 is empty or not. //If it is empty then execute do part otherwise go //to the else part. if S2.isEmpty() then //Execute the while loop till the //size of stack 1 is greater than 1. while S1.size() > 1 do //Pop the element from stack 1 and // store it in the variable element. element = S1.pop() //And push the popped element // of stack 1 to the stack 2. S2.push(element) //Pop the element form stack 1 and //store it in the variable element. element = S1.pop() //Return the element. return element //The else part. else //Pop the element form stack 2 and //store it in the variable element. element = S2.pop() //Return the element. return element Where, S1 and S2 represent stack 1 and stack 2 respectively. Explanation: 1 + 1 + 1 + … + n Thus, for the dequeue operation the amortized complexity is O (1)..