You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _posts/2013-02-27-3.3-dictionaries.md
+23-2Lines changed: 23 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,8 +5,29 @@ title: 3.3 Dictionaries
5
5
6
6
* the dictionary abstract data type permits access to data items by content
7
7
* items added to a dictionary can be found by their key
8
+
9
+
## Dictionary operations
10
+
8
11
* search – given a search key, return a pointer to the element whose key value is k (if one exists)
9
12
* 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
11
14
* 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
0 commit comments