-
-
Notifications
You must be signed in to change notification settings - Fork 195
[mangodm-web] Week10 Solutions #543
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
Conversation
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.
@mangodm-web 님 한 주 고생 많으셨습니다!
리뷰가 조금 늦었지만, 이번주도 화이팅입니다!
course-schedule/mangodm-web.py
Outdated
- Time Complexity: O(v + e). v와 e는 각각 과목의 수, e는 선행 관계(과목 => 선행 과목)의 수다. | ||
모든 과목과 그 과목의 선행 과목을 탐색해야 하기 때문에 각 노드와 엣지에 대해 한번씩 방문해야 한다. | ||
- Space Complexity: O(v). v는 과목의 수다. | ||
각 과목에 대해서 그래프(선행 관계)를 저장하고, 재귀 호출 스택에 의해 공간이 사용된다. |
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.
그래프를 저장 할 때, 과목 수 뿐 아니라, 엣지 수 만큼도 중복 저장이 되지 않을까요?
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.
dfs 풀이도 있지만 위상 정렬 알고리즘도 참고해보시면 좋을 것 같습니다. 특정 케이스에 더 적합한 알고리즘이 존재한다면 이를 알고있으면 인터뷰에 도움이 될 것 같습니다.
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.
@HC-kang님,
생각해보니, v보다 e가 큰 경우가 있을 수 있으니, O(v + e)로 표현해줘야겠네요.
꼼꼼하게 봐주시고, 코멘트 해주셔서 감사합니다!
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.
@lymchgmk님,
다음에 필요한 상황에 맞게 위상 정렬을 한번 적용해보겠습니다!
좋은 주제 알려주셔서 감사합니다.
invert-binary-tree/mangodm-web.py
Outdated
- Idea: 재귀를 이용하여 각 노드의 왼쪽 자식과 오른쪽 자식을 바꾼다. | ||
- Time Complexity: O(n). n은 전체 노드의 수다. | ||
모든 노드에 대해서 반복적으로 수행해야 하기 때문에 O(n) 시간이 걸린다. | ||
- Space Complexity: O(h). h는 트리의 높이로, 재귀 호출으로 인한 스택 공간이 필요하다. |
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.
이 부분에 대해서 다들 의견이 다양한것같아요.
저는 빅오 표기법은 최악을 나타내어야 하기때문에 O(n)으로 생각을 했는데, 어찌보면 h를 알 수 있다면-어차피 h의 최악은 n이 될테니- O(h)가 좀 더 정확한 표현 같기도 하고 말이죠.
이 부분에서 @mangodm-web 님의 의견은 어떠실까요?
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.
@HC-kang님 말씀처럼 불균형 트리라면, 전체 노드의 수만큼 재귀 호출이 필요하기 때문에,
공간 복잡도는 O(n)으로 나타내는 것이 더 직관적인 것 같아요. 알려주셔서 감사합니다!
while left <= right: | ||
mid = (left + right) // 2 | ||
|
||
if nums[mid] == target: | ||
return mid | ||
|
||
if nums[left] <= nums[mid]: | ||
if nums[left] <= target < nums[mid]: | ||
right = mid - 1 | ||
else: | ||
left = mid + 1 | ||
else: | ||
if nums[mid] < target <= nums[right]: | ||
left = mid + 1 | ||
else: | ||
right = mid - 1 | ||
|
||
return -1 |
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.
이분탐색에서 제일 귀찮은게 어디에 등호 넣고 어디에 +1 아니면 -1 하느냐인데, 다른 문제에서 아 이거 이분탐색이다 싶을 때, 각각 조절해보시면 좋을 것 같습니다. 어떨 때는 되고 어떨 때는 안되어서 골치아플 때가 있습니다.
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.
@lymchgmk님,
범위를 조정하는 부분이 정말 까다롭더라구요. 앞으로는 문제 풀 때, 이 부분을 좀 더 신경 써봐야겠네요.
좋은 팁 감사합니다!
@lymchgmk, @HC-kang님! |
답안 제출 문제
체크 리스트
In Review
로 설정해주세요.