Wednesday, March 25, 2020

003 - Hashing and Binary Tree



Hashing

Hashing is basically giving alias that is determined by a hash function to a data. The reason that whenever we are logging in into an account, it didn’t take a long time for our account data to be retrieved is because they didn’t look and search for our account one by one. By using a hash function and turning our login information into a key, the data that is stored within the index of the key can be immediately called accurately.

Here is a diagram that I’ve made to visualize hashing:




This is the reason that, whenever someone is signing up for an account, having the same username as someone else is not a possibility. It’s because those names are used as keys to the specific address in the database. Simply speak, your username is equivalent to the address of your data.





Binary Tree



Binary Tree is a tree data structure that has the special condition of having 2 children at most, thus the word “binary” in the name. Classifying a tree as a binary tree is not that difficult since the condition of “having 2 children at most” is literally the only condition of it. This means that a binary tree’s node doesn’t have to have 2 children beneath it. As long as the number of children in a single node is less than two, it is a binary tree.
Nodes that don’t have a child (the leaf of the tree) or missing a child (either left or right child) has the value of the missing child set as NULL. This basically means that all of the missing child’s node exist but they have NULL values inside of them.

Some terminologies and types of Binary Tree might be:

-         Balanced Binary Tree:
The concept of minimizing the levels in a binary tree or in other words, “Balancing” a binary tree. Since there are operations in binary tree that depends on the height of a tree, the longer a tree is, the longer that operation will take. Thus, minimizing a tree and keep it as dense (Balanced) as possible is an important aspect.

-         Complete Binary Tree:
A binary tree will be called a completed one, if it satisfies 2 requirements: There are no missing nodes (only has 1 child), and the nodes are filled mostly on the left side of the tree rather than the right. However, it’s allowed for the last level of the tree to not be filled completely.

-         Perfect Binary Tree:
It’s a binary tree which satisfies the fact that every child is filled. that means that it will always use the maximum number of nodes available in every level.



Most of the Information used are based on:
https://www.youtube.com/watch?v=H5JubkIy_p8&t=78s

A highly recommended channel to learn Data Structure.