Skip to content

Ports - Ngoc#18

Open
lebaongoc wants to merge 1 commit intoAda-C11:masterfrom
lebaongoc:master
Open

Ports - Ngoc#18
lebaongoc wants to merge 1 commit 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.

Checklist

  • Clean, working code
  • Efficient code
    • There's a solution that is O(1) space complexity that involves a trick. See if you can figure it out, and feel free to ping me on Slack if you're curious!
  • 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.

# Space complexity: ?
#Approach 1:
# Time complexity: O(n^3) 3 nested loops
# Space complexity: O(n^2) n is the number of rows and columns in the matrix being cloned
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is true if the number of rows and columns are the same (i.e. the input matrix is a "square" matrix). However, if you allow the number of rows & columns to differ, you probably need to specify O(nm) and define n as the number of rows and m as the number of columns.

# Time complexity: ?
# Space complexity: ?
#Approach 1:
# Time complexity: O(n^3) 3 nested loops
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Yep

end

#Approach 2:
# Time complexity: O(n^2) 2 nested loops
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Same comment as above (O(nm) instead of O(n^2)), but well done! This second implementation is a significant improvement over the O(n^3) implementation above.

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