Skip to content

Conversation

Chaedie
Copy link
Contributor

@Chaedie Chaedie commented Dec 17, 2024

답안 제출 문제

체크 리스트

  • 우측 메뉴에서 PR을 Projects에 추가해주세요.
  • Projects의 오른쪽 버튼(▼)을 눌러 확장한 뒤, Week를 현재 주차로 설정해주세요.
  • 바로 앞에 PR을 열어주신 분을 코드 검토자로 지정해주세요.
  • 문제를 모두 푸시면 프로젝트에서 StatusIn Review로 설정해주세요.
  • 코드 검토자 1분 이상으로부터 승인을 받으셨다면 PR을 병합해주세요.

@Chaedie Chaedie requested a review from a team as a code owner December 17, 2024 00:50
@github-actions github-actions bot added the py label Dec 17, 2024
@Chaedie Chaedie requested a review from yolophg December 17, 2024 00:50
Copy link
Contributor

@obzva obzva left a comment

Choose a reason for hiding this comment

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

한 주 풀이 수고하셨습니다~

@yolophg 헬레나님 지정된 PR 리뷰 부탁드립니다

Comment on lines +13 to +14
Time: O(n^2)
Space: O(n^2)
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. 공간 복잡도 분석을 O(N^2)으로 하신 이유가 궁금해요. 혹시 설명해주실 수 있으신가요? (틀렸다는 지적은 아니고 생각의 과정이 궁금했습니다 ㅎㅎ)

  2. 찾아보니 파이썬의 List.index 메소드의 시간 복잡도가 O(N)이라는 걸 알게 되었습니다. dictionary를 이용하시면 전체 풀이의 시간복잡도를 O(N^2) -> 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.

  1. index 연산이 O(n)이고 O(n)이 줄어들면서 재귀 뎁스만큼 반복되어서 호출되면 O(n^2) 이라고 생각했습니다...!

Copy link
Contributor

@obzva obzva Dec 22, 2024

Choose a reason for hiding this comment

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

Chaedie님 생각과 제 생각이 거의 비슷한데요, 조금 더 자세한 사항을 덧붙여 보고 싶어요
self.buildTree메소드에 input으로 넘기는 새로운 두 배열 preorder[?:?], inorder[?:?]을 할당하기 위해 추가적으로 사용하는 공간이 O(N)의 공간복잡도를 지니고, 이러한 추가적인 공간 사용이 self.buildTree의 재귀호출마다 반복적으로 이루어지므로 전체적인 공간복잡도는 O(N^2)으로 볼 수 있다
저랑 비슷하게 생각하신게 맞을까요? :)

Copy link
Contributor Author

@Chaedie Chaedie Dec 22, 2024

Choose a reason for hiding this comment

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

에고, 첫번째 답변은 시간 복잡도 분석으로 잘못 이해하고 말씀드렸습니다 😅

공간 복잡도 분석의 경우 @obzva 님 말씀해주신 것과 동일하게 새로운 배열을 O(n) 만큼 계속 할당하면서 넘겨주어 O(n^2)으로 생각했던게 맞습니다..!

Copy link
Contributor Author

@Chaedie Chaedie Dec 22, 2024

Choose a reason for hiding this comment

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

97eb6f9
Flynn 님 코멘트와 알고달레 홈페이지 솔루션 참고해서 시간복잡도, 공간복잡도 최적화된 코드 추가해두었습니다.
우선 2주차는 이렇게 마무리하고 3주차 진행하면서 다시 한번 풀어보도록 하겠습니다.

리뷰 해주셔서 감사합니다..!

@Chaedie Chaedie merged commit 1341491 into DaleStudy:main Dec 22, 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