Close
Close Window

DSA Coursenotes

Chapter 11 Week 13

Show Source |    | About   «  10.1. Graphs   ::   Contents   ::   11.2. 2-3 Trees  »

11.1. Indexing

11.1.1. Indexing

11.1.1.1. Indexing

  • Goals:
    • Store large files

    • Support multiple search keys

    • Support efficient insert, delete, and range queries

11.1.1.2. Files and Indexing

  • Entry sequenced file: Order records by time of insertion.
    • Search with sequential search

  • Index file: Organized, stores pointers to actual records.
    • Could be organized with a tree or other data structure.

11.1.1.3. Keys and Indexing

  • Primary Key : A unique identifier for records. May be inconvenient for search.

  • Secondary Key: An alternate search key, often not unique for each record. Often used for search key.

11.1.1.4. Linear Indexing (1)

  • Linear index: Index file organized as a simple sequence of key/record pointer pairs with key values are in sorted order.

  • Linear indexing is good for searching variable-length records.

1 / 14 Settings
<<<>>>

Here is an array of variable length database records

Created with Raphaël 2.1.2
73
52
98
37
42
Proficient Saving... Error Saving
Server Error
Resubmit

11.1.1.5. Linear Indexing (2)

  • If the index is too large to fit in main memory, a second-level index might be used.

1 / 13 Settings
<<<>>>

Here is the Second Level Index Array which stores the first key value in the disk block of the index file

Created with Raphaël 2.1.2
  1. 1
  2. 2003
  3. 5894
  4. 10528
Proficient Saving... Error Saving
Server Error
Resubmit

11.1.1.6. Tree Indexing (1)

  • Linear index is poor for insertion/deletion.

  • Tree index can efficiently support all desired operations:
    • Insert/delete

    • Multiple search keys (multiple indices)

    • Key range search

11.1.1.7. Tree Indexing (2)

1 / 16 Settings
<<<>>>

Paged BST demo. The bottom square represents blocks on disk.

Created with Raphaël 2.1.2
Created with Raphaël 2.1.2
Proficient Saving... Error Saving
Server Error
Resubmit

11.1.1.8. Tree Indexing (3)

  • Difficulties when storing tree index on disk:
    • Tree must be balanced.

    • Each path from root to leaf should cover few disk pages.

11.1.1.9. Tree Indexing (4)

1 / 11 Settings
<<<>>>

This is the same tree as the previous slide show. Lets try to find the key 9.

Created with Raphaël 2.1.2
Created with Raphaël 2.1.2
10
5
15
3
8
13
18
2
4
7
9
12
14
17
19
10
5
15
3
8
13
18
2
4
7
9
12
14
17
19
Disk Accesses:
  1. 0
Proficient Saving... Error Saving
Server Error
Resubmit

   «  10.1. Graphs   ::   Contents   ::   11.2. 2-3 Trees  »

nsf
Close Window