DEV Community

Discussion on: Queue Data Structure in Go

Collapse
 
kubistmi profile image
kubistmi

Dear Bharath!

While the presented approach is nice and simple, I think it, unfortunately, contains a memory leak (see this discussion for more details).

Since the slice still refers to the same array (even after dequeuing / reslicing), the whole thing can't be released. Therefore the space complexity is not just N = size of the queue, but it has to include all the items that were dequeued before as well.

The only efficient solution I was able to find (when trying to use the queue for one of my own packages) is to implement it using a doubly linked list, which is arguably a more advanced structure. Your queue implementation should be OK most of the time unless someone wants to push lots of items through it.

Apart from that, your explanation of the queue is very nicely done and I especially liked the visuals and animations!

Cheers,
Michal

Collapse
 
bapillai profile image
Bharath Uday

Thanks Michal.
This is truly helpful.I will definitely look into this and put up a fix soon!Please watch out the space and provide us with more feedback.We are always look at ways to improve our posts.