CS ๊ณต๋ถ€

์ธ๋ฑ์Šค๊ฐ€์— Hash๋ณด๋‹ค B-TREE๋ฅผ ์“ฐ๋Š” ์ด์œ ?

์€์ง„ 2021. 11. 29. 19:22

Buckets (Hash Table)๋Š” O(1)๋กœ ํƒ์ƒ‰์‹œ๊ฐ„์ด ๋น ๋ฅด๋‹ค

  • Hash ํ•จ์ˆ˜๋Š” ์ž…๋ ฅ ๊ฐ’(keys)์ด ๋“ค์–ด์˜ค๋ฉด ์–ธ์ œ๋‚˜ ๊ฐ™์€ ์ถœ๋ ฅ ๊ฐ’(Hash ๊ฐ’)์„ ๊ฐ€์ง
  • buckets์˜ index ๊ฐ’์œผ๋กœ ๋งคํ•‘๋˜์–ด ์ฐพ๊ณ ์ž ํ•˜๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ์–ป์„ ์ˆ˜ ์žˆ์Œ
  • ๋ฏธ๋ฆฌ ์ €์žฅ๋œ ๋ฉ”๋ชจ๋ฆฌ ๊ณต๊ฐ„(buckets)์— ํ•œ ๋ฒˆ์— ์ ‘๊ทผ์„ ํ•˜๊ธฐ ๋•Œ๋ฌธ์—, ํƒ์ƒ‰ ์‹œ๊ฐ„์ด O(1)๋กœ ๋น ๋ฆ„
    • Hash ๊ฐ’์ด ์ถฉ๋Œ์ด ์ผ์–ด๋‚˜๋Š” ๋“ฑ์˜ ์ตœ์•…์˜ ๊ฒฝ์šฐ, O(N)์ด ๋  ์ˆ˜๋„ ์žˆ์Œ

 

 

 

 

ํƒ์ƒ‰์‹œ๊ฐ„์ด ๋น ๋ฅธ Hash๊ฐ€ ์ธ๋ฑ์Šค๋กœ ์ ์ ˆํ•˜์ง€ ์•Š์€ ์ด์œ 

  • ๋‹จ ํ•˜๋‚˜์˜ ๋ฐ์ดํ„ฐ๋ฅผ ํƒ์ƒ‰ํ•˜๋Š” ์‹œ๊ฐ„์ด O(1)์œผ๋กœ ๋น ๋ฅธ ๊ฒƒ์ด๋‹ค.
  • Hash Table์— ์ €์žฅ๋˜๋Š” ๊ฐ’๋“ค์€ ์ •๋ ฌ๋˜์–ด ์žˆ์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— ํŠน์ • ๊ฐ’๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ์ž‘์€ ๊ฐ’์„ ์ฐพ์„ ์ˆ˜ ์—†๋‹ค.
  • SQL ์ฟผ๋ฆฌ๋ฌธ์—์„œ ํŠน์ • ๋ฒ”์œ„์˜ ๊ฐ’์„ ์กฐํšŒํ•˜๋Š” ๊ฒฝ์šฐ, ํŠน์ • ๊ฐ’๋ณด๋‹ค ํฌ๊ฑฐ๋‚˜ ์ž‘์€ ๊ฐ’์„ ์ฐพ์„ ์ˆ˜ ์—†๋‹ค.

ํ•ด์‹œ ์ธ๋ฑ์Šค๋Š” ๊ฒ€์ƒ‰ํ•˜๊ณ ์žํ•˜๋Š” ๊ฐ’์„ ํ•ด์‹œํ•จ์ˆ˜์— ์ž…๋ ฅํ•œ ํ›„ ๊ทธ ๊ฒฐ๊ณผ์™€ Bucket์˜ ๋‚ด์šฉ๊ณผ ๋น„๊ตํ•˜์—ฌ ํ•ด๋‹น ๋ฐ์ดํ„ฐ ๋ ˆ์ฝ”๋“œ์˜ ์œ„์น˜๋ฅผ ์ฐพ์„ ์ˆ˜ ์žˆ๋Š” ์ธ๋ฑ์Šค ๊ธฐ๋ฒ•์ด๋‹ค.

SELECT .. FROM tb_hash WHERE column >= '๊ฒ€์ƒ‰์–ด';
SELECT .. FROM tb_hash WHERE column BETWEEN 100 AND 120;
SELECT .. FROM tb_hash WHERE column LIKE '๊ฒ€์ƒ‰์–ด%'
SELECT .. FROM tb_hash WHERE column <> '๊ฒ€์ƒ‰์–ด';

 

  • ๋ฒ”์œ„ ๋น„๊ต๋‚˜ ๋ถ€์ •ํ˜• ๋น„๊ต๊ฐ€ ํฌํ•จ๋œ SQL ์ฟผ๋ฆฌ๋Š” ํ•ด์‹œ ์ธ๋ฑ์Šค๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†๋‹ค.

 

 

 


 

 

ํ‰๊ท  Tree์˜ ํƒ์ƒ‰ ์‹œ๊ฐ„๋ณต์žก๋„ : O(logN)

 

 

์ตœ์•… Tree์˜ ํƒ์ƒ‰ ์‹œ๊ฐ„๋ณต์žก๋„ : O(N)

  • ์ตœ์•…์˜ ๊ฒฝ์šฐ๋ฅผ ๋Œ€๋น„ํ•ด์„œ Balanced Tree๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.

 

B Tree -- Balanced Tree -- ๊ท ํ˜•์žกํžŒ Tree

  • ์ตœ์•…์˜ ๊ฒฝ์šฐ์ฒ˜๋Ÿผ ํŠธ๋ฆฌ๊ฐ€ ํ•œ์ชฝ์œผ๋กœ ์ ๋ฆฌ์ง€ ์•Š๊ฒŒ ํŠธ๋ฆฌ๊ฐ€ ์žฌ์ •๋ ฌ
  • ๋…ธ๋“œ ์‚ฝ์ž… ๋ฐ ์‚ญ์ œ ์‹œ์— ํŠน์ • ๊ทœ์น™์— ๋”ฐ๋ผ ์ขŒ / ์šฐ SubTree์˜ ๋ฐธ๋Ÿฐ์Šค๋ฅผ ์œ ์ง€ํ•˜๋Š” Tree

 

 

  • ํƒ์ƒ‰์— ๋Œ€ํ•œ ์‹œ๊ฐ„ ๋ณต์žก๋„ : ์–ธ์ œ๋‚˜ O(logN)
  • ๋…ธ๋“œ ์‚ฝ์ž…, ์‚ญ์ œ, ๋ณ€๊ฒฝ --> ํŠธ๋ฆฌ ์žฌ์ •๋ ฌ ์ž‘์—… --> ์ผ๋ฐ˜์ ์ธ Tree๋ณด๋‹ค ์‹œ๊ฐ„๋ณต์žก๋„ ์„ฑ๋Šฅ์ด ์ข‹์ง€ ์•Š์Œ

 

 

 

 

 

 

 

์ถœ์ฒ˜

siAhn, https://siahn95.tistory.com/entry/DB-%EC%9D%B8%EB%8D%B1%EC%8A%A4%EB%9E%80-2-%EA%B5%AC%EC%A1%B0-B-Tree-%EA%B3%84%EC%97%B4%EC%9D%84-%EC%93%B0%EB%8A%94-%EC%9D%B4%EC%9C%A0?category=821999 

 

[DB] ์ธ๋ฑ์Šค๋ž€? - (2) ๊ตฌ์กฐ, B-Tree ๊ณ„์—ด์„ ์“ฐ๋Š” ์ด์œ 

๊ฑฐ์˜ ๋ชจ๋“  DBMS๋Š” ์ธ๋ฑ์Šค ์ข…๋ฅ˜์— ๋Œ€ํ•ด ํŠน๋ณ„ํ•œ ์–ธ๊ธ‰์ด ์—†๋‹ค๋ฉด B-Tree ๊ณ„์—ด ์ธ๋ฑ์Šค๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ๋Œ€๋‹ค์ˆ˜์ด๋‹ค. ๋งŽ๊ณ  ๋งŽ์€ ์ž๋ฃŒ๊ตฌ์กฐ์—์„œ ์™œ ํ•˜ํ•„ B-Tree, B+-Tree๋ฅผ ์‚ฌ์šฉํ•˜๋Š”์ง€์— ๋Œ€ํ•ด ์•Œ์•„๋ณธ๋‹ค. ์ด ๊ธ€

siahn95.tistory.com

jsj3282, https://velog.io/@jsj3282/17.-%ED%95%B4%EC%8B%9CHash-%EC%9D%B8%EB%8D%B1%EC%8A%A4

 

17. ํ•ด์‹œ(Hash) ์ธ๋ฑ์Šค

ํ•ด์‹œ ์ธ๋ฑ์Šค๋Š” B-Tree๋งŒํผ ๋ฒ”์šฉ์ ์ด์ง€๋Š” ์•Š์ง€๋งŒ ๊ณ ์œ ์˜ ํŠน์„ฑ๊ณผ ์šฉ๋„๋ฅผ ์ง€๋‹Œ ์ธ๋ฑ์Šค ๊ฐ€์šด๋ฐ ํ•˜๋‚˜์ด๋‹ค. ํ•ด์‹œ ์ธ๋ฑ์Šค๋Š” ๋™๋“ฑ ๋น„๊ต ๊ฒ€์ƒ‰์—๋Š” ์ตœ์ ํ™”๋ผ ์žˆ์ง€๋งŒ ๋ฒ”์œ„๋ฅผ ๊ฒ€์ƒ‰ํ•œ๋‹ค๊ฑฐ๋‚˜ ์ •๋ ฌ๋œ ๊ฒฐ๊ณผ๋ฅผ ๊ฐ€

velog.io