From c581a59e95ab77c9ff19922b7f1a14e67b518d34 Mon Sep 17 00:00:00 2001 From: Anuj Rathour Date: Sun, 8 Oct 2023 10:21:22 +0530 Subject: [PATCH 1/5] updated-queue-readme.md-file --- .../datastructures/queues/README.md | 56 ++++++++++++++++--- 1 file changed, 49 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/thealgorithms/datastructures/queues/README.md b/src/main/java/com/thealgorithms/datastructures/queues/README.md index e110686acae9..d6d30dd8ca49 100644 --- a/src/main/java/com/thealgorithms/datastructures/queues/README.md +++ b/src/main/java/com/thealgorithms/datastructures/queues/README.md @@ -9,15 +9,57 @@ ## Declaration -`Queue queue = new PriorityQueue ();` +`Queue queue = new LinkedList ();` ## 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. + From 1365d1ab6b83779fd012762c91689a031561ed44 Mon Sep 17 00:00:00 2001 From: Anuj Rathour Date: Sun, 8 Oct 2023 14:59:59 +0530 Subject: [PATCH 2/5] updated-changes --- .../java/com/thealgorithms/datastructures/queues/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/thealgorithms/datastructures/queues/README.md b/src/main/java/com/thealgorithms/datastructures/queues/README.md index d6d30dd8ca49..f8bd7d9b40d9 100644 --- a/src/main/java/com/thealgorithms/datastructures/queues/README.md +++ b/src/main/java/com/thealgorithms/datastructures/queues/README.md @@ -9,7 +9,9 @@ ## Declaration -`Queue queue = new LinkedList ();` +`Queue queue = new PriorityQueue ();` + +`Queue queue = new LinkedList();` ## Important operations From cc8bae485f367f40001c9fc564319dde9990c15f Mon Sep 17 00:00:00 2001 From: Anuj Rathour Date: Sun, 8 Oct 2023 15:02:28 +0530 Subject: [PATCH 3/5] updated-changes --- .../java/com/thealgorithms/datastructures/queues/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/thealgorithms/datastructures/queues/README.md b/src/main/java/com/thealgorithms/datastructures/queues/README.md index f8bd7d9b40d9..520b322f7473 100644 --- a/src/main/java/com/thealgorithms/datastructures/queues/README.md +++ b/src/main/java/com/thealgorithms/datastructures/queues/README.md @@ -8,9 +8,10 @@ - LinkedList, ArrayBlockingQueue and PriorityQueue are the most commonly used implementations. ## Declaration - + //queue implementation using PriorityQueue `Queue queue = new PriorityQueue ();` + //queue implementation using LinkedList `Queue queue = new LinkedList();` ## Important operations From 178c8c472c6cef9bf6c3d35a3807493989f91c6f Mon Sep 17 00:00:00 2001 From: Anuj Rathour Date: Mon, 9 Oct 2023 12:26:17 +0530 Subject: [PATCH 4/5] updated changes --- .../java/com/thealgorithms/datastructures/queues/README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/com/thealgorithms/datastructures/queues/README.md b/src/main/java/com/thealgorithms/datastructures/queues/README.md index 520b322f7473..cc81951a7b6e 100644 --- a/src/main/java/com/thealgorithms/datastructures/queues/README.md +++ b/src/main/java/com/thealgorithms/datastructures/queues/README.md @@ -11,9 +11,6 @@ //queue implementation using PriorityQueue `Queue queue = new PriorityQueue ();` - //queue implementation using LinkedList -`Queue queue = new LinkedList();` - ## Important operations | Operations | Description |Time Complexity From 9f6f52ef47a69555a9c2c34fbe23ea687c11b512 Mon Sep 17 00:00:00 2001 From: Andrii Siriak Date: Mon, 9 Oct 2023 18:29:19 +0300 Subject: [PATCH 5/5] Update src/main/java/com/thealgorithms/datastructures/queues/README.md --- .../java/com/thealgorithms/datastructures/queues/README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/com/thealgorithms/datastructures/queues/README.md b/src/main/java/com/thealgorithms/datastructures/queues/README.md index cc81951a7b6e..0d9a39f2daa0 100644 --- a/src/main/java/com/thealgorithms/datastructures/queues/README.md +++ b/src/main/java/com/thealgorithms/datastructures/queues/README.md @@ -8,8 +8,7 @@ - LinkedList, ArrayBlockingQueue and PriorityQueue are the most commonly used implementations. ## Declaration - //queue implementation using PriorityQueue -`Queue queue = new PriorityQueue ();` +`Queue queue = new PriorityQueue();` ## Important operations