Skip to content

Latest commit

ย 

History

History

03. Searching

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
ย 
ย 

Searching

Contents


Trees

  • Tree Terminology

    แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2021-12-10 - แ…ฉแ„’แ…ฎ 2 37 10
Terminology Explain Example
Root node without parent A
Child if node u is the parent of node v, v is a child of u A
Internal node node with at least one child A, B, C, F
External node (=Leaf) node without children E, I, J, K, G, H, D
Ancestors of a node parent, grandparent, great-grandparent, etc.
Siblings of a node Any node which shares a parent
Depth of a node number of ancestors (๋…ธ๋“œ์˜ ์†์„ฑ) K์˜ ๊ฒฝ์šฐ, A, B, F์ด๋ฏ€๋กœ 3
Height of a tree maximum depth of any node (ํŠธ๋ฆฌ์˜ ์†์„ฑ) 3
Descendant of a node child, grandchild, great-grandchild, etc.
Subtree tree consisting of a node and its descendants (๋ถ€๋ถ„์ง‘ํ•ฉ ๊ฐ™์€ ๊ฐœ๋…)
Degree number of children of a node (ํŠธ๋ฆฌ์˜ ์†์„ฑ) F์˜ ๊ฒฝ์šฐ, I, J, K์ด๋ฏ€๋กœ 3
Edge a pair of node (u, v) such that u is a parent of v((C, H))
Path A sequence of nodes such that any two consecutive nodes form an edge A, B, F, J
Ordered tree a tree with a linear ordering defined for the children of each node

1) Preorder Traversal (P-L-R)

  • A traversal visits the nodes of a tree in a systematic manner
  • search ๋ž‘์€ ๋‹ค๋ฅด๋‹ค. (๋ชจ๋“  node๋“ค์„ ์ฐพ์•„๊ฐ€๋Š” ๊ทœ์น™)

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2021-12-12 - แ…ฉแ„’แ…ฎ 8 55 54

  • In a preorder traversal, a node is visited before its descendants
  • Application: print a structured document
Algorithm preOrder(T,p)
  visit(p)
  for each child q of p
    preOrder(T,q)

2) Postorder Traversal (L-P-R)

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2021-12-12 - แ…ฉแ„’แ…ฎ 8 57 09

  • In a post order traversal, a node is visited after its descendants
  • Application: compute space used by files in a directory and its subdirectories
Algorithm postOrder(T,p)
  for each child q of p
    postOrder(T,q)
  visit(p)

3) In-order Traversal

  • In an inorder traversal, a node is visited after its left subtree and before its right subtree
  • Application: draw a binary tree
    • x(v) = inorder rank of v
    • y(v) = depth of v
Algorithm inOrder(T,p)
  if ยฌp.isExternal()
    inOrder(T,p.left())
  visit(p)

  if ยฌp.isExternal()
    inOrder(T,p.right())

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2021-12-12 - แ…ฉแ„’แ…ฎ 8 51 32

4) Euler Tour Traversal

  • Generic traversal of a binary tree
  • Includes as special cases the preorder, postorder and inorder traversals
  • Walk around the tree and visit each node three times: (ํ•œ ๋…ธ๋“œ๋ฅผ 3๋ฒˆ ๋ฐ˜๋ณต)
    • on the left (preorder)
    • from below (inorder)
    • on the right (postorder)
  • ํ•œ๋ถ“๊ทธ๋ฆฌ๊ธฐ ๋Š๋‚Œ
Algorithm eulerTour(T,p)
  visit(p) on the left // preOrder
  if ยฌp.isExternal()
    eulerTour(T,p.left())
  visit(p) from below // inOrder
  if ยฌp.isExternal()
    eulerTour(T,p.right())
  visit(p) on the right // postOrder

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2021-12-13 - แ…ฉแ„Œแ…ฅแ†ซ 11 32 22

์ด์ง„ ํŠธ๋ฆฌ (Binary Tree)

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2021-12-12 - แ…ฉแ„’แ…ฎ 4 55 28

  • A binary tree is a tree with the following properties:
    • Each internal node has at most two children
      (exactly two for proper binary trees)
      • degree = 2
    • The children of a node are an ordered pair
  • We call the children of an internal node left child and right child
  • Are cursive definition
    • A binary tree is either empty or consists of:
      • A node r,called the root of T and storing an element
      • A binary tree, called the left subtree of T
      • A binary tree, called the right subtree of T
  • Applications:
    • arithmetic expressions
    • decision processes
    • searching

Properties of Binary Trees

  • Notation

    • n: number of nodes
    • e: number of external nodes
    • i: number of internal nodes
    • h: height
  • Properties

    • e = i + 1 (์™ธ๋ถ€๋…ธ๋“œ ์ˆ˜ = ๋‚ด๋ถ€๋…ธ๋“œ ์ˆ˜ + 1)
    • n = 2e - 1
    • h <= i
    • h <= (n - 1)/2
    • e <= 2^h
    • h >= log_2(e)
    • h >= log_2(n + 1) - 1

Arithmetic Expression Tree

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2021-12-12 - แ…ฉแ„’แ…ฎ 4 55 55

  • Binary tree associated with an arithmetic expression
    • Internal nodes: operators
    • External nodes(leaves): operands

์ด์ง„ ํƒ์ƒ‰ ํŠธ๋ฆฌ (Binary Serarch Tree)

  • A binary search tree is a binary tree storing keys (or key-value entries) at its internal nodes and satisfying the following property:
    • Let u, v, and w be three nodes such that u is in the left subtree of v and w is in the right subtree of v. We have
    • key(u) <= key(v) <= key(w)
  • External nodes do not store items
  • An inorder traversal of a binary search trees visits the keys in increasing order

Search

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2021-12-14 - แ…ฉแ„’แ…ฎ 5 04 25

  • To search for a key k, we trace a downward path starting at the root
  • The next node visited depends on the comparison of k with the key of the current node
  • If we reach a leaf, the key is not found and we return a null position
Algorithm TreeSearch(k, u)
  if u.isExternal()
    return u

  if k < u.key()
    return TreeSearch(k, u.left())
  else if k = u.key()
    return u
  else // k > u.key()
    return TreeSearch(k, u.right())

BST์—์„œ์˜ Insertion

์ฐธ๊ณ  : https://new93helloworld.tistory.com/115?category=691027

  • Step 1) Find k
  • Step 2) Insert k
  • Example:
    • แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2021-12-14 - แ…ฉแ„’แ…ฎ 6 57 25
  • Assume k is not already in the tree, and let w be the leaf reached by the search
  • We insert k at node w and expand w into an internal node
public:
    void insertItem(const Key& k, const Element& e) // insert (key, element)
        { inserter(k, e); }
protected:
    BTPosition inserter(const Key& k, const Element& e) { // insert utillity
        BTPosition p = finder(k, T.root()); // find insertion spot
        // ๋‚ด๋ถ€๋…ธ๋“œ์ธ ๊ฒฝ์šฐ
        while (T.isInternal(p)) // key already exists?
            // look further
            p = finder(k, T.rightChild(p)); // leftChild๋กœ ํ•ด๋„ ์•„๋ฌด ์ƒ๊ด€ ์—†์Œ
        // ์™ธ๋ถ€๋…ธ๋“œ์ธ ๊ฒฝ์šฐ
        T.expandExternal(p); // add new node here
        setItem(p, BSTItem(k, e)); // store (key, element)
        return p;
    }

Example: Insertion

  • put(5,"A")

    • แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2021-12-14 - แ…ฉแ„’แ…ฎ 5 07 02
  • Inserting an entry with key 78

    • แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2021-12-14 - แ…ฉแ„’แ…ฎ 5 08 48

Removal

์ฐธ๊ณ  : https://new93helloworld.tistory.com/116?category=691027

  • To perform operation erase(k), we search for key k
  • Assume key k is in the tree, and let v be the node storing k
  • If node v has a leaf child w, we remove v and w from the tree with operation removeAboveExternal(w), which removes w and its parent
    • An example operation of removeAboveExternal(w)
    • แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2021-12-14 - แ…ฉแ„’แ…ฎ 5 12 53
public:
    // remove using key
    void removeElement(const Key& k) throw(NonexistentElementException) {
        BTPosition p = finder(k, T.root()); // find the node
        if (p.isNull()) // not found?
            throw NonexistentElementException("Remove nonexistent element");
        remover(p); // remove it
    }
protected:
    BTPosition remover(const BTPosition& r) { // remove utility
        BTPosition p;
        if (T.isExternal(T.leftChild(r))) // left is external?
            p = T.leftChild(r); // remove from left
        else if (T.isExternal(T.rightChild(r))) // right is external?
            p = T.rightChild(r); // remove from right
        else {
            p = T.rightChild(r); // p = replacement
            do
                p = T.leftChild(p); // ... right subtree
            while (T.isInternal(p));
            setItem(r, T.parent(p).element()); // copy parent(p) to r
        }
        return T.removeAboveExternal(p); // remove p and parent
    }

Example: Removal

erase(4)

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2021-12-14 - แ…ฉแ„’แ…ฎ 5 57 47

Removing an entry with key 32

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2021-12-14 - แ…ฉแ„’แ…ฎ 5 58 38

Removal (cont.)

  • We consider the case where the key k to be removed is stored at a node v whose children are both internal
    • we find the internal node w that follows v in an inorder traversal
    • we copy key(w) into node v
    • we remove node w and its left child z (which must be a leaf) by means of operation removeAboveExternal(z)

Example: Removal

erase(3)

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2021-12-14 - แ…ฉแ„’แ…ฎ 6 15 50

Removing an entry with key 65

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2021-12-14 - แ…ฉแ„’แ…ฎ 6 17 30

Performance

  • The height h is O(n) in the worst case
  • Consider an ordered map with n items implemented by means of a binary search tree of height h
    • Functions find, put and erase take O(h) = O(n) time
  • Functions size, empty take O(1)

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2021-12-14 - แ…ฉแ„’แ…ฎ 6 50 59

๊ท ํ˜• ํŠธ๋ฆฌ (Balanced Tree)

  • Balanced์˜ ์ •์˜ : ๋ชจ๋“  leaf node๋“ค์ด ๊ฐ™์€ level์— ์žˆ๋Š” ์ƒํƒœ
  • Balanced Tree์˜ ์ •์˜ : ์ž„์˜์˜ ๋…ธ๋“œ์—์„œ ํŒŒ์ƒ๋˜๋Š” ์ขŒ์šฐ์˜ ๋ถ€๋ถ„ํŠธ๋ฆฌ์˜ ๋…ธ๋“œ ์ˆ˜๊ฐ€ ์ตœ๋Œ€ 1 ๋ฐ–์— ํ‹€๋ฆฌ์ง€ ์•Š๋Š” ํŠธ๋ฆฌ

  • ์ด์ง„ ํŠธ๋ฆฌ ์•Œ๊ณ ๋ฆฌ์ฆ˜
    • ์ตœ์•…์˜ ๊ฒฝ์šฐ ์„ฑ๋Šฅ์ด ๋‚˜์จ
      • ์ •๋ ฌ๋œ ํŒŒ์ผ ๋˜๋Š” ์—ญ์ˆœ์œผ๋กœ ์ •๋ ฌ๋œ ํŒŒ์ผ, ํฐ ํ‚ค์™€ ์ž‘์€ ํ‚ค๊ฐ€ ๊ต๋Œ€๋กœ ๋‚˜์˜ค๋Š” ํŒŒ์ผ
  • ์„ฑ๋Šฅ ๊ฐœ์„ 
    • ํ€ต ์ •๋ ฌ์˜ ๊ฒฝ์šฐ ์„ฑ๋Šฅ ๊ฐœ์„  ๋ฐฉ๋ฒ•์€ ํ™•๋ฅ ์— ์˜ํ•ด ์ž„์˜์˜ ๋ถ„ํ•  ์›์†Œ๋ฅผ ์„ ํƒํ•˜๋Š” ์ˆ˜ ๋ฐ–์— ์—†์Œ
    • ์ด์ง„ ํŠธ๋ฆฌ ํƒ์ƒ‰์˜ ๊ฒฝ์šฐ์—๋Š” ํŠธ๋ฆฌ๋ฅผ ๊ท ํ˜• ์žˆ๊ฒŒ ์œ ์ง€ํ•˜๋ฉด ์ตœ์•…์˜ ์ƒํ™ฉ์„ ํ”ผํ•  ์ˆ˜ ์žˆ์Œ
    • ์ผ๋ฐ˜์ ์ธ ๊ฐœ๋…์€ ์‰ฝ๊ฒŒ ๊ธฐ์ˆ ํ•  ์ˆ˜ ์žˆ์ง€๋งŒ, ์‹ค์ œ ๊ตฌํ˜„์—์„œ๋Š” ํŠน์ˆ˜ํ•œ ์ƒํ™ฉ์„ ๊ณ ๋ คํ•ด์•ผ ํ•จ

2-4 Tree

  • Visualization : 2-3-4 tree (์ดˆ๊ธฐ ๋กœ๋”ฉ๋Š๋ฆผ ์ฃผ์˜)

  • A (2,4) tree (also called 2-4 tree or 2-3-4 tree) is a multi-way search with the following properties

    • Node-Size Property
      • every internal node has at most four children
    • Depth Property
      • all the external nodes have the same depth
  • Depending on the number of children, an internal node of a (2,4) tree is called a 2-node, 3-node or 4-node

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2022-04-18 - แ…ฉแ„Œแ…ฅแ†ซ 1 37 22

Red-Black Tree

A red-black tree is a representation of a (2,4) tree by means of a binary tree whose nodes are colored red or black

Hashing

  • ๋ชจ๋“  ํ‚ค์˜ ๋ ˆ์ฝ”๋“œ๋ฅผ ์‚ฐ์ˆ  ์—ฐ์‚ฐ์— ์˜ํ•ด ํ•œ ๋ฒˆ์— ๋ฐ”๋กœ ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋Š” ๊ธฐ๋ฒ•
  • ํ•ด์‹ฑ์˜ ๋‹จ๊ณ„
    • ํ•ด์‹œ ํ•จ์ˆ˜(hash function)๋ฅผ ํ†ตํ•ด ํƒ์ƒ‰ ํ‚ค๋ฅผ ํ•ด์‹œ ํ…Œ์ด๋ธ” ์ฃผ์†Œ๋กœ ๋ณ€ํ™˜
    • ๊ฐ™์€ ํ…Œ์ด๋ธ” ์ฃผ์†Œ๋กœ ์‚ฌ์ƒ๋˜์—ˆ์„ ๊ฒฝ์šฐ์—๋Š” ์ถฉ๋Œ์„ ํ•ด๊ฒฐ(collision-resolution)ํ•ด์•ผ ํ•จ

ํŠน์ง•

  • ์‹œ๊ฐ„๊ณผ ๊ณต๊ฐ„์˜ ๊ท ํ˜•
    • ๋ฉ”๋ชจ๋ฆฌ์˜ ์ œํ•œ์ด ์—†์„ ๊ฒฝ์šฐ : ํ‚ค๋ฅผ ๋ฉ”๋ชจ๋ฆฌ ์ฃผ์†Œ๋กœ ์‚ฌ์šฉํ•˜๋ฉด ์–ด๋–ค ํƒ์ƒ‰์ด๋“ ์ง€ ํ•œ ๋ฒˆ์˜ ๋ฉ”๋ชจ๋ฆฌ ์ ‘๊ทผ์œผ๋กœ ์ˆ˜ํ–‰ ๊ฐ€๋Šฅ
    • ์‹œ๊ฐ„์— ์ œํ•œ์ด ์—†์„ ๊ฒฝ์šฐ : ์ตœ์†Œํ•œ์˜ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ฐ์ดํ„ฐ๋ฅผ ์ €์žฅํ•˜๊ณ  ์ˆœ์ฐจ ํƒ์ƒ‰
  • ํ•ด์‹ฑ์€ ์ด๋Ÿฌํ•œ ๋‘ ๊ทน๋‹จ ์‚ฌ์ด์—์„œ ํ•ฉ๋ฆฌ์ ์ธ ๊ท ํ˜•์„ ์ด๋ฃฐ ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ•์„ ์ œ๊ณต
  • ํ•ด์‹ฑ์„ ์‚ฌ์šฉํ•˜๋Š” ๋ชฉ์ ์€ ๊ฐ€์šฉํ•œ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ํšจ๊ณผ์ ์œผ๋กœ ์‚ฌ์šฉํ•˜๋ฉด์„œ ๋น ๋ฅด๊ฒŒ ๋ฉ”๋ชจ๋ฆฌ์— ์ ‘๊ทผํ•˜๊ธฐ ์œ„ํ•จ

ํ•ด์‹ฑ๊ณผ ์ด์ง„ ํŠธ๋ฆฌ

  • ์ด์ง„ ํŠธ๋ฆฌ๋ณด๋‹ค ํ•ด์‹ฑ์„ ๋งŽ์ด ์‚ฌ์šฉํ•˜๋Š” ์ด์œ 
    • ๊ฐ„๋‹จํ•จ
    • ์•„์ฃผ ๋น ๋ฅธ ํƒ์ƒ‰ ์‹œ๊ฐ„
  • ์ด์ง„ ํŠธ๋ฆฌ์˜ ์žฅ์ 
    • ๋™์ 
      • ์‚ฝ์ž… ํšŸ์ˆ˜๋ฅผ ๋ฏธ๋ฆฌ ์•Œ๊ณ  ์žˆ์ง€ ์•Š์•„๋„ ๋จ
    • ์ตœ์•…์˜ ๊ฒฝ์šฐ ์„ฑ๋Šฅ์„ ๋ณด์žฅ
      • ํ•ด์‹ฑ์˜ ๊ฒฝ์šฐ ์•„๋ฌด๋ฆฌ ์ข‹์€ ํ•ด์‹œํ•จ์ˆ˜๋ผ๋„ ๋ชจ๋“  ๊ฐ’์„ ๊ฐ™์€ ์žฅ์†Œ๋กœ ํ•ด์‹ฑํ•˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ๋ฐœ์ƒ
    • ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์—ฐ์‚ฐ์˜ ์ข…๋ฅ˜๊ฐ€ ๋งŽ์Œ (์˜ˆ: ์ •๋ ฌ์—ฐ์‚ฐ)

์—ฐ์‡„๋ฒ• (chaining)

  • ๋™์ผ ์ฃผ์†Œ๋กœ ํ•ด์‹œ๋˜๋Š” ๋ชจ๋“  ์›์†Œ๊ฐ€ ์—ฐ๊ฒฐ ๋ฆฌ์ŠคํŠธ ํ˜•ํƒœ๋กœ ์—ฐ๊ฒฐ๋จ
  • ์žฅ์ 
    • ์›์†Œ์˜ ์‚ญ์ œ๊ฐ€ ์šฉ์ด
  • ๋‹จ์ 
    • ํฌ์ธํ„ฐ ์ €์žฅ์„ ์œ„ํ•œ ๊ธฐ์–ต๊ณต๊ฐ„์ด ํ•„์š”
    • ๊ธฐ์–ต์žฅ์†Œ ํ• ๋‹น์ด ๋™์ ์œผ๋กœ ์ด๋ฃจ์–ด์ ธ์•ผ ํ•จ

์„ ํ˜• ํƒ์‚ฌ๋ฒ• (linear probing)

  • ํ•ด์‹œ ํ•จ์ˆ˜
    • ๊ฐœ๋ฐฉ ์ฃผ์†Œ๋ฒ•(open addressing) ์‚ฌ์šฉ : m ๊ฐ’์ด ์ž…๋ ฅ ์›์†Œ์˜ ์ˆ˜๋ณด๋‹ค ์ปค์•ผ ํ•จ
  • ํด๋Ÿฌ์Šคํ„ฐ๋ง์ด ๋ฐœ์ƒ
    • ์ ์œ ๋œ ์œ„์น˜๊ฐ€ ์—ฐ์†์ ์œผ๋กœ ๋‚˜ํƒ€๋‚˜๋Š” ๋ญ‰์น˜๊ฐ€ ์žˆ์œผ๋ฉด ์ด๊ฒƒ์ด ์ ์  ๋” ์ปค์ง€๋Š” ํ˜„์ƒ - ์ด๋Ÿฌํ•œ ๋ญ‰์น˜๋Š” ํ‰๊ท  ํƒ์ƒ‰ ์‹œ๊ฐ„์„ ์ฆ๊ฐ€์‹œํ‚ด
  • ์„ฑ๋Šฅ ํŠน์„ฑ
    • ํ•ด์‹œ ํ…Œ์ด๋ธ”์ด 2/3 ์ •๋„ ์ฐจ ์žˆ์„ ๊ฒฝ์šฐ, ์„ ํ˜• ํƒ์‚ฌ๋ฒ•์€ ํ‰๊ท ์ ์œผ๋กœ 5๋ฒˆ๋ณด๋‹ค ์ ์€ ํƒ ์‚ฌ๋ฅผ ์ˆ˜ํ–‰
    • ์„ฑ๊ณต์ ์ธ ํƒ์ƒ‰์€ ํ…Œ์ด๋ธ”์ด 90% ์ •๋„ ์ฐฐ ๋•Œ๊นŒ์ง€ 5๋ฒˆ ์ดํ•˜์˜ ํƒ์‚ฌ๋กœ ๊ฐ€๋Šฅ
    • ์„ฑ๊ณต์ ์ด์ง€ ์•Š์€ ํƒ์ƒ‰์€ ํ•ญ์ƒ ์„ฑ๊ณต์ ์ธ ํƒ์ƒ‰์— ๋น„ํ•ด ๋น„์šฉ์ด ๋งŽ์ด ๋“ฌ

์ด์ค‘ ํ•ด์‹ฑ (double hashing)

  • ํด๋Ÿฌ์Šคํ„ฐ๋ง ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐ

    • ์„ ํ˜•ํƒ์‚ฌ๋ฒ•์€ ๋‘๋ฒˆ์งธ ์ดํ›„์— ํƒ์‚ฌ๋˜๋Š” ์œ„์น˜๋Š” ์ดˆ๊ธฐ ํƒ์‚ฌ ์œ„์น˜์— ๋”ฐ๋ผ ๊ฒฐ์ •
    • ๋‘๋ฒˆ์งธ ์ดํ›„ ํƒ์‚ฌ๋˜๋Š” ์œ„์น˜๊ฐ€ ์ฒซ๋ฒˆ์งธ ํƒ์‚ฌ ์œ„์น˜์™€ ๋ฌด๊ด€ํ•˜๋‹ค๋ฉด ํด๋Ÿฌ์Šคํ„ฐ๋ง์„ ์—†์•จ ์ˆ˜ ์žˆ์Œ
  • ์„ฑ๋Šฅ ํŠน์„ฑ

    • ์ด์ค‘ ํ•ด์‹ฑ์€ ํ‰๊ท ์ ์œผ๋กœ ์„ ํ˜• ํƒ์‚ฌ๋ณด๋‹ค ์ ์€ ํƒ์‚ฌ ํšŒ์ˆ˜๋ฅผ ๊ฐ€์ง
    • ์ด์ค‘ ํ•ด์‹ฑ์€ ์„ ํ˜• ํƒ์‚ฌ์— ๋น„ํ•ด ์ž‘์€ ํ…Œ์ด๋ธ” ํฌ๊ธฐ๋ฅผ ๊ฐ€์ง€๊ณ ๋„ ๋™์ผํ•œ ํƒ์ƒ‰ ์„ฑ๋Šฅ์„ ๋‚˜ํƒ€๋ƒ„
    • ํ…Œ์ด๋ธ”์ด 80% ์ดํ•˜๋กœ ์ฑ„์›Œ์ ธ ์žˆ์„ ๊ฒฝ์šฐ ์„ฑ๊ณต์ ์ด์ง€ ์•Š์€ ํƒ์ƒ‰์˜ ํ‰๊ท  ํƒ์‚ฌ ํšŒ์ˆ˜๋Š” 5๋ฒˆ ์ดํ•˜์ด๋ฉฐ, 99% ์ฑ„์›Œ์ ธ ์žˆ์„ ๊ฒฝ์šฐ ์„ฑ๊ณต์ ์ธ ํƒ์ƒ‰์„ 5๋ฒˆ ์ดํ•˜๋กœ ํ•  ์ˆ˜ ์žˆ์Œ

Grid File (๋‹ค์ฐจ์› Hashing)

  • ๊ฒฉ์ž ํŒŒ์ผ
    • ์ „์ฒด ๊ณต๊ฐ„์„ ํ•˜๋‚˜ ์ด์ƒ์˜ ๊ฒฉ์ž(grid)๋กœ ๋ถ„ํ• 
    • ๋ฐ์ดํ„ฐ ์ถ”๊ฐ€์— ๋”ฐ๋ผ ๊ธฐ์กด ๊ฒฉ์ž๋ฅผ ๋ถ„ํ• ํ•˜์—ฌ ์ƒˆ๋กœ์šด ๊ฒฉ์ž ๊ตฌ์„ฑ
  • ํŠน์ง•
    • ๋””์Šคํฌ ๊ธฐ๋ฐ˜ -> ๋Œ€์šฉ๋Ÿ‰ ๋ฐ์ดํ„ฐ ์ฒ˜๋ฆฌ ๊ฐ€๋Šฅ
    • ํ•ด์‹œ ๊ธฐ๋ฐ˜ -> ์ผ๋ฐ˜์ ์œผ๋กœ ๋‘ ๋ฒˆ์˜ ๋””์Šคํฌ ์ ‘๊ทผ์œผ๋กœ ๋ฐ์ดํ„ฐ ๊ฒ€์ƒ‰
  • ๊ฒฉ์ž ๋ธ”๋ก๊ณผ ๋ฐ์ดํ„ฐ ํŽ˜์ด์ง€
    • ๊ธฐ๋ณธ์ ์œผ๋กœ ํ•˜๋‚˜์˜ ๊ฒฉ์ž ๋ธ”๋ก๋‹น ํ•˜๋‚˜์˜ ๋ฐ์ดํ„ฐ ํŽ˜์ด์ง€
    • ๋‘ ๊ฐœ ์ด์ƒ์˜ ๊ฒฉ์ž ๋ธ”๋ก์ด ํ•˜๋‚˜์˜ ๋ฐ์ดํ„ฐ ํŽ˜์ด์ง€์— ๋Œ€ํ•œ ๊ณต์œ  ๊ฐ€๋Šฅ

๊ธฐ์ˆ˜ ํƒ์ƒ‰ (Radix searching)

  • ํƒ์ƒ‰ ํ‚ค์˜ ๋””์ง€ํ„ธ ์„ฑ์งˆ(0๊ณผ 1)์„ ์ด์šฉํ•ด ํƒ์ƒ‰์„ ์œ„ํ•œ ์ด์ง„ ํŠธ๋ฆฌ๋ฅผ ๋งŒ๋“ค์–ด ํƒ์ƒ‰์„ ์ง„ํ–‰
  • ํƒ์ƒ‰ ํ‚ค์˜ ํ•ด๋‹น ๋น„ํŠธ๊ฐ€ 0์ด๋ฉด ์™ผ์ชฝ ์ž์‹์„ ๋ฐฉ๋ฌธํ•˜๊ณ , 1์ด๋ฉด ์˜ค๋ฅธ์ชฝ ์ž์‹์„ ๋ฐฉ๋ฌธ
  • ํƒ์ƒ‰ ํ‚ค๊ฐ€ ํด ๋•Œ๋Š” ๋…ธ๋“œ๋ฅผ ๋ฐฉ๋ฌธํ•  ๋•Œ๋งˆ๋‹ค ํƒ์ƒ‰ ํ‚ค๋ฅผ ๋น„๊ตํ•˜๋Š” ๊ฒƒ์ด ์„ฑ๋Šฅ์— ๋งŽ์€ ์˜ํ–ฅ์„ ์คŒ
  • ๊ธฐ์ˆ˜ ํƒ์ƒ‰ ์•Œ๊ณ ๋ฆฌ์ฆ˜์€ ํƒ์ƒ‰ ํ‚ค์˜ ๋น„๊ต ํšŸ์ˆ˜๋ฅผ ์ค„์ด๋ฉด์„œ ๊ธฐ์–ต ์žฅ์†Œ์˜ ๋‚ญ๋น„๋ฅผ ์ค„์ด๊ณ  ๊ตฌํ˜„์„ ์‰ฝ ๊ฒŒ ํ•˜๋Š” ๋ฐฉํ–ฅ์œผ๋กœ ๊ฐœ๋ฐœ๋˜์–ด ์˜ด

๋””์ง€ํ„ธ ํƒ์ƒ‰ ํŠธ๋ฆฌ (Digital Search Tree)

  • ํƒ์ƒ‰ ํ‚ค์˜ ํ•ด๋‹น ๋น„ํŠธ๊ฐ€ 0์ด๋ฉด ์™ผ์ชฝ, 1์ด๋ฉด ์˜ค๋ฅธ์ชฝ์œผ๋กœ ์ง„ํ–‰ํ•˜์—ฌ ๋‹จ๋ง ๋…ธ๋“œ๊นŒ์ง€ ์ด๋ฅด๋ฉด ๊ทธ ๊ณณ์— ์ƒˆ๋กœ์šด ๋…ธ๋“œ๋ฅผ ์‚ฝ์ž…
  • ๋…ธ๋“œ๋ฅผ ๋ฐฉ๋ฌธํ•  ๋•Œ๋งˆ๋‹ค ํƒ์ƒ‰ ํ‚ค๋ฅผ ๋น„๊ตํ•ด์•ผ ํ•˜๋ฏ€๋กœ ํƒ์ƒ‰ ํ‚ค๊ฐ€ ํฐ ๊ฒฝ์šฐ ํ‚ค ๋น„๊ต์— ๋งŽ์€ ์‹œ๊ฐ„์ด ๊ฑธ๋ฆผ
  • ๊ท ํ˜•์€ ๋งž์ง€ ์•Š์ง€๋งŒ, ์†๋„๊ฐ€ ๋น ๋ฅด๋‹ค.
  • ์žฅ์ 
    • ์ดํ•ดํ•˜๊ธฐ ์‰ฝ๊ณ  ๊ตฌํ˜„์ด ๊ฐ„๋‹จํ•จ
  • ๋‹จ์ 
    • ํƒ์ƒ‰ ํ‚ค์˜ ๋น„ํŠธ์— ๋”ฐ๋ผ ๋…ธ๋“œ๋ฅผ ๋ฐฉ๋ฌธํ•  ๋•Œ ๋งˆ๋‹ค ๋””์ง€ํ„ธ ํƒ์ƒ‰ ํŠธ๋ฆฌ์˜ ํ‚ค์™€ ํƒ์ƒ‰ ํ‚ค๋ฅผ ๋งค๋ฒˆ ๋น„๊ตํ•ด์•ผํ•˜๋ฏ€๋กœ, ํƒ์ƒ‰ ํ‚ค๊ฐ€ ํฐ ๊ฒฝ์šฐ์—๋Š” ํ‚ค ๋น„๊ต์— ๋งŽ์€ ์‹œ๊ฐ„์ด ์†Œ์š”

๊ธฐ์ˆ˜ ํƒ์ƒ‰ ํŠธ๋ผ์ด (Radix Search Trie)

  • ํŠธ๋ผ์ด(trie) : reTRIEval ์— ์œ ์šฉํ•˜๋‹ค๊ณ  ํ•˜์—ฌ Fredkin์ด ๋ช…๋ช…ํ•จ (ํŠธ๋ฆฌ๋Š” ์ง„์งœ ๋‚˜๋ฌด, ํŠธ๋ผ์ด๋Š” ๋ฉ์ฟจ ๊ฐ™์€ ๋Š๋‚Œ)
  • ๋…ธ๋“œ๋ฅผ ๋‚ด๋ถ€ ๋…ธ๋“œ์™€ ์™ธ๋ถ€ ๋…ธ๋“œ๋กœ ๋‚˜๋ˆ„์–ด ๋‚ด๋ถ€ ๋…ธ๋“œ๋Š” ํƒ์ƒ‰์‹œ ์™ผ์ชฝ๊ณผ ์˜ค๋ฅธ์ชฝ ์ด๋™๋งŒ์„ ๋‚˜ํƒ€๋‚ด๊ณ  ํ‚ค๋Š” ์™ธ๋ถ€ ๋…ธ๋“œ์—๋งŒ ์ €์žฅ
  • ํƒ์ƒ‰ ๋‹น ํ•œ ๋ฒˆ์˜ ํ‚ค ๋น„๊ต๋งŒ์„ ์ˆ˜ํ–‰ํ•˜๋ฏ€๋กœ ๋น„๊ต ์‹œ๊ฐ„์„ ์ ˆ์•ฝ
  • ๋‚ด๋ถ€ ๋…ธ๋“œ๋Š” ํ‚ค๋ฅผ ์ €์žฅํ•˜์ง€ ์•Š์œผ๋ฏ€๋กœ ๊ธฐ์–ต ์žฅ์†Œ์˜ ๋‚ญ๋น„๊ฐ€ ์‹ฌํ•˜๊ณ , ๋‚ด๋ถ€ ๋…ธ๋“œ์™€ ์™ธ๋ถ€ ๋…ธ๋“œ๋ฅผ ๋‚˜๋ˆ„์–ด ๊ด€๋ฆฌํ•ด์•ผ ํ•˜๋ฏ€๋กœ ํ”„๋กœ๊ทธ๋ž˜๋ฐํ•˜๊ธฐ๊ฐ€ ์–ด๋ ค์›€

ํŒจํŠธ๋ฆฌ์ƒค ํŠธ๋ฆฌ (Patricia)

  • โ€œPractical Algorithm To Retrieve Information Coded In Alphanumericโ€์˜ ์•ฝ์ž

  • ๋…ธ๋“œ์— ๋ช‡ ๋ฒˆ์งธ ๋น„ํŠธ๋ฅผ ๋น„๊ตํ•  ๊ฒƒ์ธ์ง€๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” ์ˆซ์ž๋ฅผ ํ†ตํ•ด ๋‚ด๋ถ€ ๋…ธ๋“œ์™€ ์™ธ๋ถ€ ๋…ธ๋“œ์˜ ๊ตฌ ๋ถ„์„ ์—†์• ์„œ ๊ธฐ์–ต ์žฅ์†Œ๋ฅผ ์ ˆ์•ฝ

  • ์œ„์ชฝ ๋งํฌ(upward link)๋ฅผ ๋งŒ๋‚˜๋ฉด ์œ„์ชฝ ๋งํฌ๊ฐ€ ๊ฐ€๋ฆฌํ‚ค๋Š” ๋…ธ๋“œ์™€ ํƒ์ƒ‰ ํ‚ค๋ฅผ ๋น„๊ตํ•˜๊ฒŒ ๋˜๋ฏ€๋กœ ํƒ์ƒ‰๋‹น 1๋ฒˆ๋งŒ ๋น„๊ต ์ˆ˜ํ–‰

  • ๋…ธ๋“œ๋งˆ๋‹ค ํ‚ค๋ฅผ ๋น„๊ตํ•ด์•ผ ํ•˜๋Š” ๋””์ง€ํ„ธ ํƒ์ƒ‰ ํŠธ๋ฆฌ์˜ ๋‹จ์ ๊ณผ ๋‚ด๋ถ€ ๋…ธ๋“œ์™€ ์™ธ๋ถ€ ๋…ธ๋“œ๋ฅผ ๋‘์–ด ๊ธฐ์–ต ์žฅ์†Œ๋ฅผ ๋‚ญ๋น„ํ•˜๋Š” ๊ธฐ์ˆ˜ ํƒ์ƒ‰ ํŠธ๋ผ์ด์˜ ๋‹จ์ ์„ ๋™์‹œ์— ๊ทน๋ณตํ•œ ๋ฐฉ๋ฒ•

  • ๋‚ด๋ถ€ ๋…ธ๋“œ์— ํ‚ค๋ฅผ ์ €์žฅํ•˜์—ฌ ๊ธฐ์–ต ์žฅ์†Œ๋ฅผ ์ ˆ์•ฝ

  • ์ƒํ–ฅ ๋งํฌ๋ฅผ ๋งŒ๋‚  ๋•Œ๋งŒ ํ‚ค ๋น„๊ต๋ฅผ ์ˆ˜ํ–‰ํ•˜๊ฒŒ ํ•˜์—ฌ ํƒ์ƒ‰ ๋‹น ํ•œ ๋ฒˆ์˜ ๋น„๊ต๋งŒ์„ ์ˆ˜ํ–‰

  • ๋””์ง€ํ„ธ ํƒ์ƒ‰ ํŠธ๋ฆฌ์™€ ๊ธฐ์ˆ˜ ํƒ์ƒ‰ ํŠธ๋ผ์ด์˜ ๋‹จ์ ์„ ๋™์‹œ์— ๊ทน๋ณต

์™ธ๋ถ€ ํƒ์ƒ‰ (external seraching)

  • ๋งค์šฐ ํฐ ํ™”์ผ์— ์žˆ๋Š” ๋ฐ์ดํ„ฐ์— ๋น ๋ฅด๊ฒŒ ์ ‘๊ทผํ•˜๋Š” ๊ฒƒ์€ ๋งŽ์€ ์‘์šฉ์—์„œ ๋งค์šฐ ์ค‘์š”ํ•จ
  • ์™ธ๋ถ€ ํƒ์ƒ‰์€ ํฐ ๋””์Šคํฌ ํ™”์ผ์„ ์ฃผ๋กœ ๋‹ค๋ฃธ
    • ํ…Œ์ดํ”„ ๊ฐ™์€ ์ˆœ์ฐจ ์ ‘๊ทผ ์žฅ์น˜๋Š” ์ˆœ์ฐจ ํƒ์ƒ‰ ์™ธ์— ๋ณ„๋‹ค๋ฅธ ํƒ์ƒ‰ ๋ฐฉ๋ฒ•์ด ์—†์Œ
  • ์™ธ๋ถ€ ํƒ์ƒ‰ ๊ธฐ๋ฒ•์€ ์ด๋ฏธ ๋ฐฐ์šด ๋‚ด๋ถ€ ํƒ์ƒ‰ ๊ธฐ๋ฒ•์˜ ๋…ผ๋ฆฌ์  ํ™•์žฅ์ž„
  • 10์–ต๊ฐœ ์ด์ƒ์˜ ๋ฐ์ดํƒ€๋ฅผ ํƒ์ƒ‰ํ•˜๋Š”๋ฐ ๋ถˆ๊ณผ 2โˆผ3ํšŒ์˜ ๋””์Šคํฌ ์ ‘๊ทผ์œผ๋กœ ๊ฐ€๋Šฅํ•จ
  • ๋””์Šคํฌ๋Š” ํŽ˜์ด์ง€๋กœ ๊ตฌ๋ถ„๋˜์–ด ์žˆ์œผ๋ฉฐ, ํŽ˜์ด์ง€๋Š” ๋งŽ์€ ๋ ˆ์ฝ”๋“œ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์Œ

B-tree

  • Visualization : B-tree (์ดˆ๊ธฐ ๋กœ๋”ฉ๋Š๋ฆผ ์ฃผ์˜)

B+-tree

  • Knuth๊ฐ€ ์ œ์•ˆํ•œ B-tree์˜ ๋˜ ๋‹ค๋ฅธ ๋ณ€ํ˜• ๊ตฌ์กฐ
    • Index set & Sequence set๋กœ ๊ตฌ์„ฑ
    • ๋ชฉ์  : ์ˆœ์ฐจ ํƒ์ƒ‰์˜ ์„ฑ๋Šฅ ํ–ฅ์ƒ(B-tree์˜ ์ˆœ์ฐจ ํƒ์ƒ‰ ๋ณด์™„)
  • ์ธ๋ฑ์Šค ์„ธํŠธ (index set)
    • ๋ฆฌํ”„ ์ด์™ธ์˜ ๋…ธ๋“œ
    • ๊ตฌ์กฐ : ํ‚ค ๊ฐ’๋งŒ ์กด์žฌ(๋ฆฌํ”„ ๋…ธ๋“œ์— ๋Œ€ํ•œ ๊ฒฝ๋กœ๋งŒ ์ œ๊ณต)
  • ์ˆœ์ฐจ ์„ธํŠธ (sequence set) - ๋ฆฌํ”„ ๋…ธ๋“œ
    • ๊ตฌ์กฐ : ๋ชจ๋“  (ํ‚ค๊ฐ’, ๋ฐ์ดํƒ€ ๋ ˆ์ฝ”๋“œ์˜ ์ฃผ์†Œ)๋“ค์ด ์กด์žฌ

B+-tree์˜ ์„ฑ๋Šฅ (B-tree์™€์˜ ๋น„๊ต)

  • ํŠน์ • ํ‚ค ๊ฐ’์˜ ๊ฒ€์ƒ‰
    • ๋‹จ์ 
      • ๊ฒ€์ƒ‰์ด ํ•ญ์ƒ ๋ฆฌํ”„ ๋…ธ๋“œ๊นŒ์ง€ ๋‚ด๋ ค๊ฐ€์•ผ๋งŒ ์ข…๋ฃŒ (ํ•ญ์ƒ O(log n))
        • ๊ฒ€์ƒ‰ํ•˜๊ณ ์ž ํ•˜๋Š” ๊ฐ’์ด ์ธ๋ฑ์Šค ์„ธํŠธ์—์„œ ๋ฐœ๊ฒฌ๋˜๋”๋ผ๋„ ๋ฆฌํ”„ ๋…ธ๋“œ๊นŒ์ง€ ๋‚ด๋ ค๊ฐ€์•ผ๋งŒ ์‹ค์ œ ๋ ˆ์ฝ”๋“œ์˜ ํฌ์ธํ„ฐ๋ฅผ ์•Œ ์ˆ˜ ์žˆ์Œ
    • ์žฅ์ 
      • ์ธ๋ฑ์Šค ๋…ธ๋“œ๋Š” ํฌ์ธํ„ฐ๋ฅผ ์ €์žฅํ•˜์ง€ ์•Š์œผ๋ฏ€๋กœ ๋…ธ๋“œ ๋‚ด ๊ณต๊ฐ„์ด ์ ˆ์•ฝ๋จ โ†’ ํŠธ๋ฆฌ๋ ˆ๋ฒจ์ด ๋‚ฎ์•„์งˆ ์ˆ˜ ์žˆ์Œ
      • ๋ฒ”์œ„ ๊ฒ€์ƒ‰
        • ์—ฐ๊ฒฐ๋ฆฌ์ŠคํŠธ๋ฅผ ์ˆœํšŒ โ†’ ํšจ์œจ์ 
      • B+-ํŠธ๋ฆฌ๋Š” ํ‚ค ๊ฒ€์ƒ‰๊ณผ ๋ฒ”์œ„ ๊ฒ€์ƒ‰์„ ๋ชจ๋‘ ํ•„์š”๋กœ ํ•˜๋Š” ์‘์šฉ์—์„œ ํšจ์œจ์ 
        • DBMS
        • File systems

R-tree

  • B-tree๋ฅผ ๋‹ค์ฐจ์›์œผ๋กœ ํ™•์žฅ์‹œํ‚จ ์™„์ „ ๊ท ํ˜• ํŠธ๋ฆฌ
  • ์„ , ๋ฉด, ๋„ํ˜• ๋“ฑ ๋‹ค์–‘ํ•œ ๋‹ค์ฐจ์› ๊ณต๊ฐ„ ๋ฐ์ดํ„ฐ์˜ ์ €์žฅ์ด ๊ฐ€๋Šฅ(SAM)
  • ํŠน์ง•
    • ๋ฃจํŠธ ๋…ธ๋“œ๊ฐ€ ์•„๋‹Œ ๋…ธ๋“œ๋Š” ์ตœ์†Œ m, ์ตœ๋Œ€ M๊ฐœ์˜ ์—”ํŠธ๋ฆฌ๋ฅผ ํฌํ•จํ•œ๋‹ค. (m <= M/2)
    • ๋ฃจํŠธ๋…ธ๋“œ๋Š” ๋‹จ๋ง์ด ์•„๋‹Œ ๊ฒฝ์šฐ ์ตœ์†Œ 2๊ฐœ์˜ ์—”ํŠธ๋ฆฌ๋ฅผ ํฌํ•จํ•œ๋‹ค.
    • ์™„์ „ ๊ท ํ˜•ํŠธ๋ฆฌ(๋ชจ๋“  ๋‹จ๋ง ๋…ธ๋“œ๋Š” ๊ฐ™์€ ๋ ˆ๋ฒจ)์ด๋‹ค.