0% found this document useful (0 votes)
185 views5 pages

Dictionary ADT: Types Operations

This document discusses dictionary abstract data types (ADTs), which store elements keyed by a searchable value. It summarizes common dictionary types like log files and ordered dictionaries. Log files provide fast insertion but slow search, while ordered dictionaries support fast searching via binary search but slower insertion and removal. The document outlines the key operations and time complexities of searching, inserting, and removing elements from these dictionary implementations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
185 views5 pages

Dictionary ADT: Types Operations

This document discusses dictionary abstract data types (ADTs), which store elements keyed by a searchable value. It summarizes common dictionary types like log files and ordered dictionaries. Log files provide fast insertion but slow search, while ordered dictionaries support fast searching via binary search but slower insertion and removal. The document outlines the key operations and time complexities of searching, inserting, and removing elements from these dictionary implementations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

EECS 281: Data Structures and Algorithms

Dictionary Abstract Data Type

Dictionary ADT

„ Store elements so that they can be


quickly located using keys
„ Typically, useful additional information
in addition to key
„ Examples
– bank accounts with SSN as key
– student records with UMID or uniqname as
key

Dictionary ADTs

Types Operations
„ Log File „ Search
„ Ordered Dictionary „ Insertion
„ Hash Table „ Removal
„ Skip List

1
Dictionary ADTs

Stores items by key – element pairs


„ (k,e)

„ k and e may be of any type

„ k and e may be the same

„ In general, items with the same key


may be stored in same Dictionary

Unordered vs Ordered

Ordered
„ Relative order determined by comparator
between keys
„ Total Order relation defined on keys
Unordered
„ No order relation is assumed on keys
„ Only equality testing between keys

Dictionary ADT: Log File

Defn: implementation of Dictionary ADT


using a sequence to store items in
arbitrary order
Obviously, Unordered Dictionary
Useful implementation for case with many
insertions and few searches
Implemented as array (vector) or linked
list

2
Dictionary ADT: Log File
Search
„ Look through entire data set

„ O( )

Insertion
„ Always insert at end

„ O( )

Removal
„ First must find, then remove

„ O( )

Space, proportional to size of log file


„ O( )

Applications of Log Files

„ Database systems
„ File systems
„ Security audit trails

Dict. ADT: Ordered Dictionary

Defn: implementation of Dictionary ADT


in which usual operations may be used
and there exists an order relationship
between keys
Useful implementation for few insertions /
removals, but many searches

3
Binary Search
Iterative

int search(int a[], int v, int left, int right)


while (right >= left) {
int mid = (left + right)/2;
if (v == a[mid]) return mid;
if (v < a[mid])
right = mid - 1;
else
left = mid + 1;
}
return -1;

Binary Search
Recursive

int searchR(int a[], int v, int left, int right)


if (left > right) return -1;
int mid = (left + right)/2;
if (v == a[mid]) return mid;
if (v < a[mid])
return searchR(a[], v, left, mid - 1);
else
return searchR(a[], v, mid + 1, right);
}

Dict. ADT: Ordered Dictionary


Search
„ Binary Search (iterative or recursive)
„ O( )
Insertion
„ Always insert in correct location
„ O( ) to find location and O( ) to move subsequent
items
Removal
„ First must find, then remove
„ O( ) to find and O( ) to move subsequent items

4
Notes
„ Binary search is an example of divide-and-
conquer technique
„ Rule: An algorithm is O(log n) if each
constant time operation (e.g., CMP) can cut
the problem size by a fraction (e.g., half).
„ Corollary: If constant time is required to
reduce the problem size by a constant
amount, the algorithm is O(N).
„ Divide and conquer doesn’t work with linked
list, unfortunately

Summary: Dictionary ADT

„ Many implementations
– Log File (today)
– Ordered Dictionary (today)
– Hash Table (soon)
„ Different styles lead to different O( ) for
– search
– insertion
– removal

You might also like