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

  • Home
  • SEARCH
  • 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 7545163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:51:27+00:00 2026-05-30T08:51:27+00:00

I have two queues, one is implemented using an array for storage and the

  • 0

I have two queues, one is implemented using an array for storage and the other is implemented using a linked list.

I believe that the complexity of the enqueue and dequeue operations looks like this –

LinkedListQueue Enqueue – O(1)

LinkedListQueue Dequeue- O(1)

ArrayQueueEnqueue – O(1)

ArrayQueue Dequeue – O(n)

So I tested both queues by adding and removing strings from them. Here are the results I got, time taken is in milliseconds –

enter image description here

Does my Big Oh complexity analysis stack up with these results? The complexity of LLQueue Enqueue I have is O(1) but as you can see it ranges from 2ms for 1000 strings to 79ms for 100000 strings. Is that expected?

And I have ArrayQueue Dequeue marked down as O(n), do those results look like O(n)? There is a huge jump between 20000 and 50000 strings, but it only doubles in time when dequeuing 100000 strings instead of 50000. That seems a bit odd…

  • 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-30T08:51:29+00:00Added an answer on May 30, 2026 at 8:51 am

    First, I am surprised that your Dequeue operation on ArrayQueue is so expensive. Are you shifting the entire queue contents on each dequeue? There is a much better approach – look up “circular queue” online.

    Now, onto the measurements. The big-Oh complexity only tells a part of the story. When you start measuring the running times, you will see a variety of complex effects, such as the following:

    Caches

    It seems like your test enqueues a bunch of elements into a queue and then dequeues them. If the entire queue fits into an L1 cache on your processor, all memory operations will be fast.

    If the size of the queue exceeds the L1 cache, then data will need to spill into L2 cache, which results in maybe a 2-3x slowdown. If the size of the queue exceeds the L2 cache, the data will have to go into the main memory and you’ll get another big drop in performance – say 5x.

    Garbage collection

    From the naming of your types, I would guess that you are using a language with garbage collection, like Java or C#. If that’s the case, then that implies that your program can pause at any time (not quite “any time”, but that’s not important now) and spend some time cleaning up memory.

    Other effects

    I would guess that the two effects I mentioned above are the ones you’d be most likely to run into in a scenario like yours, but there are many other complex behaviors in the compiler, the VM, the OS, and the hardware that make it hard to interpret performance measurements.

    It can be a great learning experience – and also fun – trying to figure out why exactly your performance measurements came out a certain way, but it certainly not trivial.

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

Sidebar

Related Questions

I have two applications written in Java that communicate with each other using XML
Suppose we have a shared queue (implemented using an array), which two threads can
I have two threads, one thread processes a queue and the other thread adds
I have two threads, one that dispatches messages and another that parses them. Simple,
I have two identical servers. Both Win2k3. I have a web service that queues
I've got a JMS messaging system implemented with two queues. One is used as
I'm getting an weird error using queues/multiprocessing. I basically have a function that takes
I have two arrays of animals (for example). $array = array( array( 'id' =>
I have two classes, and want to include a static instance of one class
I have two threads, one needs to poll a bunch of separate static resources

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.