Skip to content

Commit 026351f

Browse files
authored
Merge pull request #42 from yeoshuheng/queueCleanUp
Queue clean up
2 parents a12e098 + de1119a commit 026351f

File tree

6 files changed

+54
-38
lines changed

6 files changed

+54
-38
lines changed

.idea/workspace.xml

Lines changed: 19 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
File renamed without changes.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Double Ended Queue (Deque)
2+
3+
![Deque](https://media.geeksforgeeks.org/wp-content/uploads/anod.png)
4+
5+
*Source: GeeksForGeeks*
6+
7+
Deque is a variant of queue where elements can be removed or added from the head and tail of the queue.
8+
Deque could come in handy when trying to solve sliding window problems. This means it neither follows a fixed FIFO
9+
or LIFO order but rather can utilise either orders flexibly.
10+
11+
A deque can be implemented in multiple ways, using doubly linked lists, arrays or two stacks.
12+
13+
## Analysis
14+
Much like a queue, deque operations involves the head / tail, resulting in *O(1)* complexity for most operations.
15+
16+
## Notes
17+
Just like a queue, a monotonic deque could also be created to solve more specific sliding window problems.
18+
19+

src/main/java/dataStructures/queue/README.md

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ A [stack](../stack/README.md) is a queue with operations conducted in an opposit
1818

1919
As a queue only interacts with either the first or last element regardless during its operations,
2020
it only needs to keep the pointers of the two element at hand, which is constantly updated as more
21-
elements are removed / added. This allows stack operations to only incur a *O(1)* time complexity.
21+
elements are removed / added. This allows queue operations to only incur a *O(1)* time complexity.
2222

2323
## Notes
2424

@@ -38,31 +38,3 @@ In the context of ordered operations, the lookup is only restricted to the first
3838
Hence, there is not much advantage in using a array, which only has a better lookup speed (*O(1)* time complexity)
3939
to implement a queue. Especially when using a linked list to construct your queue
4040
would allow you to grow or shrink the queue as you wish.
41-
42-
### Queue Variants
43-
44-
These are some variants of queue that are commonly used.
45-
46-
#### Double Ended Queue (Deque)
47-
48-
![Deque](https://media.geeksforgeeks.org/wp-content/uploads/anod.png)
49-
50-
*Source: GeeksForGeeks*
51-
52-
Deque is a variant of queue where elements can be removed or added from the head and tail of the queue.
53-
Deque could come in handy when trying to solve sliding window problems.
54-
55-
A deque can be implemented in multiple ways, using doubly linked lists, arrays or two stacks.
56-
57-
#### Monotonic Queue
58-
59-
This is a variant of queue where elements within the queue are either strictly increasing or decreasing.
60-
Monotonic queues are often implemented with a deque.
61-
62-
Within a increasing monotonic queue, any element that is smaller than the current minimum is removed.
63-
Within a decreasing monotonic queue, any element that is larger than the current maximum is removed.
64-
65-
It is worth mentioning that the most elements added to the monotonic queue would always be in a
66-
increasing / decreasing order,
67-
hence, we only need to compare down the monotonic queue from the back when adding new elements.
68-
File renamed without changes.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Monotonic Queue
2+
3+
This is a variant of queue where elements within the queue are either strictly increasing or decreasing.
4+
Monotonic queues are often implemented with a deque.
5+
6+
Within a increasing monotonic queue, any element that is smaller than the current minimum is removed.
7+
Within a decreasing monotonic queue, any element that is larger than the current maximum is removed.
8+
9+
It is worth mentioning that the most elements added to the monotonic queue would always be in a
10+
increasing / decreasing order,
11+
hence, we only need to compare down the monotonic queue from the back when adding new elements.
12+
13+
## Operation Orders
14+
Just like a queue, a monotonic queue mainly has *O(1)* operations,
15+
which is unique given that it ensures a certain order, which usually incurs operations of a higher complexity.

0 commit comments

Comments
 (0)