Skip to content

Conversation

mangodm-web
Copy link
Contributor

@mangodm-web mangodm-web commented Oct 19, 2024

답안 제출 문제

체크 리스트

  • PR을 프로젝트에 추가하고 Week를 현재 주차로 설정해주세요.
  • 바로 앞에 PR을 열어주신 분을 코드 검토자로 지정해주세요.
  • 문제를 모두 푸시면 프로젝트에서 Status를 In Review로 설정해주세요.
  • 코드 검토자 1분 이상으로부터 승인을 받으셨다면 PR을 병합해주세요.

@mangodm-web mangodm-web self-assigned this Oct 19, 2024
@mangodm-web mangodm-web requested a review from a team as a code owner October 19, 2024 16:37
@github-actions github-actions bot added the py label Oct 19, 2024
@mangodm-web mangodm-web requested a review from EgonD3V October 19, 2024 16:37
Copy link
Contributor

@HC-kang HC-kang left a comment

Choose a reason for hiding this comment

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

@mangodm-web 님 한 주 고생 많으셨습니다!
리뷰가 조금 늦었지만, 이번주도 화이팅입니다!

- Time Complexity: O(v + e). v와 e는 각각 과목의 수, e는 선행 관계(과목 => 선행 과목)의 수다.
모든 과목과 그 과목의 선행 과목을 탐색해야 하기 때문에 각 노드와 엣지에 대해 한번씩 방문해야 한다.
- Space Complexity: O(v). v는 과목의 수다.
각 과목에 대해서 그래프(선행 관계)를 저장하고, 재귀 호출 스택에 의해 공간이 사용된다.
Copy link
Contributor

Choose a reason for hiding this comment

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

그래프를 저장 할 때, 과목 수 뿐 아니라, 엣지 수 만큼도 중복 저장이 되지 않을까요?

Copy link
Contributor

Choose a reason for hiding this comment

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

dfs 풀이도 있지만 위상 정렬 알고리즘도 참고해보시면 좋을 것 같습니다. 특정 케이스에 더 적합한 알고리즘이 존재한다면 이를 알고있으면 인터뷰에 도움이 될 것 같습니다.

Copy link
Contributor Author

@mangodm-web mangodm-web Oct 21, 2024

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)로 표현해줘야겠네요.
꼼꼼하게 봐주시고, 코멘트 해주셔서 감사합니다!

Copy link
Contributor Author

@mangodm-web mangodm-web Oct 21, 2024

Choose a reason for hiding this comment

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

@lymchgmk님,
다음에 필요한 상황에 맞게 위상 정렬을 한번 적용해보겠습니다!
좋은 주제 알려주셔서 감사합니다.

- Idea: 재귀를 이용하여 각 노드의 왼쪽 자식과 오른쪽 자식을 바꾼다.
- Time Complexity: O(n). n은 전체 노드의 수다.
모든 노드에 대해서 반복적으로 수행해야 하기 때문에 O(n) 시간이 걸린다.
- Space Complexity: O(h). h는 트리의 높이로, 재귀 호출으로 인한 스택 공간이 필요하다.
Copy link
Contributor

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 님의 의견은 어떠실까요?

Copy link
Contributor Author

@mangodm-web mangodm-web Oct 21, 2024

Choose a reason for hiding this comment

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

@HC-kang님 말씀처럼 불균형 트리라면, 전체 노드의 수만큼 재귀 호출이 필요하기 때문에,
공간 복잡도는 O(n)으로 나타내는 것이 더 직관적인 것 같아요. 알려주셔서 감사합니다!

Comment on lines +17 to +34
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
Copy link
Contributor

Choose a reason for hiding this comment

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

이분탐색에서 제일 귀찮은게 어디에 등호 넣고 어디에 +1 아니면 -1 하느냐인데, 다른 문제에서 아 이거 이분탐색이다 싶을 때, 각각 조절해보시면 좋을 것 같습니다. 어떨 때는 되고 어떨 때는 안되어서 골치아플 때가 있습니다.

Copy link
Contributor Author

@mangodm-web mangodm-web Oct 21, 2024

Choose a reason for hiding this comment

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

@lymchgmk님,
범위를 조정하는 부분이 정말 까다롭더라구요. 앞으로는 문제 풀 때, 이 부분을 좀 더 신경 써봐야겠네요.
좋은 팁 감사합니다!

@mangodm-web
Copy link
Contributor Author

@lymchgmk, @HC-kang님!
두 분 덕분에 많은 것을 알게된 것 같아요. 정성스럽게 리뷰해주셔서 감사합니다!
알려주신 것들을 토대로 이번 주차는 좀 더 꼼꼼하게 살펴봐야겠네요.
이 PR은 머지하겠습니다! 감사합니다. 😄

@mangodm-web mangodm-web merged commit ef6bd30 into DaleStudy:main Oct 21, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Status: Completed
Development

Successfully merging this pull request may close these issues.

3 participants