You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In #algorithms-curriculum channel in[Operation Code Slack](https://operationcode.org), we will solve and discuss one exercise a week. The curriculum will reset and restart after solving every exercise. The exercises will be in increasing difficulty, and though you can jump in and out, be aware that some are built on top of previously built data structures.
47
+
The plan is to meet in #algorithms-curriculum channel on[Operation Code Slack](https://operationcode.org), and solve one or two exercises a week. The curriculum will reset and restart after solving every exercise. The exercises will be in increasing difficulty, and though you can jump in and out, be aware that some are built on top of previously built data structures.
48
48
49
49
### Folders
50
50
@@ -102,14 +102,12 @@ See how it reads like regular language? Understanding the test specifications wi
102
102
103
103
- There will be times when the problem sets will be updated. In that case, we will announce in the channel for everyone to pull from `upstream`.
104
104
- Enter the terminal, and run `git pull upstream master`.
105
-
- If you have edited the `/solutions` or `/skeletons` folder, you may run into a merge conflict. At that point, please reach out to the channel on Slack.
105
+
- If you have edited the `/solutions` or `/solutions` folder, you may run into a merge conflict. At that point, please reach out to the channel on Slack.
106
106
107
107
## How to Contribute
108
108
109
109
- We need mentors in #basic-algorithms channel.
110
-
- Because the problem descriptions are poorly written at the moment, we will need to walk the students on Slack. Also, some may have deeper questions about the material, and we can all learn together by providing mentorship.
111
110
- We need help writing a walkthrough for each problem set.
112
-
- Currently, the problemss only provide a brief description. A detailed walkthrough is needed for the first several problems in order to help people adjust to the system.
113
111
- We need help with writing tests in other languages.
114
112
- Not everyone maybe familiar with JavaScript. Also, learning this material is actually better in other languages such as Python or Ruby.
A queue is a data structure that can store or retrieve one item at a time, in first-in-first-out (FIFO) order. Think of FIFO as standing in the line at the grocery store. You would expect the first person that stood in the line to be the first one served by the cashier.
6
+
7
+
Queue implements FIFO through two operations; `enqueue` and `dequeue`, which can be visualized in the diagram below:
8
+
9
+

10
+
11
+
-`enqueue` operation stores the item at the back of the queue.
12
+
-`dequeue` operation retrieves the item from the front of the queue.
13
+
14
+
(_In the diagram above, the right side is the front, and the left is the back. However, the same operations are applied even when the direction is reversed_)
15
+
16
+
## Implementation
17
+
18
+
In this exercise, implement the following functions for the `Queue` class
19
+
20
+
-`isEmpty()`
21
+
- Write a method that returns `true` if the queue is currently empty.
22
+
-`peek()`
23
+
- Write a method that returns the element at the front of the queue.
24
+
-`enqueue(el)`
25
+
- Write a method that stores an element(`el`) into the queue.
26
+
-`dequeue()`
27
+
- Write a method that retrieves an element from the queue.
28
+
-`toString()`
29
+
- The stringify method is provided for you. `toString()` is a useful method to implement into data structures for easier debugging.
30
+
- For example, you could use it for logging:
31
+
```
32
+
const queue = new Queue();
33
+
constole.log(queue.toString());
34
+
```
35
+
- A queue is simple enough to be logged without actually needing `toString()`, but with more complex data structures, this is an invaluable method.
36
+
37
+
## Queue Exercises
38
+
39
+
**Stack Queue**
40
+
41
+
(Solve this exercise after finishing the stack exercise).
42
+
43
+
Implement a queue using stacks. Instead of using an array as your store, use a stack:
Copy file name to clipboardExpand all lines: solutions/data-structures/stack/README.md
+44-17Lines changed: 44 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,25 +1,52 @@
1
1
# Stack
2
2
3
-
In computer science, a stack is an abstract data type that serves
4
-
as a collection of elements, with two principal operations:
3
+
## Description
5
4
6
-
***push**, which adds an element to the collection, and
7
-
***pop**, which removes the most recently added element that was not yet removed.
5
+
A stack is a data structure that can store and retrieve one item at a time, in last-in-first-out (LIFO) order. Imagine stacking plates on top of each other or grabbing them from the top one at a time. When you want a plate, you grab one from the top, and when you are done using it, you put it back on the top.
8
6
9
-
The order in which elements come off a stack gives rise to its
10
-
alternative name, LIFO (last in, first out). Additionally, a
11
-
peek operation may give access to the top without modifying
12
-
the stack. The name "stack" for this type of structure comes
13
-
from the analogy to a set of physical items stacked on top of
14
-
each other, which makes it easy to take an item off the top
15
-
of the stack, while getting to an item deeper in the stack
16
-
may require taking off multiple other items first
7
+
Stack implements LIFO through two operations: `push` and `pop`, which can be visualized in the diagram below:
17
8
18
-
Simple representation of a stack runtime with push and pop operations.
9
+

10
+
(_A stack is usually visualized from bottom-to-top_)
Copy file name to clipboardExpand all lines: src/data-structures/queue/README.md
+23-19Lines changed: 23 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,8 +8,8 @@ Queue implements FIFO through two operations; `enqueue` and `dequeue`, which can
8
8
9
9

10
10
11
-
-`enqueue` operation stores the item at the back of the line
12
-
-`dequeue` operation retrieves the item from the front of the line
11
+
-`enqueue` operation stores the item at the back of the queue.
12
+
-`dequeue` operation retrieves the item from the front of the queue.
13
13
14
14
(_In the diagram above, the right side is the front, and the left is the back. However, the same operations are applied even when the direction is reversed_)
15
15
@@ -21,8 +21,8 @@ In this exercise, implement the following functions for the `Queue` class
21
21
- Write a method that returns `true` if the queue is currently empty.
22
22
-`peek()`
23
23
- Write a method that returns the element at the front of the queue.
24
-
-`enqueue()`
25
-
- Write a method that stores an element into the queue.
24
+
-`enqueue(el)`
25
+
- Write a method that stores an element(`el`) into the queue.
26
26
-`dequeue()`
27
27
- Write a method that retrieves an element from the queue.
28
28
-`toString()`
@@ -36,25 +36,29 @@ In this exercise, implement the following functions for the `Queue` class
36
36
37
37
## Queue Exercises
38
38
39
-
Solve this exercise after writing a queue.
39
+
**Stack Queue**
40
40
41
-
**Bracket Matching**
41
+
(Solve this exercise after finishing the stack exercise).
42
42
43
-
Write an algorithm to determine if all of the delimiters in an expression are matched and closed.
43
+
Implement a queue using stacks. Instead of using an array as your store, use a stack:
A stack is a data structure that can store and retrieve one item at a time, in last-in-first-out (LIFO) order. Imagine stacking plates on top of each other or grabbing them from the top one at a time. When you want a plate, you grab one from the top, and when you are done using it, you put it back on the top.
6
+
7
+
Stack implements LIFO through two operations: `push` and `pop`, which can be visualized in the diagram below:
8
+
9
+

10
+
(_A stack is usually visualized from bottom-to-top_)
11
+
12
+
-`push` operation stores the item at the top of the stack.
13
+
-`pop` operation retrieves the item from the top of the stack.
14
+
15
+
## Implementation
16
+
17
+
In this exercise, implement the following functions for the `Stack` class
18
+
19
+
-`isEmpty()`
20
+
- Write a method that returns `true` if the stack is currently empty.
21
+
-`peek()`
22
+
- Write a method that returns the element from the top of the stack.
23
+
-`push(el)`
24
+
- Write a method that stores an element(`el`) into the stack.
25
+
-`pop()`
26
+
- Write a method that retrieves an element from the stack.
27
+
-`toString()`
28
+
- The stringify method has been provided for you.
29
+
30
+
## Stack Exercises
31
+
32
+
**Bracket Matching**
33
+
34
+
Write an algorithm to determine if all of the delimiters in an expression are matched and closed.
0 commit comments