Skip to content

Ports - Ngoc#30

Open
lebaongoc wants to merge 2 commits intoAda-C11:masterfrom
lebaongoc:master
Open

Ports - Ngoc#30
lebaongoc wants to merge 2 commits intoAda-C11:masterfrom
lebaongoc:master

Conversation

@lebaongoc
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

@mmcknett mmcknett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job! I'd like to see a brief explanation of what n is and why the algorithm is O(n) time complexity.

Checklist

  • Clean, working code
  • Efficient code - give feedback as you would give to a peer on your team
  • A detailed explanation of time and space complexity (explains what n stands for, explains why it would be a specific complexity, etc.)
  • All test cases for the assignment should be passing.

Comment thread lib/factorial.rb
# Computes factorial of the input number and returns it
# Time complexity: ?
# Space complexity: ?
# Time complexity: O(n)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you provide time complexity, please explain in a few words what n means. For example, in this case, is n equal to the value of number? Or is it equal to the number of things stored in number (which would be 1)? Or might it have anything to do with the number of decimal digits needed to represent number? It's important to define n for every new problem, since the meaning can change from algorithm to algorithm.

Comment thread lib/factorial.rb
raise ArgumentError
end

i = 1
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm used to seeing i used as a variable name only when the variable is used to iterate over a collection. This variable is actually being used to accumulate the product of numbers for the factorial calculation. I'd name this something more like product in order to avoid confusion.

Comment thread lib/factorial.rb
# Time complexity: ?
# Space complexity: ?
# Time complexity: O(n)
# Space complexity: O(1)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also briefly explain why here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants