2. Introduction
Hashing:
Hashing is a technique that is used to uniquely identify a specific object
from a group of similar objects. A searching technique based on the hash table and
hash function.
Example:
In universities, each student is assigned a unique roll number that can be used
to retrieve information about them.
In libraries, each book is assigned a unique number that can be used to
determine information about the book, such as its exact position in the library
or the users it has been issued to etc.
3. Hash Function:
A hash function is any function that can be used to map data
of arbitrary size to fixed-size values. The values returned by a hash function are
called hash values, digests.
Or
A function that converts a given big value to a small practical
integer value. Which contain the address of given data.
Hash Key or Simple Key:
A unique assigned value to large number of
objects or a single object.
4. Working or Example:
Assume that you have an object and you want
to assign a key to it to make searching easy. To store the key/value pair, you
can use a simple array like a data structure where keys (integers) can be used
directly as an index to store values. However, in cases where the keys are large
and cannot be used directly as an index, you should use hashing.
In hashing, large keys are converted into small keys by using hash functions.
The values are then stored in a data structure called hash table.
5. Implementation of hashing:
Hashing is easily implemented in two
steps:
1. An element is converted into an integer by using a hash function.
2. The element is stored in the hash table where it can be quickly retrieved using
hashed key
hashing=h(k)=adrees
Data Key Address
H(k)
6. Collision:
Since a hash function gets us a small number for a big key, there
is possibility that two keys result in same value. The situation where a newly
inserted key maps to an already occupied slot in hash table is called collision.
Data 2-Keys Address
Direct Hashing:
A simple hashing technique having no collision or
having only 1 key value. It is not suit able for larger key values.
H(k)
7. Memory Management:
Def:
Memory management is the process of controlling and coordinating
computer memory, assigning portions called blocks to various running programs
to optimize overall system performance. Memory management resides in
hardware, in the OS (operating system), and in programs and applications.
Garbage Collection:
Garbage collection (computer science) ... In computer
science, garbage collection (GC) is a form of automatic memory management.
The garbage collector, or just collector, attempts to reclaim garbage, or memory
occupied by objects that are no longer in use by the program.
8. Strengths of Manual Management:
● Comparatively easy to implement.
● “Just” need a working memory manager.
● Allows programmers to make aggressive performance optimizations.
● Programmer can choose allocation scheme that achieves best performance
Automatic Memory Management
● Idea: Have the runtime environment automatically reclaim memory.
● Objects that won't be used again are called garbage.
● Reclaiming garbage objects automatically is called garbage collection.
9. Advantages:
● Programmer doesn't have to reclaim unused resources.
Disadvantages:
● Programmer can't reclaim unused resources.
What is Garbage?
● An object is called garbage at some point during execution if it will never be
used again
Approximating Garbage
● In general, it is undecidable whether an object is garbage.
● Need to rely on a conservative approximation.
● An object is reachable if it can still be referenced by the program.
● Goal for today: detect and reclaim unreachable objects.
● This does not prevent memory leaks!
● Many reachable objects are never used again.
● It is very easy to have memory leaks in garbage collected languages.
10. Types of Garbage Collectors
● Incremental vs stop-the-world:
● An incremental collector is one that runs concurrently with the program
● A stop-the-world collector pauses program execution to look for garbage.
● Which is (generally) more precise?
● Which would you use in a nuclear reactor control system