Lecture 15 - Trees and BSTs - Symbol Table ADT Trees and...

Info iconThis preview shows pages 1–13. Sign up to view the full content.

View Full Document Right Arrow Icon
Symbol Table ADT Trees and BST
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Searching Problem Searching is done prior to data processing Data is usually organized into records or items. Each item has a " key " used to locate it Key data is extracted from the actual data Examples: Managing the account information of a customer at a bank Keeping track of airline flight reservations
Background image of page 2
Symbol Table A data structure of items with keys that support two basic operations: insert a new item return an item with a given key ( search ) search hit : successful search (key found) search miss : unsuccessful search Examples: Phone book Dictionary
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Symbol Table Operations Insert a new item Search for an item(or items) having a given key Delete a specified item Select the k th largest item in a symbol table Sort the symbol table (Process all the items in the order of their keys) Initialize,Destroy / Free,Count items
Background image of page 4
Symbol Table Design Almost synonymous to “Search algorithm” Depends on usage patterns: Rarely inserts Dynamic usage (inserts, deletes and searches frequently) Depends on access pattern finger search : a search can be begin from the point where a previous search ended range search : count or visit all nodes falling within a certain interval near-neighbor-search : find items with keys closest to a given key
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Duplicate keys Never: keys are always unique A, B, C, D, E, F Maintain duplicates in a separate branch/list A, B, C, D, E, F A C A Just add as if it was a distinct item A, A, A, B, C, C, D, E, F Have each item contain a unique identifier (apart from the key) A- 1 , A- 2 , A- 3 , B- 4 , C- 5 , C- 6 , D- 7 , E- 8 , F- 9
Background image of page 6
Common Implementations Key-Indexed Search (array) Assumes key values are distinct small numbers Associates storage to key value Sequential Search (array, list) Check each entry one at a time Binary Search (array) Divide and conquer search technique Binary Search Trees Uses a special tree structure
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Key-Indexed Array Key values are positive integers less than a certain value Symbol table is implemented as an array with size equal to ( 1 + number of key values ) Key value is just the array index Time Complexity Initialization: O(N) Search: O(1) Insert: O(1)
Background image of page 8
Key-indexed-array Symbol Table static Item * st; static int M; /* NULLitem = unique data to indicate that item is empty getkey() = Function/operation that extracts Key from Item */ void STinit( int maxN) { int i; M = maxN + 1 ; st = malloc((maxN + 1 ) * sizeof (Item)); for (i = 0 ; i <= maxN; i ++ ) st[i] = NULLitem; }
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Key-indexed-array Symbol Table void STinsert(Item item) { st[getkey(item)] = item; } Item STsearch(Key v) { return st[v]; } void STdestroy( void ) { free(st); }
Background image of page 10
Key-indexed-array Symbol Table Constraints If key values are positive integers less than M Items have distinct keys (No duplicates)
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Applicable to general keys
Background image of page 12
Image of page 13
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 57

Lecture 15 - Trees and BSTs - Symbol Table ADT Trees and...

This preview shows document pages 1 - 13. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online