% Data Structures Field Guide (v2) % Written by Krishna Parashar % Published by The OCM on February 10th, 2014 \pagebreak
While taking my Data Structures class I found it very difficult to conceptually understand and network the plethora of new found concepts. Thus I wrote up this brief synopsis of the concepts I found useful to understanding the core ideas. This is of course by no means comprehensive but I do hope it will provide you with a somewhat better understanding computer architecture. Please feel free to email me if you have an questions, suggestions, or corrections. Thanks and enjoy!
\pagebreak
- An DList's size variable is always correct.
- There is always a tail node whose next reference is null.
- Insertion: O(1)
- Deletion: O(1)
- Indexing: O(n)
- Searching: O(n)
public class SList {
private SListNode head; // First node in list.
private int size; // Number of items in list.
public SList() { // Here's how to represent an empty list.
head = null;
size = 0;
}
public void insertFront(Object item) {
head = new SListNode(item, head);
size++;
}
}
\pagebreak
- An DList's size variable is always correct.
- There is always a tail node whose next reference is null.
- item.next and item.previous either points to an item or null (if tail or head).
- Insertion: O(1)
- Deletion: O(1)
- Indexing: O(n)
- Searching: O(n)
public class DList {
private DListNode head; // First node in list.
private int size; // Number of items in list.
public DList() { // Here's how to represent an empty list.
head = tail = null;
size = 0;
}
public void insertFront(Object item) {
head = new SListNode(item, head);
size++;
}
public void insertBack(Object item) {
tail = new SListNode(item, head);
size++;
}
}
\pagebreak
- n is the number of keys (words).
- N buckets exists in a table.
- n
N << possible keys. - Load Factor is n/N < 1 (Around 0.75 is ideal).
- Best: O(1)
- Worst: O(n)
- Resizing: Average O(1) (Amortized)
Compression Function
- h(hashCode) = hashCode mod N.
- Better: h(hashCode) = ((a * (hashCode) + b) mod p) mod N
- p is prime >> N, a & b are arbitrary positive ints.
- Really Large Prime: 16908799
- If hashCode % N is negative, add N.
insert(key, value):
- Compute the key's hash code and compress it to determine the entry's bucket.
- Insert the entry (key and value together) into that bucket's list.
find(key):
- Hash the key to determine its bucket.
- Search the list for an entry with the given key.
- If found, return the entry; else, return null.
remove(key):
- Hash the key to determine its bucket.
- Search the list for an entry with the given key.
- Remove it from the list if found.
- Return the entry or null.
\pagebreak
\pagebreak
\pagebreak
\pagebreak
\pagebreak
\pagebreak
\pagebreak
\pagebreak
\pagebreak
\pagebreak
\pagebreak
\pagebreak
\pagebreak
Written by Krishna Parashar in Markdown on Byword. Used Pandoc to convert from Markdown to Latex.