1. Hashing
Hashing are
a transformation from string to a shorter value or a value that represent that
string. It used to take index or item in database because of the shorter time
for finding item using hash key.
Other
than faster data take. Hashing used in encrypt digital signature. Digital
signature modified with hash function into hash value and receipt to receiver.
using the same hash function, receiver will get the message-digest and will compare it with received
message-digest. (they must be identical.)
Hash
function used for indexing value or original key and will used every time the
data will be taken. So, hashing will always operate in one way and don’t need
to “reverse engineer” hash function with analysing hash value.
There are many ways to hash a string into a key. The
following are some of the important methods for constructing hash functions.
•
Mid-square
•
Division
(most common)
•
Folding
•
Digit
Extraction
•
Rotating
Hash
2. Hash Table
Hashing
can be used to make hash table thought hash function. Hash table is a table where we store a data temporary for efficiency
data searching. Hash table will have index of the table in from of hashed key
while the value is the original string.
The size of hash table is usually several orders of
magnitude lower than the total number of possible string, so several string
might have a same hashed-key. If that happen that will induce a collision because
two data will have a same key.to resolve it we can use one of this method:
A. Close Hashing
Close
Hashing use empty memory without using memory outside of array used. Close
hashing search new address if the aimed address is already filled. There are 3
way to search for another address.
a. Linear Probing,
If the
array is filled, linear probing will check next array until get empty array. Linear
Probing use ((h+1) mod m) equation.
b. Quadratic Probing
Quadratic Probing
search new address using more complex quadratic equation. There is no fixed
equation for this probing you can make the formula you will use.
Example:
h,(h+i2)mod m,(h-i2)mod m, … ,(h+((m-1)/2)2)mod m, (h-((m-1)/2)2)mod m
with i = 1,2,3,4, … , ((m-1)/2).
This mean you will check (h+1)mod m, if filled then
check (h-1)mod m, if filled check(h+1)mod m, if filled to check(h+4)mod m, and
continue until get empty array.
c.
Double Hashing
Double Hashing use
second hash function to save collided key value. Second hash function used when
the original hash function is filled with hash function itself. But this method
need more array address than the data and need more memory to minimize collision.
B.
Open Hashing
Basically, open
hashing is making the value of hash table into array of pointer that followed
by linked list, with the head point to the array of pointer and following data
is connected to the head. The downside is this method will make a long LinkedList
if the data override each other.
3.
Binary Tree
A
tree is a non-linear data structure that represents the hierarchical
relationships among the data objects using connected node from up to down. In tree
each node will have maximum two child(node) connected with the node.
They
are named left and right. The node in the tree doesn’t have to be stored
contiguously and can be stored anywhere and linked by pointers. Binary tree is a
tree that have maximum 3 level of root (upper node). Binary tree is saved as
implicit in array, and this method will save memory if you make a full binary
tree.
In
binary tree the child node will be found at i+1, and i+2 index, even when the
father (upper node) will found at ((i-1)/2)
A. Element of binary tree
·
Node
·
Root is the upper node
·
Leaf is root without children
·
Sibling is two node who have same parent
·
Degree of node is the total sub tree of the node.
·
Height/Depth is the maximum degree of nodes in a tree.
·
If there is a line that connects p to q, then p is
called the ancestor of q, and q is a descendant of p.
B. Type of Binary tree
·
PERFECT binary tree is a binary tree in which every
level are at the same depth.
·
COMPLETE binary tree is a binary tree in which every
level, except possibly the last, is completely filled, and all nodes are as far
left as possible. A perfect binary tree is a complete binary tree.
·
SKEWED binary tree is a binary tree in which each node
has at most one child.
·
BALANCED binary tree is a binary tree in which no leaf
is much farther away from the root than any other leaf (different balancing
scheme allows different definitions of “much farther”).