top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Give a good data structure for having n queues.

+4 votes
503 views

Give a good data structure for having n queues (n not fixed) in a finite memory segment. You can
have some data-structure separate for each queue. Try to use at least 90% of the memory space.

posted Nov 4, 2013 by Anuj Yadav

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+3 votes

For this we can design queue of queues using linked list.

We can use multiple no of linked list for designing this.

Link 1 ---- Link 2 ---- Link 3 .....(As for no of queue increasing ......till n ...)
| ----------------- | ----------- |
Link a -------- Link a ----- Link a
Link b -------- Link b ----- Link b
Link c --- -------------- --- - Link c
Link d
Link e

So dynamically when a new queue is created u can add to the queue to the upper linked list (Link1 .. Link2)
and if you want to inser any item in to the particular queue then also u can also add elements (Link a, lInk b ) to the respective queue.

Hope it help...Here it is unable to draw But picture i can make it better expressible.

answer Nov 5, 2013 by Sachidananda Sahu
I like answer for Sachidananda. Also thought of an alternate

We can use Hashtable and override hash function to select which queue it will go in :)
Similar Questions
+1 vote

While reading possible time complexity i found that time complexity O(log log n) exist for some algos,

Can any one explain an example which shows the calculation of the time complexity with O(log log n)

+4 votes

Calculate 1+2+…+n without multiplication, division, key words for, while, if, else, switch, case, as well as conditional operator (A ? B : C).

+7 votes

Given two n-node trees, how many rotations does it take to convert one tree into the other?

...