Implement Very Large Queue

Suppose you have a very large queue, and you need to do a insert and delete on the queue. Since the queue is very large , you cannot keep the entire queue in the memory. How do you go about implementing such a condition?
How do you go about inserting and deleting elements from that queue if you cannot keep the queue in the memory?

Questions by jimmy514in   answers by jimmy514in

Showing Answers 1 - 1 of 1 Answers

Problems with large Queue :

1) Space.
2) Inserting and deleting.
3) Time to perform operations.
4) Additional cost.

There are few ways to implement very large queues:

1)Using flat-files:
A "flat file" is a plain text or mixed text which usually contains one record per line. Within such a record, the single fields can be separated by delimiters, e.g. commas, or have a fixed length. In the latter case, padding may be needed to achieve this length. Extra formatting may be needed to avoid any collisions. There are no structural relationships between the records.


[current position]<-- here is no new line
[data No.1 length][data    1 in serialized format]<-- here is no new line
[data No.2 length][data    2 in serialized format]
[data No.3 length][data    3 in serialized format]
[data No.N length][data   N in serialized format]

Now, If u want to insert an element(data). 
use push( ) and insert that element into the flat-file.
If you want to pop an element, Use pop( ) by getting the pointer on that particular element that you want to remove and then pop out the element and after that increment [current position] with [data x length].

In case of databases:
[id][element data columns]
When you want to push(), you append the data to the database and when you want to remove an item, do pop() and use query element by it's id at current_item++ in order to move it out and increment the pointer to point at the next current item at the pointer's location.

Or else, You can even buy a server that suits your needs and perform the action.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.


Related Answered Questions


Related Open Questions