Skip to content

updated-queue-readme.md-file #4721

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 49 additions & 8 deletions src/main/java/com/thealgorithms/datastructures/queues/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,58 @@
- **Delay Queue:** Used for scheduling tasks to run after a specific delay or at a certain time. Elements are removed from the queue when their delay expires.

## Declaration

`Queue<Obj> queue = new PriorityQueue<Obj> ();`
`Queue<Obj> queue = new PriorityQueue<Obj>();`

## Important operations

| Operations | Description |
| ----------- | ----------- |
|Enqueue|Adds an item to the queue|
|Dequeue|Removes an item from the queue|
|Front|Gets the front item from the queue|
|Rear|Gets the last item from the queue|
| Operations | Description |Time Complexity
| ----------- | ----------- |-----------
|Enqueue|Adds an item to the queue|O(1)
|Dequeue|Removes an item from the queue|O(1)
|Front|Gets the front item from the queue|O(1)
|Rear|Gets the last item from the queue|O(n)

## Enqueue
It adds an item to the rear of the queue.

For example: If we have `1, 2, 3, 4, 5` in queue, and if we call Enqueue(8),

`8` will be added to last index of queue -> `1, 2, 3, 4, 5, 8`.
## Dequeue

It removes an item to the front of the queue.

For example: If we have `1, 2, 3, 4, 5` in queue, and we call Dequeue(),

`1` will be removed from front of queue and returned -> `2, 3, 4, 5`.

## Front
It returns an item to the front of the queue.

For example: If we have `1, 2, 3, 5` in queue, and we call Front(),

`1` will be returned (without removing it from the queue).

## Rear
It returns an item to the rear of the queue.

For example: If we have `1, 2, 3, 5` in queue, and we call Rear(),

`5` will be returned (without removing it from the queue).

# Real Life Applications
`Task Scheduling in Operating Systems:`

Processes in a multitasking system are often scheduled using queues. For example, the ready queue contains processes ready to be executed.

`Multi-threaded Programming:`

Queues are often used to facilitate communication and synchronization between different threads.

`Breadth-First Search (BFS) in Graphs:`

Queues are used in algorithms like BFS to explore a graph level by level.




Expand Down