-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Hunter Smith - Sprint-Challenge--Data-Structures-Python #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Hunter315
wants to merge
5
commits into
bloominstituteoftechnology:master
Choose a base branch
from
Hunter315:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
652df0a
initial commit
Hunter315 2580204
depth_first_for_each
Hunter315 73a2aeb
breadth_first_ffor_each
Hunter315 c8c6ad6
names.py using sets complete in 0.031 seconds
Hunter315 eece83e
finished complexities answers (MVP MET)
Hunter315 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,20 @@ | ||
| Add your answers to the questions below. | ||
|
|
||
| 1. What is the runtime complexity of your `depth_first_for_each` method? | ||
|
|
||
| O(n) , it runs through each node | ||
| 2. What is the space complexity of your `depth_first_for_each` function? | ||
|
|
||
| O(n) | ||
| 3. What is the runtime complexity of your `breadth_first_for_each` method? | ||
|
|
||
| O(n) | ||
| 4. What is the space complexity of your `breadth_first_for_each` method? | ||
|
|
||
| O(n) | ||
|
|
||
| 5. What is the runtime complexity of the provided code in `names.py`? | ||
| O(n^2) since it is looping through each element of each list to compare to each element of the other | ||
|
|
||
| 6. What is the space complexity of the provided code in `names.py`? | ||
|
|
||
| O(n) | ||
| 7. What is the runtime complexity of your optimized code in `names.py`? | ||
|
|
||
| O(n) | ||
| 8. What is the space complexity of your optimized code in `names.py`? | ||
| O(n) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,10 +11,14 @@ | |
| f.close() | ||
|
|
||
| duplicates = [] | ||
| for name_1 in names_1: | ||
| for name_2 in names_2: | ||
| if name_1 == name_2: | ||
| duplicates.append(name_1) | ||
| # for name_1 in names_1: | ||
| # for name_2 in names_2: | ||
| # if name_1 == name_2: | ||
| # duplicates.append(name_1) | ||
| a_set = set(names_1) | ||
| b_set = set(names_2) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice you can also use intersection or a for loop with an if all of these would be O(n) |
||
| if (a_set & b_set): | ||
| duplicates.append(repr(a_set & b_set)) | ||
|
|
||
| end_time = time.time() | ||
| print (f"{len(duplicates)} duplicates:\n\n{', '.join(duplicates)}\n\n") | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,10 +5,25 @@ def __init__(self, value): | |
| self.right = None | ||
|
|
||
| def depth_first_for_each(self, cb): | ||
| pass | ||
| cb(self.value) | ||
| if self.left != None: | ||
| self.left.depth_first_for_each(cb) | ||
| if self.right != None: | ||
| self.right.depth_first_for_each(cb) | ||
| return | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✔️ |
||
|
|
||
|
|
||
| def breadth_first_for_each(self, cb): | ||
| pass | ||
| nodes = [self] | ||
| #while loop going through every node | ||
| while len(nodes) > 0: | ||
| current = nodes.pop(0) | ||
| cb(current.value) | ||
| if current.left != None: | ||
| nodes.append(current.left) | ||
| if current.right != None: | ||
| nodes.append(current.right) | ||
|
|
||
|
|
||
| def insert(self, value): | ||
| new_tree = BinarySearchTree(value) | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️