Welcome! ๐Ÿ™‹โ€โ™‚๏ธ View more

Engineering ๐Ÿ’ป/Algorithm

[์ž๋ฃŒ๊ตฌ์กฐ] Binary Search Tree

DeepFlame 2022. 2. 5. 00:21

Binary Search Tree๋ž€?


๐Ÿ‘‰ ๊ฐœ๋…

Binary Search Tree(BST)๋Š” ํšจ์œจ์ ์ธ ํƒ์ƒ‰์„ ์œ„ํ•œ ๋ฐ์ดํ„ฐ ์ €์žฅ ๋ฐฉ๋ฒ•์ด๋‹ค. 

 

๐Ÿ‘‰ ๊ทœ์น™

  • ๋…ธ๋“œ์— ์ €์žฅ๋˜๋Š” ํ‚ค๋Š” ์œ ์ผํ•˜๋‹ค. 
  • ๋ถ€๋ชจ์˜ ํ‚ค ๊ฐ’์ด ์™ผ์ชฝ ์ž์‹ ๋…ธ๋“œ์˜ ํ‚ค ๊ฐ’๋ณด๋‹ค ํฌ๋‹ค. 
  • ๋ถ€๋ชจ์˜ ํ‚ค ๊ฐ’์ด ์˜ค๋ฅธ์ชฝ ์ž์‹ ๋…ธ๋“œ์˜ ํ‚ค ๊ฐ’๋ณด๋‹ค ์ž‘๋‹ค. 
  • ์™ผ์ชฝ๊ณผ ์˜ค๋ฅธ์ชฝ ์„œ๋ธŒํŠธ๋ฆฌ๋„ BST์ด๋‹ค. 

 

๐Ÿ‘‰ ์žฅ๋‹จ์ 

์žฅ์ 
ํƒ์ƒ‰ ์—ฐ์‚ฐ ์‹œ๊ฐ„๋ณต์žก๋„๊ฐ€ O(log N)์ด๋‹ค. (๋ช…ํ™•ํžˆ ๋งํ•˜๋ฉด O(h))

๋‹จ์  
ํŽธํ–ฅ ํŠธ๋ฆฌ์˜ ๊ฒฝ์šฐ ์ €์žฅ ์ˆœ์„œ์— ๋”ฐ๋ผ์„œ ํ•œ ์ชฝ์œผ๋กœ๋งŒ ๋…ธ๋“œ๊ฐ€ ์ถ”๊ฐ€๋˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค.
์ตœ์•…์˜ ๊ฒฝ์šฐ๋Š” ํƒ์ƒ‰ ์‹œ๊ฐ„๋ณต์žก๋„๊ฐ€ O(N)์ด๋‹ค.
๋ฐฐ์—ด๋ณด๋‹ค ๋งŽ์€ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.

 

์ถœ์ฒ˜: https://yoongrammer.tistory.com/71

 

 

 

Leetcode ๋ฌธ์ œ๋ฅผ ํ†ตํ•œ BST ๊ตฌํ˜„


BST๋ฅผ ์ง์ ‘ ๊ตฌํ˜„ํ•˜๋Š” ๊ฒƒ์ด ๋„์›€์ด ๋  ๊ฒƒ์ด๋ผ ์ƒ๊ฐํ•˜์—ฌ ์•„๋ž˜ ๋ฌธ์ œ๋ฅผ ํ’€์–ด๋ณด์•˜๋‹ค. 

1. ํƒ์ƒ‰: https://leetcode.com/problems/search-in-a-binary-search-tree/

 

Search in a Binary Search Tree - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

 

2. ์‚ฝ์ž…: https://leetcode.com/problems/insert-into-a-binary-search-tree/

 

Insert into a Binary Search Tree - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

 

3. ์‚ญ์ œ: https://leetcode.com/problems/delete-node-in-a-bst/

 

Delete Node in a BST - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

 

 

๐Ÿ‘‰ ํ’€์ด

1. ํƒ์ƒ‰

 

2. ์‚ฝ์ž…

 

3. ์‚ญ์ œ