After getting into Guvi,daily i am seeing many students who comes to guvi for mentorship.When we ask some basic questions in programming,they will tell like, mam I know only basics,Brush up pananum,college did not teach well, loads of reason for not answering.But in the back of all of their minds they think like only exceptions/genius can do programming.They don’t even give a try to understand the concepts.It takes lot of efforts, just to make them believe, as they think coding is not such a difficult one.So this post is for people who believes coding is godly.….
We feel like this build up is too much,we will get the same feel once we start programming.
I bet you one of the easiest skill to acquire in this world is coding, but at the cost of 2 things. One is we have to believe is coding is easy. Next is practice.
You may think like yenname ipadi solitiyema, whenver I attend interview I feel like Yaradi Mohani Dhanush. What is foreign Key,What is class,what is stack ….
So our first goal you have to believe, coding is easy. Lets try to understand, what majority of the software industry is developing or working on.The software industry is trying to make the human life easy in earth. Did you remember when is the last time you stand in queue to book your train ticket, cinema ticket etc.When is the last time you have seen loads of files in government offices So we have to understand that most of the software companies are trying to develop products to solve our pain points in our daily life. They are nothing new to us. Take a list of software companies you know and dig into the details of what they are working. It will be mostly any one the things related to our daily life. So if we have little common sense it is sufficient is build a wonderful product.
Lets take a little bit complex topic and try to understand how easy it is. What is Hash Table? A hash table (hash map) is a data structure used to implement an associative array, a structure that can map keys to values. A hash table uses a hash function to compute an index into an array of buckets or slots, from which the desired value can be found.
When you look in google you will get some definition like this. But we are going to make it simple
Did you ever think whenever you ask for some item in your home, your mom will tell its place correctly . Actually all our moms are doing this hashing daily in kitchen, dress shelf, bookshelf etc Whenever you go to shopping mall to buy dresses, they will ask for size and tell you in which shelf it will be. Imaging how it will be, if they mix dresses of all kinds and sizes in one big shelf and ask you to search for it. It will be like the big box in Saravana Stores where there will be dresses of all sizes in a single box and make us to struggle .That is the difference between array and hash table.
Another perfect example for hash table is Chappal stand in temples, when you leave your chappal they give you a token. When you come back and give the token he will take it quickly from the respective position. This is called searching in hash table.
Imagine this scenario, if there is no token system how he will you search your chappal. He has to check each and every chappal in the stand. This is similar to searching an element in an array, since we don’t know the index where the element is stored.
So now we can revisit the definition of hash table Hash Table is a data structure used to store key / value pairs. Hash table uses a hash function to compute an index into an array where the element will be inserted or searched.Each position of the hash table, often called a slot, can hold an item and is named by an integer value starting at 0. For example, we will have a slot named 0, a slot named 1, a slot named 2, and so on. Initially, the hash table contains no items so every slot is empty.shows a hash table of size m.In other words, there are m slots in the table, named 0 through 10.
When you look at the image,you can understand that it’s also an array.Then what is the difference between array and hash table.In an array items are filled in the next consecutive slots.When you have to search for an item,you have to check each and every entry in the array.So in worst case the order of search can be O(n) But in case of hash table,from the key value we can tell the index in which the value is residing.So any value can be searched in the O(1)
Our Chappal stand person decided to eliminate token system for cost cutting.So now he has to come up with a technique which will help him to identify the slot no without tokens.When a person comes to keep his chappal he will ask for this mobile number.For Eg:9894906789 what he will do is he will take the last 2 digits from his mobile no and keep the chappals in that slot no. in our case it will be slot no 89. So when they come back for chappal he will easily finds the slot from the mobile no.
This is called as hashing function in data structures, converting key into index.The mapping between an item and the slot where that item belongs in the hash table is called the hash function.The hash function will take any item in the collection and return an integer in the range of slot names, between 0 and m-1
Lets stop here……….other topics like Collision Resolution Techniques –Separate Chaining,Linear Probing,Quadratic Probing,Double Hashing and applications of hash table with code samples in our next blog.
For more technical videos log into guvi website