Hash Tables and Hash Functions: ·
A hash table is an array with index range: 0 to TableSize – 1
Storage Allocation:
• Assumes a logical address space
• Memory typically divided into areas for
Static vs. Dynamic Allocation:
Example:
Consider the quick sort programint a[ll]
void readArray() { / Reads 9 integers into a[l],a[9j. */ int i;
>
int partition (int m, int n) ■(
/* Picks a separator value v, and partitions a[m.. n] so that
a\m .. p — 1] are less than v, a\p\ = v, and a[p + 1.. n] are
equal to or greater than v. Returns >
void quicksort (int m, int n) -( int i;
if (n > m) -(
i = partition(m, n);
quicksort(m, i-1);
quicksort(i+1, n);
>
>
main() {
readArray() ; a[0] = -9999;
a [10] = 9999;
quicksort(1,9);
>
Activation for Quicksort
enter main()
enter readArray()
leave readArray()
enter quicksort(1,9)
enter partition(l,9)
leave partition(1,9)
enter quicksort(1,3)
leave quicksort(1,3)
enter quicksort(5,9)
leave quicksort(5,9)
leave quicksort(1,9)
leave main()
Activation tree representing calls during an execution of quicksort:
Activation records
A General Activation Record
Activation Record
Downward-growing stack of activation records:
Designing Calling Sequences:
Access to dynamically allocated arrays:
ML
A version of quick sort, in ML style, using nested functions:
Access links for finding nonlocal data:
Sketch of ML program that uses function-parameters:
fun a(x) =
let
fun b(f) =
... f ... ;
fun c(y) =
let
fun d(z) =
in
b(d)
end
in
....c(1).......
end;
Actual parameters carry their access link with them:
Maintaining the Display:
Memory Manager:
Low overhead
Typical Memory Hierarchy Configurations:
Locality in Programs:
The conventional wisdom is that programs spend 90% of their time executing 10% of the code:
26 videos|66 docs|30 tests
|
1. What is a hash table? |
2. What is a hash function? |
3. What is collision in a hash table? |
4. What are the advantages of using hash tables? |
5. What are some common applications of hash tables? |
|
Explore Courses for Computer Science Engineering (CSE) exam
|