Skip to content

Conversation

haklee
Copy link
Contributor

@haklee haklee commented Oct 22, 2024

답안 제출 문제

체크 리스트

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

@haklee haklee requested a review from a team as a code owner October 22, 2024 15:27
@github-actions github-actions bot added the py label Oct 22, 2024
@haklee haklee requested a review from jdalma October 22, 2024 15:28
@haklee
Copy link
Contributor Author

haklee commented Oct 22, 2024

3, 5번째 문제에 대해 TC, SC 분석을 아직 덜 달아두었는데, 코드는 작성을 완료해서 일단은 답안을 제출한 것으로 치고 올려두었습니다. 분석은 추후 추가 예정입니다.

@haklee
Copy link
Contributor Author

haklee commented Oct 23, 2024

분석 추가하여 커밋해두었습니다.

Copy link
Member

@jdalma jdalma left a comment

Choose a reason for hiding this comment

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

한 주 수고하셨습니다

Comment on lines +73 to +75
if pa == pb:
# parent가 같음. rank 작업 안 해도 된다.
return True
Copy link
Member

Choose a reason for hiding this comment

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

두 노드의 부모 노드가 같다면 바로 트리가 아니라고 판단 할 수 있군요 ㅎㅎ 간선이 중북되어 들어오면 어쩌나 했는데 입력 조건에 중복된 간선은 없다는 전제가 있군요
유니온 파인드 풀이 잘 봤습니다!

Comment on lines +34 to +53
if newInterval:
# 아직 newInterval이 None으로 변경되지 않았다.
if curInterval[1] < newInterval[0]:
# cur, new가 겹치지 않고, curInterval이 더 앞에 있음.
res.append(curInterval)
elif curInterval[0] > newInterval[1]:
# cur, new가 겹치지 않고, newInterval이 더 앞에 있음.
res.append(newInterval)
res.append(curInterval)
newInterval = None
else:
# 겹치는 부분 존재. newInterval을 확장한다.
newInterval = [
min(curInterval[0], newInterval[0]),
max(curInterval[1], newInterval[1]),
]
else:
# 더 이상 newInterval과 연관된 작업을 하지 않는다. 순회 중인
# curInterval을 결과 리스트에 더하고 끝.
res.append(curInterval)
Copy link
Member

@jdalma jdalma Oct 24, 2024

Choose a reason for hiding this comment

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

엄청 간단하고 직관적이게 해결하셨네요 👍 이 풀이를 참고하여 해결하였습니당 ㅎㅎ

않으므로 None으로 바꿔준다.

SC:
- newInterval 값만 업데이트 하면서 관리. O(1).
Copy link
Member

@jdalma jdalma Oct 24, 2024

Choose a reason for hiding this comment

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

결과 배열인 res를 사용하여서 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.

공간복잡도를 분석할때 리턴하는 변수를 포함 안 시키는 것이 일반적이라고 들었는데, 이건 각종 알고리즘 분석 글들을 찾아보다 보면 사람들마다 다르게 적용하고 있는 것 같습니다.
저는 어차피 알고리즘 돌릴때 리턴하는 값에 대한 공간 복잡도가 크면(예를 들어, O(n^2)) 중간 과정에 사용하는 변수들에 대한 공간 복잡도가 작은 것이(예를 들어, O(n)) 실제 알고리즘을 돌리는 환경에서 별 이득이 없으니 그냥 리턴 값까지 포함해서 분석하는 것이 맞다고 생각했는데, 알고리즘을 튜링 머신의 관점에서 봤을때 공간 복잡도는 read/write에 필요한 테이프라는 말이 일리가 있다고 생각하여 알고리즘에 필요한 추가 공간만 공간복잡도에 포함시키는 것으로 결정하고 분석을 작성하고 있습니다.

Copy link
Member

Choose a reason for hiding this comment

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

저는 단순히 메모리라는 영역을 사용한다면 항상 포함해왔는데 이런 관점도 있군요 ㅎㅎ 처음알게 된 내용이라 신선하네요 감사합니다

@haklee haklee merged commit 82029fc into DaleStudy:main Oct 27, 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.

2 participants