Skip to content
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

이진 탐색 트리 삭제 Case.3 #177

Open
tagrn opened this issue Sep 21, 2023 · 1 comment
Open

이진 탐색 트리 삭제 Case.3 #177

tagrn opened this issue Sep 21, 2023 · 1 comment

Comments

@tagrn
Copy link

tagrn commented Sep 21, 2023

링크

https://github.com/gyoogle/tech-interview-for-developer/blob/master/Computer%20Science/Data%20Structure/Binary%20Search%20Tree.md#%EC%82%AD%EC%A0%9C%EC%9D%98-3%EA%B0%80%EC%A7%80-case

수정해야할 내용

이진 탐색 트리 삭제 케이스 중 3번째에 밑과 같이 쓰여져 있습니다.

  1. 자식이 2개인 노드일 때 → 오른쪽 자식 노드에서 가장 작은 값 or 왼쪽 자식 노드에서 가장 큰 값 올리기

하지만 밑과 같은 상황일 때, 위와 같은 방식으로 삭제하게 된다면 트리가 깨질 거라 생각합니다.

  1. 50을 삭제하려 합니다.
  2. 오른쪽 자식 노드 중 가장 작은 값은 70입니다.
  3. 왼쪽 자식 노드 중 가장 큰 값은 45입니다.
  4. 두 노드 중 아무 노드나 올려도 트리가 깨지게 됩니다.
image

그래서 밑과 같이 바꾸는게 좋아보여 이슈 올립니다.

  1. 자식이 2개인 노드일 때 → 자식 노드들의 임의의 리프 노드를 삭제할 노드에 위치에 올려 자식노드들과 비교하며 재정렬하기
@CheorHyeon
Copy link

좋은 것 같습니다!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants