Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6564097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:55:28+00:00 2026-05-25T13:55:28+00:00

Possible Duplicate: Why use two stacks to make a queue? I got this assignment

  • 0

Possible Duplicate:
Why use two stacks to make a queue?

I got this assignment question that asks me to implement a queue using two stacks. My question is not how to do it but why to do it? I am not from computer background and I tried to find the answer for this, but couldn’t really find why to do it? I think you experts can help me understand what are advantages of implementing such a thing. I found a related article Why use two stacks to make a queue? talking about this, but want to know if there is anything more.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T13:55:29+00:00Added an answer on May 25, 2026 at 1:55 pm

    There are a few very good reasons to do this.

    First, some functional programming languages like Haskell, ML, or Lisp support lists as a built-in type. Lists typically are represented as singly, forward-linked lists, which means that they support O(1) prepend but O(n) concatenate. In languages like this, it’s extremely easy to make a stack – you just prepend to a list to push and drop the first element to pop. Because of the internal implementation, this runs in O(1) time. If you tried to make a queue using this sort of list, enqueue would take O(n) time because you’d have to add to the end of a singly-linked list that doesn’t store a pointer to the last element. On the other hand, if you implement the queue using two stacks (or more; the Hood-Melville queue uses six!), then you can get amortized O(1) enqueue and dequeue even if you only have stacks in your language. Although more advanced data structures have been devised to support purely functional queues and lists (such as the 2-3 finger tree), the two-stack construction is still quite useful in many applications.

    In addition to this, in some cases you may want to use special stacks to implement the queue to get extra functionality out. For example, you can augment a stack data structure to support O(1) find-min/find-max. If you have a stack like this, you can then use the two-stack construction to make a queue that also has O(1) find-min/find-max. Trying to solve this problem directly is much harder (check out my considerably more complex construction to make a queue with these properties!)

    Finally, it is interesting from a theoretical perspective to know that a queue can be simulated with two stacks. In computability theory, a two-stack pushdown automaton is a theoretical computing device with power equivalent to a Turing machine. A queue automaton is a similar structure that uses a queue instead of two stacks. Because we know that you can simulate a queue with two stacks, you can immediately prove that the queue automaton is at least as powerful as a Turing machine, and thus that queue automata are Turing-complete.

    Hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Use SVN Revision to label build in CCNET I'm working through the
Possible Duplicate: Why not use tables for layout in HTML? Under what conditions should
Possible Duplicate: When to use “strictfp” keyword in java? What is the use of
Possible Duplicate: Internationalization in SSRS We use SQL Server Reporting Services for our web
Possible Duplicate: How can I use a carriage return in a HTML tooltip? I'd
Possible Duplicate: Escape string for use in Javascript regex I have a msg like
Possible Duplicate: When should you use 'friend' in C++? I was brushing up on
Possible Duplicate: How do I calculate someone's age in C#? Maybe this could be
Possible Duplicate: .NET - What’s the best way to implement a catch all exceptions
Possible Duplicate: NAnt or MSBuild, which one to choose and when? What is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.