๐Ÿ“
til
  • TIL(Today I Learned)
  • javascript
    • value-number-string-boolean-null-undefined
    • primitive-reference
    • Hoisting
    • Prototypes in Javascript
    • this
    • prototype
    • ์ฝœ๋ฐฑํ•จ์ˆ˜ (Callback function)
    • ํ•จ์ˆ˜์˜ ํ˜ธ์ถœ
    • ์ž๋ฃŒ๊ตฌ์กฐ new keyword
    • closure
    • Promise
    • event-loop
    • array-object
    • ๊ฐ์ฒด
    • Arguments
    • higher order function
    • operators-function-control-flow
    • ๊ฐ์ฒด ์ƒ์„ฑ ํŒจํ„ด 3๊ฐ€์ง€
    • Javascript scopes
    • Functional Programming
    • Design Patterns
    • ๋ฐ์ดํ„ฐ ํƒ€์ž…
    • Object ๊ฐ์ฒด
    • ํ‘œ์ค€ ๋‚ด์žฅ ๊ฐ์ฒด์˜ ํ™•์žฅ
    • ์ฐธ์กฐ
    • ํ•จ์ˆ˜
    • ์ƒ์†(Inheritance)
    • this - 'this'๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ํ•ด๋‹น ํ•จ์ˆ˜๋ฅผ '์–ด๋–ป๊ฒŒ' ์‹คํ–‰ํ•˜๋А๋ƒ์— ๋”ฐ๋ฅธ 4๊ฐ€์ง€ this ์ •์˜
    • ์ „์—ญ๊ฐ์ฒด(Global object)
    • ๊ฐ์ฒด ์ง€ํ–ฅ ํ”„๋กœ๊ทธ๋ž˜๋ฐ
    • The 'new' keyword - Object Creation in JavaScript
  • javascript-api
    • Number
      • Number.MAX_VALUE
      • Number.isInteger
      • Number.NEGATIVE_INFINITY
      • Number.isNaN()
      • Number.POSITIVE_INFINITY
      • Number.parseFloat
      • Number.EPSILON
      • number.toExponential
      • Number.MAX_SAFE_INTEGER
      • Number1 - ์ž์—ฐ์ˆ˜, ์ •์ˆ˜, 10์ง„์ˆ˜, 2์ง„์ˆ˜, ๋ถ€๋™์†Œ์ˆ˜์ , ์‹ค์ˆ˜
      • Number.isSafeInteger()
      • Number.MIN_VALUE
      • Number.parseInt
      • Number.NaN
      • Number.isFinite()
      • Number.MIN_SAFE_INTEGER
      • toFixed
    • string.split
    • String.fromCodePoint
    • string.trimEnd
    • string.padStart
    • string.@@iterator
    • String.fromCharCode
    • string.toUpperCase
    • string.codePointAt
    • string.toLowerCase()
    • string.toString
    • string.includes
    • string.replace()
    • string.charAt
    • String.lastIndexOf
    • string.slice
    • string.search
    • string.padEnd
    • string.substring
    • string.length
    • string.trim
    • string.localeCompare
    • String.indexOf
    • string.endsWith
    • string.valueOf
    • String.raw
    • string.matchAll()
    • string.repeat
    • string.match
    • String.prototype
    • string.startsWith
    • string.charCodeAt
    • string.trimStart
    • string.concat
    • string.toLocaleUpperCase()
    • string.toLocaleLowerCase
    • String
  • learn-node
    • debugger
    • Tip
  • schema-design
    • Database Schema Design
    • Database Schema Design
  • react
    • LifeCycle
    • redux
    • Context API
    • ํ•จ์ˆ˜ํ˜• ์ปดํฌ๋„ŒํŠธ์™€ ํด๋ž˜์Šค, ์–ด๋–ค ์ฐจ์ด๊ฐ€ ์กด์žฌํ• ๊นŒ?
    • Hooks๊ณผ useEffect ์‚ฌ์šฉํ•ด ๋ณด๊ธฐ
    • Route
    • async wait ์‚ฌ์šฉํ•˜๊ธฐ
    • Hooks API Reference
    • context
    • npm uninstall ํ•˜๋Š”๋ฒ•
    • test ๋งŒ๋“ค๊ธฐ
  • tip
    • ํด๋ฆฐ์ฝ”๋“œ
    • BxSlider๋กœ ํ…์ŠคํŠธ ํ๋ฅด๋Š” ํšจ๊ณผ ๋งŒ๋“ค๊ธฐ
  • javascript30
    • Event Capture, Propagation, Bubbling and Once
    • Object and Arrays - Reference VS Copy
  • typescript
    • ์šฐ์•„ํ•œ ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ 2๋ถ€
    • The Basic Cheatsheet
    • TypeScript
    • Type Guards and Differnetiating Types
    • ์šฐ์•„ํ•œ ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ
    • Generics
  • git-from-the-hell
    • git
    • init-status-add-commit-log-stage-repository
    • log-diff
    • ๋จธ์ง€ ํ›„ branch ์‚ญ์ œํ•˜๊ธฐ
    • ์ง€์˜ฅ์—์„œ ์˜จ Git
    • reset-revert
    • develop branch ๋ฅผ pull ํ•˜๊ณ  ์‹ถ์„๋•Œ
  • conference-and-seminar
    • ๋ชจ๋˜ ํ”„๋ก ํŠธ์—”๋“œ ๊ฐœ๋ฐœํ™˜๊ฒฝ์˜ ์ดํ•ด
  • fire-base
    • Firebase .gitignore
  • vanillacoding
    • Data Structures
    • Sorting Algorithms - part 1
    • Promise
    • class
    • 04.quiz
    • 07.event-loop
    • Design Patterns
    • OOP (Object Oriented Programming)
  • etc
    • ์•Œ๊ณ ๋ฆฌ์ฆ˜ ์ฝ”๋“œ๋ฆฌ๋ทฐ
    • ์Šค์Šค๋กœ ๊ณต๋ถ€ํ•˜๋Š” ๋ฒ•
    • ๋ฐ”๋‹๋ผ์ฝ”๋”ฉ ์ˆ˜๊ฐ• ํ›„๊ธฐ
    • async ๊ณผ์ œ ํ›„๊ธฐ - ๋น„๋™๊ธฐ, ๋™๊ธฐ, ํด๋กœ์ €, ๋ฐฐ์—ด๊ณผ ๊ฐ์ฒด
    • ์œ ์šฉํ•œ ์‚ฌ์ดํŠธ
  • algorithm
    • The Supermarket Queue
    • Find the odd int
    • The Office III - Broken Photocopier
    • Directions Reduction
    • The Office II - Boredom Score
    • Divisible Sum Pairs
    • Codewars ์ด์šฉ์ž ์†”๋ฃจ์…˜ ๋ชจ์Œ
    • Shortest Word
    • find key
    • Two Sum
    • Simple Pig Latin
  • Book
    • the essence of object-orientation
      • ํƒ€์ž…๊ณผ ์ถ”์ƒํ™”
      • ๊ฐ์ฒด ์ง€๋„
      • ์ด์ƒํ•œ ๋‚˜๋ผ์˜ ๊ฐ์ฒด
      • ์ถ”์ƒํ™” ๊ธฐ๋ฒ•
      • 05. ์ฑ…์ž„๊ณผ ๋ฉ”์‹œ์ง€
      • 07.ํ•จ๊ป˜ ๋ชจ์œผ๊ธฐ
      • 04. ์—ญํ• , ์ฑ…์ž„, ํ˜‘๋ ฅ
      • ํ˜‘๋ ฅํ•˜๋Š” ๊ฐ์ฒด๋“ค์˜ ๊ณต๋™์ฒด
  • ecma-script2015
    • Object Literal Upgrades
    • default-parameter-template-literals-arrow-functions
    • spread-operator-rest-param
    • let-const-rest-parameter-spread-operator-destructuring
  • http
    • ์›น ๋ธŒ๋ผ์šฐ์ €์— URL์„ ์ž…๋ ฅํ–ˆ์„ ๋•Œ ์–ด๋–ป๊ฒŒ ์›น ํŽ˜์ด์ง€๊ฐ€ ๋ณด์—ฌ์งˆ๊นŒ?
  • jest
    • toThrow(error?)
  • data-structures
    • Data Structures
  • express
    • express generator
    • CORS
  • css-flexible-box-layout
    • flex ํ•ด๋ฒ„๋ ธ์ง€ ๋ญ์•ผ
  • git
    • Git
  • mongodb
    • MongoDB
  • markdown
    • use-markdown
  • cmder
    • cmd ๋ช…๋ น์–ด ๋ชจ์Œ
  • debug
    • trackClicksEx function error
  • npm
    • NPM TOKEN ์„ค์ •ํ•˜๊ธฐ
  • storybook
    • Storybook
  • sort
    • Sorting Algorithms - part 1
  • javascript-koans
    • Javascript Koans ์˜ค๋‹ต๋…ธํŠธ
  • rxjs
    • Rx.js
  • dom-elements
    • HTML Element
  • redux-toolkit
    • Redux Toolkit
  • github-actions
    • GitHub Actions
  • redux-middleware
    • redux middleware
  • rest
    • rest
  • css-rendering
    • ์ฝ”๋“œ ์Šคํ”ผ์ธ  - CSS Rendering 1ํšŒ์ฐจ 2/2
    • ์ฝ”๋“œ ์Šคํ”ผ์ธ  - CSS Rendering 1ํšŒ์ฐจ 1/2
  • you-dont-know-js
    • ํƒ€์ž…
  • server
    • # shutdown local server
  • semantic-versioning
    • Semantic Versioning 2.0.0
Powered by GitBook
On this page
  • Stack (Last-In First-Out)
  • Big O
  • Real Life Use Cases
  • Queue (First-In First-Out)
  • Big O
  • Real Life Use Case
  • Linked List ์—ฐ๊ฒฐ ๋ฆฌ์ŠคํŠธ
  • Big O
  • Real Life Use Case
  • Linked List vs Array
  • Tree
  • node
  • ํŠธ๋ฆฌ ์ข…๋ฅ˜
  • Real Life Use Case
  • Binary Search Tree
  • Big O - ํ‰๊ท 
  • What does the time complexity O(log n) actually mean?
  • o(n)์ด ์•„๋‹ˆ๊ณ  o(log(n))์ธ ์ด์œ 
  • Big O - ์ตœ์•…์˜ ์ƒํ™ฉ
  • Real Life Use Case
  • What is the difference between a binary tree and a binary search tree?
  • Set
  • Real Life Use Case
  • Hash Table
  • collison(์ถฉ๋Œ)
  • What is hashing?
  • Hash Function
  • Big O
  • Real Life Use Case

Was this helpful?

  1. vanillacoding

Data Structures

PreviousvanillacodingNextSorting Algorithms - part 1

Last updated 5 years ago

Was this helpful?

์ž๋ฃŒ๋ฅผ ๋‹ค๋ฃฐ๋•Œ ์‚ฌ์šฉํ•˜๋Š” ํŠน์ •ํ˜•ํƒœ - ์–ด๋–ค ์ƒํ™ฉ์ด ๊ฐ€์žฅ ์ ํ•ฉํ•œ์ง€ ์ฐพ๋Š”๋‹ค๋ฉด ์ตœ์ ํ™”๋œ ์ฝ”๋“œ๋ฅผ ์งค ์ˆ˜ ์žˆ๋‹ค. ์–ธ์–ด์— ๊ตญํ•œ๋˜์ง€ ์•Š๊ณ  ๋ณด์žฅ๋˜์–ด ์žˆ๋‹ค.

Big O๋ฅผ ํ•ญ์ƒ ์ƒ๊ฐํ•˜๊ณ  ์ฝ”๋“œ์—์„œ ๊ตฌ๋ถ„ํ•œ๋‹ค.

  • [stack](Stack-(Last-In First-Out))

  • [Queue](Queue (First-In First-Out))

Stack (Last-In First-Out)

stack

์ž๋ฃŒ๋ฅผ ์ถ”๊ฐ€ํ–ˆ๋‹ค๊ฐ€ ๋บ๋‹ค๊ฐ€ ํ•œ๋‹ค. ๋งจ ๋งˆ์ง€๋ง‰์œผ๋กœ ๋“ค์–ด๊ฐ„๊ฒŒ ์ฒซ๋ฒˆ์งธ๋กœ ๋‚˜์˜จ๋‹ค. - Last-In First-Out

  • Push: ์ž๋ฃŒ๋ฅผ ์ถ”๊ฐ€๋ฅผ ํ•œ๋‹ค. ์ฑ…์„ ์Œ“์•„๊ฐ€๋Š” ๋ฐฉ์‹์œผ๋กœ ํ•˜๋‚˜ํ•˜๋‚˜ ์Œ“์ธ๋‹ค๊ณ  ์ƒ๊ฐํ•˜์ž

  • Pop: ์ž๋ฃŒ๋ฅผ ๋บ€๋‹ค. - ์Œ“์ธ ์ฑ…์ด ์“ฐ๋Ÿฌ์ง€์ง€ ์•Š๋„๋ก ์œ„์—์„œ๋ถ€ํ„ฐ ๋นผ๋‚ธ๋‹ค.

Big O

์ˆ˜ํ•™์ ์ธ ํ‘œ๊ธฐ๋ฒ•์„ ๋งํ•œ๋‹ค. Big O๋ž€ ํ‘œ๊ธฐ๋ฒ•์˜ ํ•˜๋‚˜๋กœ ์‹œ๊ฐ„,๊ณต๊ฐ„์˜ ๋ณต์žก๋„๋ฅผ ์„ค๋ช…ํ•ด์ค€๋‹ค.

Time Complexity

Big O

์„ค๋ช…

Insertion

O(1)

๊ด„ํ˜ธ์˜ 1์€ ์ƒ์ˆ˜๋ฅผ ๋งํ•œ๋‹ค. ํ•ญ์ƒ 1์ด๋‹ค. ์‹œ๊ฐ„์ ์ธ ์†Œ์š”๊ฐ€ ํ•ญ์ƒ ๊ฐ™๋‹ค. ์˜ฌ๋ฆฌ๋ฉด ๋, ๊ทธ ์™ธ์— ๊ณ ๋ คํ•  ์‚ฌํ•ญ์ด ์ „ํ˜€์—†๋‹ค. ์—ฐ์‚ฐ์„ ํ•œ ํ›„ ์˜ฌ๋ฆฌ๋Š”๊ฒŒ ์•„๋‹ˆ๋‹ค. ์˜ฌ๋ฆฌ๋Š”๊ฒŒ ํ•ญ์ƒ ๋™์ผํ•œ ์‹œ๊ฐ„์ด ์†Œ์š”๋œ๋‹ค.

Deletion

O(1)

์ œ๊ฑฐํ•˜๋Š”๊ฑฐ ์™ธ์— ๋‹ค๋ฅธ ์‚ฌํ•ญ์€ ๊ณ ๋ คํ•  ํ•„์š”๊ฐ€ ์—†๋‹ค.

Search

O(n)

n์€ ์ƒํ™ฉ์— ๋”ฐ๋ผ ๋‹ค๋ฅด๋‹ค. stack์˜ ์‚ฌ์ด์ฆˆ. ์–ด๋””์— ์žˆ๋Š”์ง€ ์•Œ ์ˆ˜ ์—†๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.

Real Life Use Cases

  • ์žฌ๊ท€ํ•จ์ˆ˜

  • Undo/Rodo Mechanism - ์—๋””ํ„ฐ๋ฅผ ์‚ฌ์šฉํ–ˆ์„ ๋•Œ๋ฅผ ์˜ˆ์‹œ๋กœ ๋“ค ์ˆ˜ ์žˆ๋‹ค.

  • Backwards/Forwards Mechanism of Browsers

  • Call Stack

  • matching Brackets ์•Œ๊ณ ๋ฆฌ์ฆ˜ - {}() ์ด๋Ÿฐ์‹์˜ ์ง์ด ๋งž๋Š”์ง€์— ๋Œ€ํ•œ ์•Œ๊ณ ๋ฆฌ์ฆ˜

Queue (First-In First-Out)

์‚ฌ๋žŒ๋“ค์ด ์ค„์„œ๋Š”๊ฑฐ๋ž‘ ๋น„์Šทํ•˜๋‹ค.

  • Enqueue: ์•ž์—์„œ ๋ถ€ํ„ฐ ์ฐจ๋ก€๋Œ€๋กœ ์Œ“์ธ๋‹ค.

  • Dequeue: ์•ž์—์„œ ๋ถ€ํ„ฐ ์ฐจ๋ก€๋Œ€๋กœ ๋น ์ง„๋‹ค.

Big O

๋ณ€์ˆ˜๊ฐ€ ์—†๋‹ค. ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๋ณต์žก๋„๋ฅผ ํ‘œํ˜„ํ•œ๋‹ค. ์–ด๋А์ •๋„ ์‹œ๊ฐ„์ด ๊ฑธ๋ฆฌ๋Š”์ง€, ๊ณต๊ฐ„์„ ๋”ฐ์งˆ๋•Œ๋„ ์“ด๋‹ค.

Time Complexity

Big O

์„ค๋ช…

Insertion

O(1)

๋ณ€์ˆ˜๊ฐ€ ์—†๋‹ค.

Deletion

O(1)

์ค‘๊ฐ„์— ์žˆ๋Š”๊ฑธ ์‚ญ์ œํ•œ๋‹ค ํ•ด๋„ ์ฐพ๋Š”๊ฑฐ๋ž‘ ์ œ๊ฑฐํ•˜๋Š”๊ฑฐ๋ž‘ ๊ฐ™์ดํ•œ๋‹ค. ํ•˜์ง€๋งŒ ์ œ๊ฑฐ๋งŒ ์ƒ๊ฐํ•œ๋‹ค.

Search

O(n)

n์€ ์ƒํ™ฉ์— ๋”ฐ๋ผ ๋‹ค๋ฅด๋‹ค. stack์˜ ์‚ฌ์ด์ฆˆ

Real Life Use Case

  • Life of people standing for food

  • Callback queue

Linked List ์—ฐ๊ฒฐ ๋ฆฌ์ŠคํŠธ

  • next๋ฅผ ์ธ์ง€ํ•˜๊ณ  ์žˆ๋‹ค.

  • ์˜ค์ง ๋‚ด ๋’ค์— ๋ˆ„๊ฐ€ ์žˆ๋Š”์ง€ ์ธ์ง€ ํ•œ๋‹ค.

  • ์Šคํƒํ๋Š” ์ธ์ง€ํ•˜์ง€ ์•Š๋Š”๋‹ค.

  • ๋งจ ์ฒซ๋ฒˆ์งธ๋Š” head๊ณ  ๋งจ ๋งˆ์ง€๋ง‰์€ tail์ด๋ผ ๋ถ€๋ฅธ๋‹ค.

  • ๋ฐฐ์—ด๊ณผ ๋‹ค๋ฅด๋‹ค.

  • ์—ฐ๊ฒฐ๋˜์–ด ์žˆ๋‹ค.

Big O

Time Complexity

Big O

์„ค๋ช…

Insertion

O(1)

์–ด๋–ค ์ž๋ฆฌ์— ๊ฝ‚๋˜ ์•ž์˜ ๊ผฌ๋ฆฌ๋ฅผ ์—ฐ๊ฒฐํ•˜๊ณ  ๋’ค์— ๊ผฌ๋ฆฌ๋ฅผ ์—ฐ๊ฒฐํ•œ๋‹ค.

Deletion

O(1)

์‚ญ์ œํ•œ ํ›„ ์•ž์˜ ๊ผฌ๋ฆฌ์™€ ๋’ค์˜ ๊ผฌ๋ฆฌ๋ฅผ ์—ฐ๊ฒฐํ•œ๋‹ค.

Search

O(n)

์•ž์—์„œ๋ถ€ํ„ฐ ์‹œ์ž‘ํ•œ๋‹ค. next๋ฅผ ๊ธฐ์–ตํ•˜๊ณ  ์žˆ๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.

Real Life Use Case

  • The history section of web browers

  • Line of people standing for food

Linked List vs Array

์ฐจ์ด

Array

Linked List

์ ‘๊ทผ

index๋ฅผ ํ†ตํ•ด ๋น ๋ฅด๊ฒŒ ์ ‘๊ทผ

Array๋ณด๋‹ค ๋А๋ฆฌ๋‹ค.

์‚ฝ์ž… ์‚ญ์ œ

๋А๋ฆฌ๋‹ค

๋น ๋ฆ„

ํฌ๊ธฐ

๊ณ ์ •

์œ ๋™์ 

๋ฉ”๋ชจ๋ฆฌ ์š”๊ตฌ ์‚ฌํ•ญ

์ธ๋ฑ์Šค์— ์‹ค์ œ ๋ฐ์ดํ„ฐ๊ฐ€ ์ €์žฅ๋˜๊ธฐ ๋•Œ๋ฌธ์— ์ ๋‹ค.

์ด์ „๊ณผ ๋‹ค์Œ์„ ์ฐธ์กฐํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋” ๋งŽ์€ ๋ฉ”๋ชจ๋ฆฌ๊ฐ€ ํ•„์š”ํ•˜๋‹ค.

์žฅ์ 

  • ๋™์  ํฌ๊ธฐ

  • ๊ฐ„ํŽธํ•œ ์‚ฝ์ž…/์‚ญ์ œ (๋ฐฐ์—ด์€ ์ƒˆ๋กœ์šด ์š”์†Œ๋ฅผ ์‚ฝ์ž…ํ•˜๋Š” ๊ฒƒ์€ cost๊ฐ€ ๋งŽ์ด ๋“ ๋‹ค.)

๋‹จ์ 

  • ์ˆœ์ฐจ์ ์œผ๋กœ ์—‘์„ธ์Šค ํ•ด์•ผํ•œ๋‹ค.

  • ๋ฉ”๋ชจ๋ฆฌ๊ฐ€ ์š”๊ตฌ๋œ๋‹ค.

Tree

  • ๋ถ€๋ชจ ์ž์‹ ๊ด€๊ณ„๋ฅผ ๊ฐ€์ง„๋‹ค.

  • ๊ณ„์ธต์ด๊ณ  ๊ทธ๋ฃน์„ ๊ฐ€์ง„๋‹ค.

  • node๋Š” ํ•˜๋‚˜ ์ด์ƒ์˜ child๋ฅผ ๊ฐ€์ง„๋‹ค.

  • ๋ถ€๋ชจ๋ฅผ ์•„๋Š” ๊ฒฝ์šฐ๋„ ์žˆ๊ณ  ์ž์‹๋งŒ ์•„๋Š” ๊ฒฝ์šฐ๋„ ์žˆ๋‹ค.

  • ํŠน์ •ํ•œ ์ˆœ์„œ๊ฐ€ ์žˆ์„ ์ˆ˜๋„ ์—†์„ ์ˆ˜๋„ ์žˆ๋‹ค.

  • ์‹œ์ž‘์ ์„ Root๋ผ๊ณ  ํ•œ๋‹ค.

  • ๋”์ด์ƒ ์ž์‹์ด ์—†๋Š” ๊ฒฝ์šฐ leap ์žŽ์‚ฌ๊ท€๋ผ ๋ถ€๋ฅธ๋‹ค.

node

  • ํ•˜๋‚˜์˜ ๊ตฌ์„ฑ์š”์†Œ (์–ด๋””์„œ๋“ ์ง€ ์“ฐ์ผ ์ˆ˜ ์žˆ๋‹ค.)

ํŠธ๋ฆฌ ์ข…๋ฅ˜

  • Binary Tree(์ด์ง„ํŠธ๋ฆฌ): ์ž์‹์„ ๋‘๊ฐœ๊นŒ์ง€ ๊ฐ–๋Š”๋‹ค.

  • Ternary Tree: ์„ธ๊ฐœ

  • Binary Search Tree(์ด์ง„๊ฒ€์ƒ‰ํŠธ๋ฆฌ):

    • ์ž์‹์„ ์ตœ๋Œ€ ๋‘๊ฐœ๊นŒ์ง€ ๊ฐ€์งˆ ์ˆ˜ ์žˆ๋‹ค.

    • ์™ผ์ชฝ์ž์‹๋…ธ๋“œ๋Š” ๋ถ€๋ชจ๋…ธ๋“œ๋ณด๋‹ค ์ž‘์•„์•ผ ํ•˜๊ณ  ์˜ค๋ฅธ์ชฝ์ž์‹๋…ธ๋“œ๋Š” ์ปค์•ผํ•œ๋‹ค.

    • ์™ผ์ชฝ๋ถ€ํ„ฐ ์ฑ„์›Œ๋‚˜๊ฐ„๋‹ค.

  • Perfect Binary Tree: ์™„๋ฒฝ์“ฐ

Real Life Use Case

  • ํšŒ์‚ฌ๋‚˜ ์ •๋ถ€์˜ ์กฐ์ง ๊ตฌ์กฐ

  • ๋‚˜๋ผ, ์ง€๋ฐฉ, ์‹œโ€ข๊ตฐ๋ณ„, ๊ณ„์ธต์ ์ธ ๋ฐ์ดํ„ฐ์˜ ์ €์žฅ

  • ์ปดํ“จํ„ฐ ํŒŒ์ผ ์‹œ์Šคํ…œ๊ณผ ๊ฐ™์ด ๊ณ„์ธต์„ ํ˜•์„ฑํ•˜๋Š” ์ •๋ณด๋ฅผ ์ €์žฅํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉ

  • DOM

  • File System

Hierarchical Data(๊ณ„์ธต๊ตฌ์กฐ)๊ฐ€ ํŠน์ง•์ด๋‹ค.

Binary Search Tree

Big O - ํ‰๊ท 

Time Complexity

Big O

์„ค๋ช…

Insertion

O(log(n))

๋ฐ˜๋ฐ˜๋ฐ˜๋ฐ˜๋ฐ˜ ์ž˜๋ผ๋‚˜๊ฐ€๋ฉด์„œ ์ฐพ๋Š”๋‹ค.

Deletion

O(log(n))

Search

O(log(n))

What does the time complexity O(log n) actually mean?

o(n)์ด ์•„๋‹ˆ๊ณ  o(log(n))์ธ ์ด์œ 

ํŠธ๋ฆฌ๋Š” ์ „์ฒด๊ฐ€ ์œ ๊ธฐ์ฒด๋ผ ์„œ๋กœ ๋–ผ๋†“์„ ์ˆ˜ ์—†๋Š” ๊ด€๊ณ„์ด๊ธฐ ๋•Œ๋ฌธ์— o(log(n));

์‚ญ์ œํ•  ๋•Œ ๋ฃจํŠธ์™€ ๊ณ„์† ๊ฐ’์„ ๋น„๊ตํ•ด์•ผํ•˜๊ธฐ ๋•Œ๋ฌธ์— ํ•˜๋‚˜์˜ ์œ ๊ธฐ์ฒด๋ผ๊ณ  ํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒƒ์ด๋‹ค.

Big O - ์ตœ์•…์˜ ์ƒํ™ฉ

Time Complexity

Big O

Insertion

O(n)

Deletion

O(n)

Search

O(n)

ํŠธ๋ฆฌ๊ฐ€ ์–‘์ชฝ์œผ๋กœ ๋‚˜๋‰˜์–ด์ ธ ์žˆ๋Š”๊ฒŒ ์•„๋‹ˆ๋ผ ์ผ๋ ฌ๊ณผ ๋น„์Šทํ•œ ๋ชจ์–‘์„ ๊ฐ€์งˆ๋•Œ์ด๋‹ค.

Real Life Use Case

  • ์ˆœ์„œ๊ฐ€ ์žˆ๋Š” ์ž๋ฃŒ - ํ‚ค ์ˆœ์„œ

AVL Tree, Red Black Tree(trie) - ํ•œ์ชฝ์œผ๋กœ๋งŒ ์ ๋ฆฌ๋Š” ์ƒํ™ฉ์„ ํ”ผํ•  ์ˆ˜ ์žˆ๋‹ค. self-balancing์„ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค.

What is the difference between a binary tree and a binary search tree?

  • binary tree - ์ž์‹์„ ๋‘๊ฐœ ๊นŒ์ง€ ๊ฐ–๋Š”๋‹ค.

  • binary search tree - ์™ผ์ชฝ์ด ์ž‘์€๊ฐ’, ์˜ค๋ฅธ์ชฝ์ด ํฐ ๊ฐ’์„ ๊ฐ–๋Š”๋‹ค.

Set

  • ์ˆœ์„œ๊ฐ€ ์—†๋‹ค. ์˜ค์ง ์ž๋ฃŒ๊ฐ€ ์žˆ๋ƒ ์—†๋ƒ๋งŒ ์ค‘์š”ํ•˜๋‹ค.

  • ์ง‘ํ•ฉ์ด๋ฏ€๋กœ ์ค‘๋ณต๋œ ๋ฐ์ดํ„ฐ๊ฐ€ ๋“ค์–ด๊ฐˆ ์ˆ˜ ์—†๋‹ค.

  • ์ค‘๋ณต๋˜์ง€ ์•Š์€ ์ˆซ์ž(๋ฐ์ดํ„ฐ)๋ฅผ ๊ตฌํ•  ๋•Œ ์‚ฌ์šฉํ•˜๋ฉด ์œ ์šฉํ•˜๋‹ค.

  • ๋น ๋ฅธ ์†๋„

Real Life Use Case

  • ํ•˜๋ฃจ ์ ‘์†์ž ์นด์šดํŠธ - ์ค‘๋ณต๋œ ip๋Š” ์‚ญ์ œํ•œ๋‹ค.

Hash Table

Extrememly Important - ๊ฐ€์žฅ ์ค‘์š”ํ•œ ๊ฒƒ ์ค‘์— ํ•˜๋‚˜๋‹ค.

F(key) -> HashCode -> Index ->  Value
  1. hsah Table ํ•จ์ˆ˜(F(key))๋ฅผ ๋„ฃ๊ณ  ๋ฐ˜ํ™˜ ๋ฐ›์€๊ฒƒ์ด HashCode

  2. HashCode๋ฅผ ์ €์žฅ์†Œ์˜ Index๋กœ ํ™˜์‚ฐ์„ ํ•ด์„œ ->

  3. ๋ฐ์ดํ„ฐ์— ์ ‘๊ทผํ•˜๋Š” ์ž๋ฃŒ๊ตฌ์กฐ์ด๋‹ค.

key: ๋ฌธ์ž๋‚˜ ํŒŒ์ผ๋ฐ์ดํ„ฐ๋‚˜ ์ˆซ์ž ๋“ฑ์ด ๋  ์ˆ˜ ์žˆ๋‹ค.

์žฌ์ •๋ฆฌ

  1. ๋ฐ์ดํ„ฐ๊ฐ€ ์žˆ๋‹ค.

    1. ํ•ด์‹œ ํ•จ์ˆ˜๋ฅผ ํ†ตํ•ด ํ•จ์ˆ˜์•ˆ์— ๊ทœ์น™,์•Œ๊ณ ๋ฆฌ์ฆ˜์œผ๋กœ ๋ฐ์ดํ„ฐ๋“ค์€ Hash Code๋ฅผ ๊ฐ–๋Š”๋‹ค.

    2. ํ•ด์‹œ์ฝ”๋“œ๋Š” index๊ฐ€ ๋˜์–ด ์ž๋ฃŒ๋ฅผ ์ฐพ๋Š”๋‹ค.

  • key ๊ฐ’์ด ์–ผ๋งˆ๋‚˜ ํฐ์ง€ ์ƒ๊ด€์—†์ด ๋™์ผํ•œ HashCode๋กœ ๋งŒ๋“ค์–ด ์ค€๋‹ค.

๋ชจ๋“  ์‚ฌ๋žŒ๋“ค์ด ๋ชจ๋“  ๊ฑฐ๋ž˜์žฅ๋ถ€๋ฅผ ๋‹ค ๊ฐ–๊ณ  ์žˆ๋‹ค. ๊ทธ๊ฑด ๋„ˆ๋ฌด ํฌ๊ธฐ๋•Œ๋ฌธ์— HashCode๋กœ ๊ฐ€์ง€๊ณ  ์žˆ๋Š”๋‹ค.

Hash Algorithm

  • ๋ฐฉ์„ ๋‚˜๋ˆŒ๋•Œ ๋…ธ๋Š” ๋ฐฉ์ด ์—†๋„๋ก ๋ฐฉ์„ ์ž˜ ๋งŒ๋“ค์–ด์•ผ ํ•œ๋‹ค.

collison(์ถฉ๋Œ)

 ๊ฒ€์ƒ‰์‹œ๊ฐ„์ด O(1) ๋งŒํผ ๊ฑธ๋ฆฌ๋Š”๋ฐ ๋ฐฉ์„ ์ž˜๋ชป๋งŒ๋“ค๋ฉด(collison์ด ๋งŽ์„ ๊ฒฝ์šฐ) O(n)๋งŒํผ ๊ฑธ๋ฆฐ๋‹ค.

์„œ๋กœ๋‹ค๋ฅธ key๊ฐ’์œผ๋กœ ๋™์ผํ•œ hashcode๋ฅผ ๋งŒ๋“ค๊ธฐ๋„ ํ•œ๋‹ค. ์™œ๋ƒ๋ฉด hashcode๋Š” ์œ ํ•œํ•˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.

๋‹ค๋ฅธ ์ฝ”๋“œ์ง€๋งŒ ๊ฐ™์€ index๋ฐฉ์„ ๋ฐ›์„ ์ˆ˜ ์žˆ๋‹ค.

์žฅ์ 

  • ๊ฒ€์ƒ‰์†๋„๊ฐ€ ๋งค์šฐ ๋น ๋ฅด๋‹ค.

    • ํ•ด์‹œํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•ด์„œ ๋งŒ๋“  ํ•ด์‹œ์ฝ”๋“œ๋Š” ์ •์ˆ˜๋‹ค. ๋ฐฐ์—ด๊ณต๊ฐ„์„ ๊ณ ์ •๋œ ํฌ๊ธฐ๋งŒํผ ๋งŒ๋“ ๋‹ค. ํ•ด์‹œ์ฝ”๋“œ๋ฅผ ๋ฐฐ์—ด์˜ ๋‚˜๋จธ์ง€์—ฐ์‚ฐ์„ ํ•œ ๋งŒํผ ๋‚˜๋ˆ  ๊ฐ–๋Š”๋‹ค.

    • ํ•ด์‹œ์ฝ”๋“œ ์ž์ฒด๊ฐ€ ๋ฐฐ์—ด๋ฐฉ์˜ index๋กœ ์‚ฌ์šฉ๋œ๋‹ค.

    • ๋ฐฐ์—ด์— ํ•ด์‹œ์ฝ”๋“œ๋กœ ๋ฐ”๋กœ ๋‹ค์ด๋ ‰ํŠธ๋กœ ์ ‘๊ทผํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋น ๋ฅด๋‹ค.

๋‹จ์ 

  • ๋žœ๋คํ•˜๊ฒŒ ๋„ฃ๊ธฐ ๋•Œ๋ฌธ์— ๊น”๋”ํ•˜๊ฒŒ ์ •๋ฆฌ๋˜์ง€ ์•Š๋Š”๋‹ค.

  • ๊ณต๊ฐ„ํšจ์œจ์„ฑ์ด ๋–จ์–ด์ง„๋‹ค. ๊ณต๊ฐ„ํฌ๊ธฐ๋ฅผ ๋ฌด์กฐ๊ฑด ์ •ํ•ด์•ผํ•œ๋‹ค.

    • ์‚ฌ๋žŒ, ์ž๋ฆฌ๋กœ ์ƒ๊ฐํ•˜๋ฉด ์‚ฌ๋žŒ < ์ž๋ฆฌ๊ฐ€ ํ•ญ์ƒ ์ปค์•ผํ•˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.

  • Hash Function์˜ ์˜ค์กด๋„๊ฐ€ ๋†’๋‹ค.

What is hashing?

๋ฌธ์ž์—ด์„ ๋ฐ›๊ณ  ์ •ํ•ด์ง„ ๊ธธ์ด์˜ ์•„์›ƒํ’‹์„ ์ค€๋‹ค.

ex) MD5, SHA and etc.. ์œ ๋ช…ํ•œ ํ•ด์‰ฌ/ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ์ด๋ฆ„์ด๋‹ค.

Hash Function

  • ํ•ด์‹œํ•จ์ˆ˜๋Š” Idempotent ์—ฌ์•ผ ํ•œ๋‹ค.

function hash (k) {
  return 2 * k;
}

์ธํ’‹์— ๊ด€ํ•ด ๊ฐ™์€ ์•„์›ƒํ’‹์ด ๋‚˜์™€์•ผ ํ•œ๋‹ค.

  • good distribution of values

    • ํ™•๋ณดํ•œ ๊ณต๊ฐ„์„ ๊ณ ๋ฃจ๊ณ ๋ฃจ ์ž˜ ์ด์šฉํ•ด์•ผ ํ•œ๋‹ค.

  • needs to be performant O(1) ์ด๋ผ๋Š” ์˜๋ฏธ๊ฐ€ ํ™•์‹คํ•˜๋„๋ก ํ•ด์•ผํ•œ๋‹ค.

Big O

Time Complexity

Big O

์„ค๋ช…

Insertion

O(1)

์–ด๋–ค ์ƒํ™ฉ์ด๋˜ ๋ณ€ํ•˜์ง€ ์•Š๊ณ  ๋„์ถœํ•œ ์‹œ๊ฐ„์ด ํ•ญ์ƒ ๋™์ผํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์–ธ์ œ๋‚˜ 0(1) ex) ๋ฃจํ”„๋ฅผ ์—ฌ๋Ÿฌ๋ฒˆ ๋Œ๋ ค๋„ ํ•ญ์ƒ ๋™์ผํ•œ ์‹œ๊ฐ„์ด๊ธฐ ๋•Œ๋ฌธ์— O(1)

Deletion

O(1)

Search

O(1)

Real Life Use Case

  • ์ฃผ์†Œ๋ก

    • ๋žœ๋คํ•˜๊ฒŒ ์ €์žฅํ–ˆ๋‹ค๊ฐ€ ๋ฝ‘์•„ ์˜ฌ ์ˆ˜ ์žˆ์–ด์•ผ ํ•œ๋‹ค.

    • ๊ฐœ๋ณ„์ ์œผ๋กœ ๊ด€๊ณ„๊ฐ€ ์—†๋‹ค. ๋™์ผ ์ด๋ฆ„์€ ์ถฉ๋Œํ•  ์ˆ˜ ์žˆ๋‹ค.

  • ๋ธ”๋ก์ฒด์ธ

  • ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋กœ ๊ฐ์ฒด๋กœ ๋งŒ๋“ค์—ˆ์„๋•Œ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ์‹คํ–‰ ์—”์ง„์—์„œ key์™€ value๋ฅผ ํ•ด์‹œํŽ‘์…˜์œผ๋กœ ๊ตฌํ˜„๋˜์–ด ์žˆ๋‹ค.

  • ์œ ํŠœ๋ธŒ์— ์˜์ƒ์„ ๋‹ค์šด ๋ฐ›์•„์„œ ์˜ฌ๋ฆฐ๋‹ค๋ฉด

์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋กœ ํ•ด์‹œํ…Œ์ด๋ธ”๋กœ ๊ตฌํ˜„ํ•˜๋Š” ๊ฒฝ์šฐ๋Š” ์—†๋‹ค.

Queue

hash table

์ด๋ฏธ์ง€ ์ถœ์ฒ˜ - w3schools
์ฐธ๊ณ  ๋งํฌ
link
link
์ถœ์ฒ˜ - wikipedia
Linked List
Tree
Hash Table
linked-list