forked from AdaGold/dynamic-programming
-
Notifications
You must be signed in to change notification settings - Fork 41
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
C. Gutierrez #30
Open
CEsGutierrez
wants to merge
4
commits into
Ada-C12:master
Choose a base branch
from
CEsGutierrez: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
C. Gutierrez #30
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 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,8 +1,38 @@ | ||
|
||
# Time Complexity: ? | ||
# Space Complexity: ? | ||
def max_sub_array(nums) | ||
return 0 if nums == nil | ||
# Time Complexity: O(n) | ||
## The method iterates over the entire array but does so only once | ||
|
||
# Space Complexity: O(1) | ||
## There are a limited number of variables that are constantly being re-assessed, so as the input goes to infitity the space requirements do not grow. | ||
|
||
def max_sub_array(number_array) | ||
length = number_array.length | ||
if length == 0 | ||
return nil | ||
elsif length == 1 | ||
return number_array[0] | ||
end | ||
|
||
max_so_far = number_array[0] | ||
max_ending_here = 0 | ||
|
||
i = 0 | ||
|
||
until i == length do | ||
|
||
max_ending_here = max_ending_here + number_array[i] | ||
|
||
if max_so_far < max_ending_here | ||
max_so_far = max_ending_here | ||
i += 1 | ||
elsif max_ending_here < 0 | ||
max_ending_here = 0 | ||
i += 1 | ||
else | ||
i+= 1 | ||
end | ||
end | ||
|
||
return max_so_far | ||
|
||
raise NotImplementedError, "Method not implemented yet!" | ||
end |
This file contains 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,7 +1,43 @@ | ||
|
||
|
||
# Time complexity: ? | ||
# Space Complexity: ? | ||
# Time complexity: O(n) | ||
## As the number goes to infinity, its values have to be assessed relative to whatever's already in the array, but because it's based on an array, the look-up cost is very low given that an index value is being passed in. | ||
# Space Complexity: O(n) | ||
## As the number goes to infinity, the amount of space will grow at the same rate | ||
|
||
def newman_conway(num) | ||
Comment on lines
+3
to
8
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. 👍 Awesome work 😃 |
||
raise NotImplementedError, "newman_conway isn't implemented" | ||
|
||
if num == 0 || num == nil | ||
raise ArgumentError | ||
elsif num == 1 | ||
return "1" | ||
elsif num == 2 | ||
return "1 1" | ||
end | ||
|
||
if num >= 3 | ||
return_array = [1, 1] | ||
end | ||
|
||
i = 3 | ||
|
||
until i > num do | ||
|
||
# P(n) = P(P(n - 1)) + P(n - P(n - 1)) | ||
|
||
temp_a = return_array[(return_array[i-2])-1] | ||
|
||
temp_b = return_array[(i-(return_array[i-2]))-1] | ||
|
||
temp = temp_a + temp_b | ||
|
||
i += 1 | ||
|
||
return_array.push temp | ||
end | ||
|
||
return_string = return_array.join(" ") | ||
|
||
return return_string | ||
|
||
end |
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.
👍