Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3f8ec79

Browse files
added array dictionary implementations
1 parent 1d232fb commit 3f8ec79

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

‎_posts/2013-02-27-3.3-dictionaries.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,29 @@ title: 3.3 Dictionaries
55

66
* the dictionary abstract data type permits access to data items by content
77
* items added to a dictionary can be found by their key
8+
9+
## Dictionary operations
10+
811
* search – given a search key, return a pointer to the element whose key value is k (if one exists)
912
* insert – given an element and it's key add it to the dictionary
10-
* delete - given a search key remove the element form the dictionary
13+
* delete - given an element remove it form the dictionary
1114
* max, min - certain implementations support efficient retrieval of the largest/smallest key from the dictionary
12-
* predecessor, successor - certain implementations support efficient retrieval of the item immediatley before/after a given key (in sorted order) from the dictionary
15+
* predecessor, successor - certain implementations support efficient retrieval of the item immediately before/after a given key (in sorted order) from the dictionary
16+
* different implementations provide better/worse running time guarantees
17+
18+
## Unsorted array dictionary implementation
19+
20+
* search - O(n) - checking the key against each element (potentionally)
21+
* insert - O(1) - just add the element at the end
22+
* delete - O(1) - pointer is given to element to remove, overwrite position with last element
23+
* min/max - O(n) - requires linear sweep through the elements
24+
* predecessor/successor - O(n) - requires linear sweep through the elements
25+
26+
## Sorted array dictionary implementation
27+
28+
* search - O(log n) - using binary search
29+
* insert - O(n) - because making room for the new item
30+
* delete - O(n) - because filling the hole left by the deletem item
31+
* min/max - O(1) - first and last element
32+
* predecessor/successor - O(1) - elements in previous/next positions
33+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /