GSLC KE-2 Data Structure, Pertemuan ke-6
Materi :
- Hashing and Hash Tables
- Tree and Binary Tree
Hashing and Hash Tables
Hashing is a method used to store data so it can be added, search and delete in a short time.
There are many ways of hashing.
Hash Functions :
Materi :
- Hashing and Hash Tables
- Tree and Binary Tree
Hashing and Hash Tables
Hashing is a method used to store data so it can be added, search and delete in a short time.
There are many ways of hashing.
Hash Functions :
- Mid-square : Squaring the value of key, taking the middle part.
- Division : (key) mod (value).
- Folding : Done by taking parts of a number, adding it, and ignoring some digits of it.
- Digit Extraction : Extract some digit from a number. for example, given x=219382. We want to extract some of it's digit and make it a hash key, so we extract 1st digit and 4th digit. From that the number we get is 23.
- Rotating Hash : Do any of the method above, then rotate the digit. For example, given that x=23354. If we rotate x, it would be 45332.
In some case, Collision will happen... What is a collision ? Collision is when several data have the same hash-key. What can we do to handle it ?
- Linear Probing : Search the next empty slot and put the data there.
- Chaining : Put the string n a slot as a chained list (Linked List).
Trees & Binary Tree
Tree ? What is it ? A tree is a non-linear data structure that represents the relationships ammong data objects.
Root = Node at the top (A)
Leaf = Nodes that do not have Children(E,F,G)
Degree = Total sub tree of a node
Height/Depth = maximum degree of nodes in a tree
Meanwhile, Binary Tree is a rooted tree data structure which each node has at most(max) two children.
Type of Binary Tree
- Perfect binary tree, which every level of the binary tree are at the same depth
- Complete binary tree, a binary tree in which every level except the last(optional), is completely filled. If a binary tree is perfect, it is also a complete binary tree.
- Skewed binary tree, a binary tree which each node has at most one children.
- Balanced binary tree, a binary tree which has no leaf far from the root.
In code, Binary tree can be first initialized by
Comments
Post a Comment