Skip to content

[SAM] Week 3 solutions. #70

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

Merged
merged 7 commits into from
May 14, 2024
Merged

[SAM] Week 3 solutions. #70

merged 7 commits into from
May 14, 2024

Conversation

SamTheKorean
Copy link
Contributor

No description provided.

@SamTheKorean SamTheKorean changed the title [SAM} Week 3 solutions. [SAM] Week 3 solutions. May 12, 2024
@@ -0,0 +1,29 @@
# Time complexity : O(n*m)
# Space complexity : Space complexity: O(h) h is the height of the call stack during the recursive traversal.
Copy link
Member

@DaleSeo DaleSeo May 12, 2024

Choose a reason for hiding this comment

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

흠... 모든 재귀 알고리즘에 해당하는 말이긴 한데, 이걸 가지고 공간 복잡도 "분석"을 했다라고 말할 수 있는지 의문이 들어요. 분석이 아니라 그냥 일반적인 사실을 말씀하신 느낌입니다.

시간 복잡도처럼 입력으로 들어온 두 개의 트리에 들어 있는 노드의 개수로 수식을 만들어야 하지 않을까요? 그리고 좀 더 구체적으로 이 둘 중에서 어떤 트리의 높이에 비례하는지, 아니면 둘 다 영향을 주는지에 대해서 분석을 해주는 것이 더 좋을 것 같습니다.

Copy link
Contributor Author

@SamTheKorean SamTheKorean May 13, 2024

Choose a reason for hiding this comment

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

설명 더 구체적으로 반영해서 다시 푸시하겠습니다! 피드백 감사드립니다. 다시 보니 너무 빈약했네요ㅜㅜ

@@ -0,0 +1,18 @@
# Time complexity : O(n)
# Space complexity : O(n)
Copy link
Member

Choose a reason for hiding this comment

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

Space Complexity가 $O(n)$인 이유가 궁금해요.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

오타인 것 같습니다. 이따 다시 푸시하겠습니다!

@SamTheKorean SamTheKorean force-pushed the solution3 branch 2 times, most recently from b095aa1 to 9e15b25 Compare May 13, 2024 07:54
@@ -0,0 +1,29 @@
# Time complexity: O(n*m)
# Space complexity: O(h) where h is the depth of the root tree. This is due to the recursive calls, which generate the call stack during traversal. In the worst case of a skewed tree, the space complexity can reach O(n).
Copy link
Member

Choose a reason for hiding this comment

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

subRoot는 공간 복잡도에 전혀 영향을 안 준다는 분석인 것 같은데, 제가 맞게 이해하고 있는 걸까요?

Copy link
Contributor Author

@SamTheKorean SamTheKorean May 14, 2024

Choose a reason for hiding this comment

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

네 제가 적은 건 이해하신게 맞습니다. 이 문제에서 공간분석이 애매하다고 느껴서 알고달래에 분석해주신 것 보니 이제 왜 틀렸는지 이해가 갑니다. 다시 수정해서 올리겠습니다!

@@ -0,0 +1,29 @@
# Time complexity: O(n*m)
# Space complexity: O(r + s) isSubtree() method is internally calling isSameTree() so the total depth of the stack is sum of isSubtree() call stacks and isSameTree()'s call stacks.
Copy link
Member

Choose a reason for hiding this comment

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

Finally 💯!

@DaleSeo DaleSeo merged commit 227f589 into DaleStudy:main May 14, 2024
ysle0 added a commit to ysle0/leetcode-study that referenced this pull request Dec 18, 2024
@crumbs22 crumbs22 mentioned this pull request Dec 20, 2024
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants