|
Stored as an (doubly linked) ordered list:
Operation | Ordered array implementation | Ordered linked list implementation |
---|---|---|
Insert (put(k,v)) | O(n) | O(n) |
Lookup (get(k)) | O(log(n)) (bin search) | O(n) |
Delete (remove(k)) | O(n) | O(n) |
|
Example: 2-dimensional grid structure
Note:
|
Note: the entry used to compare against the key is: p.right Note: p is initially equal to head
|
|
Example:
(Remember that the top most layer is logical --- it does not exists.)
Note:
|
|
Change:
|
|
|
|
public static void main(String[] args) { Random r = new Random(); double x; int n = 0; x = r.nextDouble(); // First toss n++; while ( x < 0.5 ) { x = r.nextDouble(); // Toss again... n++; } System.out.println("# tosses = " + n ); } |
|
|
Reason:
|
|