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
Copy file name to clipboardExpand all lines: README.md
+27-25Lines changed: 27 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,31 +26,33 @@ This Sprint Challenge is split into three parts:
26
26
27
27
### Minimum Viable Product
28
28
29
+
#### Task 1. Implement a Ring Buffer Data Structure
29
30
30
-
#### Task 1. Implement Depth-First or Breadth-First Traversal on the Binary Search Tree Class
31
+
A ring buffer is a non-growable buffer with a fixed size. When the ring buffer is full and a new element is inserted, the oldest element in the ring buffer is overwritten with the newest element. This kind of data structure is very useful for use cases such as storing logs and history information, where you typically want to store information up until it reaches a certain age, after which you don't care about it anymore and don't mind seeing it overwritten by newer data.
31
32
32
-
Navigate into the `search` directory. Inside, you'll see the `binary-search-tree.py` file with a complete implementation of the binary search tree class. Your first task is to implement either `depth_first_for_each` or `breadth_first_for_each` on the `BinarySearchTree` class:
33
+
Implement this behavior in the RingBuffer class. RingBuffer has two methods, `append` and `get`. The `append` method adds elements to the buffer. The `get` method returns all of the elements in the buffer ordered from oldest to newest. In other words, least-recently added elements first, then most-recently added elements.
33
34
34
-
*`depth_first_for_each(cb)` receives an anonymous function as a parameter. It should then execute the anonymous function on each node in the tree in [depth-first](https://en.wikipedia.org/wiki/Depth-first_search) order. Your task is to implement the logic to traverse the tree in depth-first pre-order fashion (as opposed to in-order or post-order). Note that the pseudocode showcased on the Wikipedia article traverses the tree in-order.
35
+
For example:
35
36
36
-
* Remember that the anonymous function is supplied by the caller of the method. All you have to do is ensure that the anonymous function is being called on each tree node in the desired order.
37
-
38
-
_HINT_: In order to achieve depth-first order, you'll probably want to utilize a Stack data structure.
37
+
```python
38
+
buffer = RingBuffer(3)
39
39
40
-
* Run `python test_depth_first_search.py` to test your depth-first search implementation.
40
+
buffer.append('a')
41
+
buffer.append('b')
42
+
buffer.append('c')
41
43
42
-
*`breadth_first_for_each(cb)` receives a callback function as a parameter. It should then execute the anonymous function on each node in the tree in [breadth-first](https://en.wikipedia.org/wiki/Breadth-first_search) order. Your task is to implement the logic to traverse the tree in left-to-right breadth-first fashion.
43
-
44
-
* Remember that the anonymous function is supplied by the caller of the method. All you have to do is ensure that the anonymous function is being called on each tree node in the desired order.
45
-
46
-
_HINT_: In order to achieve breadth-first order, you'll probably want to utilize a Queue data structure.
44
+
buffer.get() # should return ['a', 'b', 'c']
47
45
48
-
* Run `python test_breadth_first_search.py` to test your breadth-first search implementation.
46
+
# 'd' overwrites the oldest value in the ring buffer, which is 'a'
47
+
buffer.append('d')
49
48
50
-
> Note that in Python, anonymous functions are referred to as "lambda functions". When passing in an anonymous function as input to either `depth_first_for_each` or `breadth_first_for_each`, you'll want to define them as lambda functions. For more information on lambda functions, check out this documentation: [https://docs.python.org/3/tutorial/controlflow.html#lambda-expressions](https://docs.python.org/3/tutorial/controlflow.html#lambda-expressions)
49
+
buffer.get() # should return ['d', 'b', 'c']
51
50
52
-
> Note that it is not your job to worry about what the callback function being passed in is doing. That is up to the user of your traversal method. All you care about when implementing the traversal method is to call the passed-in callback in either depth-first or breadth-first order, depending on which traversal method you're implementing.
51
+
buffer.append('e')
52
+
buffer.append('f')
53
53
54
+
buffer.get() # should return ['d', 'e', 'f']
55
+
```
54
56
55
57
#### Task 2. Runtime Optimization
56
58
@@ -60,7 +62,7 @@ Six seconds is an eternity so you've been tasked with speeding up the code. Can
60
62
61
63
(Hint: You might try importing a data structure you built during the week)
62
64
63
-
#### Task 3. Analyze some runtimes
65
+
#### Task 3. Analyze Some Runtimes
64
66
65
67
Open up the `Data_Structures_Answers.md` file. This is where you'll jot down your answers for the runtimes of the functions you just implemented. If you implemented depth-first traversal, just answer the questions pertaining to the depth-first traversal algorithm. If you implemented breadth-first traversal, just answer the questions pertaining to breadth-first traversal.
66
68
@@ -75,26 +77,26 @@ Also, include the runtime and space complexities of the original code and your o
75
77
76
78
### Rubric
77
79
78
-
#### SEARCH
80
+
#### Ring Buffer
79
81
80
-
-DFS or BFS pass tests: 10 points
82
+
-Ring buffer implementation passes the tests: 10 points total
81
83
82
-
#### NAMES
84
+
#### Names
83
85
84
-
- Optimize with an O(n log n) runtime solution: 8 points
85
-
- Optimize with an O(n) runtime solution: 10 points
86
+
- Optimize with an O(n log n) runtime solution: 8 points total
87
+
- Optimize with an O(n) runtime solution: 10 points total
86
88
87
-
#### COMPLEXITY
89
+
#### Complexity
88
90
89
-
- One point each: 8 points
91
+
- One point each: 8 points total
90
92
91
-
#### STRETCH
93
+
#### Stretch
92
94
93
95
- Both DFS and BFS pass tests: 2 points
94
96
-`names.py` is optimized with sub-quadratic runtime complexity and tightly constrained linear space complexity: 2 points
0 commit comments