Skip to content

Commit b455114

Browse files
committed
Update README to match Sprint Challenge template README
1 parent fb7aa0b commit b455114

File tree

3 files changed

+74
-33
lines changed

3 files changed

+74
-33
lines changed

README.md

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,65 @@
11
# Sprint Challenge: Data Structures and Algorithms
22

3-
For the data structures portion of this sprint challenge, you'll be implementing a few functions that build off of some of the data structures you implemented in the first half of the week. Then you'll be analyzing the runtimes of these functions.
3+
In this week's Sprint you explored and implemented some classic algorithmic approaches and used them to solve novel problems. You also implemented some classic and fundamental data structures and learned about how to go about evaluating their respective runtimes and performance. This Sprint Challenge aims to assess your comfort with these topics through exercises that build on the data structures you implemented and the algorithmic intuition you've started to build up.
44

5-
For the algorithms portion of the sprint challenge, you'll be answering the questions posed in the `Algorithms_Questions.md` file regarding runtime complexities and algorithmic paradigms.
5+
## Instructions
66

7-
## Data Structures
7+
**Read these instructions carefully. Understand exactly what is expected _before_ starting this Sprint Challenge.**
88

9-
It is recommended that you allot about 2 hours for this portion of the sprint challenge.
9+
This is an individual assessment. All work must be your own. Your Challenge score is a measure of your ability to work independently using the material covered throughout this sprint. You need to demonstrate proficiency in the concepts and objectives that were introduced and that you practiced in the preceding days.
1010

11-
### Task 1. Implement Depth-First and Breadth-First Traversal on the Binary Search Tree Class
12-
Navigate into the `ex1` directory in the `data_structures` 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 the methods `depth_first_for_each` and `breadth_first_for_each` on the `BinarySearchTree` class:
11+
You are not allowed to collaborate during the Sprint Challenge. However, you are encouraged to follow the twenty-minute rule and seek support from your PM and Instructor in your cohort help channel on Slack. Your submitted work reflects your proficiency in the concepts and topics that were covered this week.
12+
13+
You have three hours to complete this Sprint Challenge. Plan your time accordingly.
14+
15+
## Commits
16+
17+
Commit your code regularly and meaningfully. This helps both you (in case you ever need to return to old code for any number of reasons) and it also helps your project manager to more thoroughly assess your work.
18+
19+
## Description
20+
21+
This Sprint Challenge is split into two separate parts: a data structures portion and an algorithms portion.
22+
23+
### Data Structures
24+
25+
It is recommended that you allot about 1 and a half hours for this portion of the Sprint Challenge.
26+
27+
#### Task 1. Implement Depth-First and Breadth-First Traversal on the Binary Search Tree Class
28+
29+
Navigate into the `ex1` directory in the `data_structures` 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:
1330

1431
* `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 the desired order. 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.
1532

16-
*HINT*: In order to achieve depth-first order, you'll probably want to utilize a Stack data structure.
33+
_HINT_: In order to achieve depth-first order, you'll probably want to utilize a Stack data structure.
34+
35+
* Run `python test_depth_first_search.py` to test your depth-first search implementation.
1736

1837
* `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 the desired order. 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.
1938

20-
*HINT*: In order to achieve breadth-first order, you'll probably want to utilize a Queue data structure.
39+
_HINT_: In order to achieve breadth-first order, you'll probably want to utilize a Queue data structure.
2140

22-
NOTE: 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)
41+
* Run `python test_breadth_first_search.py` to test your breadth-first search implementation.
2342

24-
Run `python test_binary_search_tree.py` to run the tests for these methods to ensure that your implementation is correct.
43+
> 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)
2544
26-
### Task 2. Implement Heapsort
27-
Inside the `ex2` directory you'll find the `heap.py` file with a working implementation of the heap class. Your second task is to implement a sorting method called [heapsort](https://en.wikipedia.org/wiki/Heapsort) that uses the heap data structure in order to sort an array of numbers. Your `heapsort` function should return a new array containing all of the sorted data.
45+
> 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.
2846
29-
Run `python test_heap.py` to run the tests for your `heapsort` function to ensure that your implementation is correct.
47+
#### Task 2. Implement Heapsort
3048

31-
### Task 3. Analyze some runtimes
32-
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. Be sure to also answer any other questions posed in the `Data_Structures_Answers.md` file!
49+
Inside the `ex2` directory you'll find the `heap.py` file with a working implementation of the heap class. Your second task is to implement a sorting method called [heapsort](https://en.wikipedia.org/wiki/Heapsort) that uses the heap data structure in order to sort an array of numbers. Your `heapsort` function should return a new list containing all of the sorted data.
3350

34-
## Algorithms
51+
Run `python test_heap.py` to run the tests for your `heapsort` function to ensure that your implementation is correct.
3552

36-
It is recommended that you allot about 1 hour for this portion of the sprint challenge.
53+
#### Task 3. Analyze some runtimes
3754

38-
For the algorithms portion of the sprint challenge, you'll be answering questions posed in the `Algorithms_Questions.md` document inside the `algorithms` directory. Add your answers to the questions in the `Algorithms_Answers.md` file.
55+
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. Be sure to also answer any other questions posed in the `Data_Structures_Answers.md` file!
3956

40-
## Rubric
57+
### Algorithms
4158

42-
Each test in the Data Structures portion is worth 2 points for a total of 6.
43-
Each runtime analysis question in the Data Structures portion is worth 1 point for a total of 6.
44-
Each question in the Algorithms portion is worth 2 points for a total of 8.
59+
It is recommended that you allot about 1 and a half hours for this portion of the sprint challenge.
4560

46-
In order to earn a score of 3, you'll need to score at least 90%, or 18 / 20 total possible points.
61+
For the algorithms portion of the sprint challenge, you'll be answering questions posed in the `Algorithms_Questions.md` document inside the `algorithms` directory. Write down your answer and also write down a justification for _why_ you put down that answer. This could net you some partial credit if your justification is sound but the answer you put down turns out to not be correct. Add your answers to the questions in the `Algorithms_Answers.md` file.
4762

48-
In order to earn a score of 2, you'll need to score at least 70%, or 14 / 20 total possible points.
63+
### Stretch Problems
4964

50-
Anything lower earns you a score of 1.
65+
Implement the other tree traversal algorithm that you didn't implement on the `BinarySearchTree` class. Run the appropriate test file to test your implementation's correctness.

data_structures/ex1/test_binary_search_tree.py renamed to data_structures/ex1/test_breadth_first_search.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,15 @@ class BinarySearchTreeTests(unittest.TestCase):
55
def setUp(self):
66
self.bst = BinarySearchTree(5)
77

8-
def test_depth_first_for_each_executes_callback(self):
8+
def test_breadth_first_traversal_1(self):
99
arr = []
1010
cb = lambda x: arr.append(x)
1111

12-
self.bst.insert(2)
13-
self.bst.insert(3)
14-
self.bst.insert(7)
15-
self.bst.insert(9)
16-
self.bst.depth_first_for_each(cb)
12+
self.bst.breadth_first_for_each(cb)
1713

18-
self.assertEqual(arr, [5, 2, 3, 7, 9])
14+
self.assertEqual(arr, [5])
1915

20-
def test_breadth_first_for_each_executes_callback(self):
16+
def test_breadth_first_traversal_2(self):
2117
arr = []
2218
cb = lambda x: arr.append(x)
2319

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import unittest
2+
from binary_search_tree import BinarySearchTree
3+
4+
class BinarySearchTreeTests(unittest.TestCase):
5+
def setUp(self):
6+
self.bst = BinarySearchTree(5)
7+
8+
def test_depth_first_traversal_1(self):
9+
arr = []
10+
cb = lambda x: arr.append(x)
11+
12+
self.bst.depth_first_for_each(cb)
13+
14+
self.assertEqual(arr, [5])
15+
16+
def test_depth_first_traversal_2(self):
17+
arr = []
18+
cb = lambda x: arr.append(x)
19+
20+
self.bst.insert(2)
21+
self.bst.insert(3)
22+
self.bst.insert(7)
23+
self.bst.insert(9)
24+
self.bst.depth_first_for_each(cb)
25+
26+
self.assertEqual(arr, [5, 2, 3, 7, 9])
27+
28+
29+
if __name__ == '__main__':
30+
unittest.main()

0 commit comments

Comments
 (0)