-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Michael Agard #2
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
Closed
fellanonymous
wants to merge
8
commits into
bloominstituteoftechnology:master
from
fellanonymous:master
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e820ca6
init commit
fellanonymous a47196a
updated PR link
fellanonymous 1b2cc8b
add __pycache__
fellanonymous 22befe6
add selection_sort function
fellanonymous 30b9c93
first try
fellanonymous 806bd7f
fixed iterate_sorting
fellanonymous ae21a9c
removed print
fellanonymous a81341b
finished Linear Search
fellanonymous 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 |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| __pycache__ |
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,36 +1,43 @@ | ||
| # Complete the selection_sort() function below in class with your instructor | ||
| def selection_sort( arr ): | ||
|
|
||
|
|
||
| def selection_sort(arr): | ||
| # loop through n-1 elements | ||
| for i in range(0, len(arr) - 1): | ||
| cur_index = i | ||
| smallest_index = cur_index | ||
| # TO-DO: find next smallest element | ||
| # (hint, can do in 3 loc) | ||
|
|
||
|
|
||
|
|
||
|
|
||
| # TO-DO: swap | ||
|
|
||
|
|
||
|
|
||
|
|
||
| # # (hint, can do in 3 loc) | ||
| for j in range(cur_index, len(arr)): | ||
| if arr[j] < arr[smallest_index]: | ||
| smallest_index = j | ||
| # TO-DO: swap | ||
| arr[cur_index], arr[smallest_index] = arr[smallest_index], arr[cur_index] | ||
| return arr | ||
|
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. This works! Great job on this function. |
||
|
|
||
|
|
||
| # TO-DO: implement the Insertion Sort function below | ||
| def insertion_sort( arr ): | ||
|
|
||
|
|
||
| def insertion_sort(arr): | ||
| for i in range(1, len(arr)): | ||
| cur_index = i | ||
| while cur_index > 0 and arr[cur_index] < arr[cur_index - 1]: | ||
| temp = arr[cur_index - 1] | ||
| arr[cur_index - 1] = arr[cur_index] | ||
| arr[cur_index] = temp | ||
| cur_index -= 1 | ||
| return arr | ||
|
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. I'm happy to say you got this one working, too. Maybe today you can work on quicksort in the recursive file. 😄 |
||
|
|
||
|
|
||
| # STRETCH: implement the Bubble Sort function below | ||
| def bubble_sort( arr ): | ||
|
|
||
|
|
||
| def bubble_sort(arr): | ||
|
|
||
| return arr | ||
|
|
||
|
|
||
| # STRETCH: implement the Count Sort function below | ||
| def count_sort( arr, maximum=-1 ): | ||
| def count_sort(arr, maximum=-1): | ||
|
|
||
| return arr | ||
| return arr | ||
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 |
|---|---|---|
| @@ -1,30 +1,32 @@ | ||
| # STRETCH: implement Linear Search | ||
| # STRETCH: implement Linear Search | ||
| def linear_search(arr, target): | ||
|
|
||
| # TO-DO: add missing code | ||
|
|
||
| return -1 # not found | ||
| for value in arr: | ||
| if value == target: | ||
| return 1 | ||
| return -1 # not found | ||
|
|
||
| # STRETCH: write an iterative implementation of Binary Search | ||
|
|
||
|
|
||
| # STRETCH: write an iterative implementation of Binary Search | ||
| def binary_search(arr, target): | ||
|
|
||
| if len(arr) == 0: | ||
| return -1 # array empty | ||
| low = 0 | ||
| high = len(arr)-1 | ||
| if len(arr) == 0: | ||
| return -1 # array empty | ||
|
|
||
| low = 0 | ||
| high = len(arr)-1 | ||
|
|
||
| # TO-DO: add missing code | ||
| # TO-DO: add missing code | ||
|
|
||
| return -1 # not found | ||
| return -1 # not found | ||
|
|
||
|
|
||
| # STRETCH: write a recursive implementation of Binary Search | ||
| # STRETCH: write a recursive implementation of Binary Search | ||
| def binary_search_recursive(arr, target, low, high): | ||
|
|
||
| middle = (low+high)/2 | ||
|
|
||
| if len(arr) == 0: | ||
| return -1 # array empty | ||
| # TO-DO: add missing if/else statements, recursive calls | ||
| middle = (low+high)/2 | ||
|
|
||
| if len(arr) == 0: | ||
| return -1 # array empty | ||
| # TO-DO: add missing if/else statements, recursive calls |
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
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.
Nice job with the inline swapping syntax.