ISYS 300 Trees: Especially BTrees - PowerPoint PPT Presentation

1 / 17
About This Presentation
Title:

ISYS 300 Trees: Especially BTrees

Description:

Used the index for a text searching (vector model) ... The Dewey Decimal System. Has a 'fan-out' of 10 (decimal) No attempt to be balanced. ... – PowerPoint PPT presentation

Number of Views:27
Avg rating:3.0/5.0
Slides: 18
Provided by: xlin2
Category:

less

Transcript and Presenter's Notes

Title: ISYS 300 Trees: Especially BTrees


1
ISYS 300 Trees Especially B-Trees
2
How we got here?
  • Created an inverted index from text
  • Used the index for a text searching (vector
    model)
  • There can be tens of thousands on items in an
    index How can we access them quickly?
  • Note These are important techniques beyond text
    searching there are many places they can be
    used.

3
(No Transcript)
4
Graph Theory
  • A graph is a set of nodes and edges
  • Some common graph problems include
  • Layout of highways, telephone lines
  • The structure of the Web
  • Social networks

5
Finding Items in an Inverted Index
  • Sorted List
  • Binary search
  • Linked List
  • Hard to search without an index
  • Easy to insert and delete items
  • Binary Trees
  • Always two choices (20 questions)
  • Multi-way Trees (B-Trees and B Trees)
  • Several choices at choice point
  • High fan-out. Not as deep as binary trees
  • Other techniques to remember but probably not a
    good choice here
  • Hashing
  • Content-based retrieval (neural networks)

6
Trees and Hierarchies Some Terminology
  • A Tree is a data structure in which one node
    links to other nodes in exactly one way.
  • We often think of a tree as a hierarchy
  • For a hierarchy, we often talk about parents
    (up the hierarchy) and children (lower in the
    hierarchy).
  • We often pick one central node as the root of a
    tree and the nodes with no children as the
    leaves
  • The depth of a tree is the (average) distance
    from the root to the children
  • Lots of times we say tree when we mean
    hierarchies
  • Trees can be used for searching with keys.
    That is, an element providing directions for
    moving around in the tree.

7
Balanced, Binary Trees
  • Binary tree (there are always 2 choices)
  • Each node contains a key
  • Left sub-trees stored all keys smaller than the
    parent key
  • Right sub-trees stored all keys larger than the
    parent key
  • Balanced trees
  • Every parent has an approximately equal number of
    left-and right sub-trees

8
The Dewey Decimal System
  • Has a fan-out of 10 (decimal)
  • No attempt to be balanced.

9
Advantages of Storing Data in a Balanced Binary
Tree
  • Why is a balanced tree helpful?
  • If its perfectly balanced, the number of steps
    to find an answer (the depth) is
  • NumStepssqrt(NumItems)

10
Operations on Search Trees
  • Search
  • Create a New Tree
  • Insert New Items
  • Delete Items

11
Constructing Balanced Trees (after insertion or
deletion)
  • Check if the original tree is balanced
  • Check if the left child is balanced
  • If it is not balanced, go to step two
  • Check if the right child is balanced
  • If it not balanced, go to step 2 (next page)

12
Constructing Balanced Trees (Contd)
  • 2. Rotate the unbalanced tree
  • If the left branch is deeper
  • Move the left child of the root to become the new
    root, move the right branch of new root to become
    the left branch of the old root
  • Make the old root become the right child of new
    root
  • If the right branch is deeper
  • 3. Go back to Step 1 to check if the new tree is
    balanced or not

13
B Trees
  • Description
  • Each node can have more than one key (multi-way
    tree)
  • If a node has m keys, it will have m1 children
    branches.
  • All keys in i-1 branch are smaller than key I
    This makes it useful for searching, it is the
    search tree property.
  • All leaves are at the same depth.
  • Advantages of B-Tree over Binary Tree
  • Useful when reading long records off a disk

14
B tree
10
25
4
8
13
18
21
22
28
39
51
52
0
3
15
B Tree
  • B Trees
  • B-tree that stores all data in the leaves.
  • That way, the B-Tree can be kept in a separate
    file from the data

16
B tree
(F, M)
(Ap, Bs, E)
(Gr, H, L)
(P, Ru, T)
1
2
3
4
5
6
7
8
9
10
11
12
17
Searching a Tree that is Not Well Structured
  • The moves in some games can be organized as a
    tree (a game space)
  • Tic-tac-toe
  • Chess
  • Have to make estimates of the value of going each
    choice
  • Can do learning (remember what good choices were)
Write a Comment
User Comments (0)
About PowerShow.com