Dequeing operation

In this appraoch we are just moving the front pointer one step ahead, but the size of arr remains same, and that element to be removed is still at place
Doesnt this leads to more space requirement as we are not really deleting the element

No this does not lead to more space requirement because the value you have left now does not have a reference and is essentially a garbage value. It can so easily be overwritten by the next operation at the same memory location.

Memory conflict only occurs when two active references compete for a single memory location. However if one of the references is dead/deleted (as we moved the front pointer forward in this case), the next reference can overwrite it.

Apart from this Java also runs its garbage collector periodically that take these dangling pointers and reset them.

But when front pointer moves ahead the name of the arr is still pointing towards the first pointer only , I mean that size of array still remains the same right even after we dequeue so there is no decrease in size?

No decrease in size is correct if you look at it via an array.
However if you see it as an queue you are only allowed to traverse from the front to the rear, so eeven though the array size has not decreased, the range which you can access has

1 Like