8.1 Hashing Techniques to Resolve Collision| Separate Chaining and Linear Probing | Data structure

Jenny's Lectures CS IT
14 Feb 201925:51

Summary

TLDRThis educational video delves into the concept of hashing, a technique for efficient data retrieval with constant time complexity. It introduces hashing methods, including division, folding, mid-square, and modulo multiplication, and discusses collision resolution strategies like chaining and open vs. closed addressing. The script provides a detailed example using division and closed addressing with a hash function (h(k) = 2k + 3) mod (M), illustrating how to handle collisions through chaining and linear probing. It also explains the process of linear probing for collision minimization and hints at upcoming coverage of quadratic probing and double hashing.

Takeaways

  • πŸ”‘ Hashing is a searching technique that provides constant time complexity, O(1), for data retrieval.
  • πŸ“š Data structures like arrays, linked lists, and trees can be used for storing data in hashing.
  • πŸ” Two common searching techniques are linear search, which has a time complexity of O(n), and binary search, with O(log n).
  • πŸšͺ Collision occurs in hashing when two keys hash to the same index in the hash table.
  • πŸ”„ There are various methods to calculate hash functions, including division, folding, mid-square, and modulo multiplication methods.
  • πŸ”„β€πŸ”§ Collision resolution techniques include open hashing (closed addressing) and closed hashing (open addressing).
  • πŸ”— Open hashing uses the chaining method, where a linked list is used to store multiple items at the same index.
  • πŸ” Closed hashing involves linear probing, quadratic probing, and double hashing to find the next available slot in case of a collision.
  • πŸ”„ Linear probing is a closed hashing technique that searches for the next free slot in a linear sequence after a collision.
  • πŸ“ˆ The total number of probes can be calculated to measure the efficiency of the hashing process.
  • πŸ”’ The order of elements in the hash table after all insertions can be determined using the hashing and collision resolution methods described.

Q & A

  • What is hashing in the context of data structures?

    -Hashing is a searching technique used to store and retrieve data in constant time, typically using a hash table and a hash function to compute the address where data is stored.

  • Why is hashing preferred over other searching techniques like linear or binary search?

    -Hashing is preferred because it offers constant time complexity for search operations, regardless of the number of keys, unlike linear or binary search which have time complexities of O(n) and O(log n) respectively.

  • What are the common data structures used for storing data?

    -Common data structures used for storing data include arrays, linked lists, and trees.

  • What is a hash table?

    -A hash table is a data structure that implements an associative array, a structure that can map keys to values, using a hash function to compute an index into an array of buckets or slots, from which the desired value can be found.

  • What is a hash function and why is it important?

    -A hash function is a function used to map data of arbitrary size to fixed-size values, which are used as keys or addresses in a hash table. It is important because it determines the efficiency of the hash table by minimizing collisions.

  • What is a collision in hashing?

    -A collision occurs when two different keys hash to the same index in the hash table, which is a problem because only one value can be stored at a given index.

  • What are the different methods to resolve collisions in hashing?

    -Common methods to resolve collisions include chaining (using linked lists), open addressing (including linear probing, quadratic probing, and double hashing), and the modulo multiplication method.

  • What is chaining in the context of resolving hash collisions?

    -Chaining is a collision resolution technique where each cell of the hash table contains a linked list of all the items that hash to the same index.

  • What is linear probing and how does it work?

    -Linear probing is an open addressing technique used to resolve collisions. When a collision occurs, the algorithm searches for the next available slot in the hash table by moving linearly through the table.

  • What is the difference between open addressing and closed addressing in hashing?

    -Open addressing is a method of collision resolution where an alternative address is found within the hash table itself. Closed addressing, on the other hand, refers to the use of a hash table and a hash function without explicitly stating the collision resolution technique, often implying chaining.

  • How is the division method used to calculate a hash function in hashing?

    -The division method involves taking the key value, multiplying it by a constant (often 2), adding a constant, and then taking the modulus of the hash table size to determine the index in the hash table.

  • Can you provide an example of how to store keys in a hash table using the division method and linear probing?

    -Sure. Given a hash function h(k) = 2k + 3 mod 10 for a hash table of size 10, to store the key value 3, you would calculate h(3) = (2*3 + 3) mod 10 = 9, so the key 3 would be stored at index 9. If there's a collision, linear probing would be used to find the next free slot.

Outlines

00:00

πŸ” Introduction to Hashing and Collision Resolution Techniques

This paragraph introduces the concept of hashing as a search technique that allows for constant time data retrieval. It explains the basic idea of using a hash table and a hash function to store and retrieve data efficiently. The paragraph also discusses the potential for collisions when two keys hash to the same index and introduces various collision resolution methods, including open addressing and closed hashing, with specific focus on the division method for hash function calculation.

05:02

πŸ”„ Collision Resolution through Chaining in Closed Hashing

The second paragraph delves into the chaining method for resolving collisions within closed hashing. It provides an example using a hash table of size N and a hash function h(k) = 2k + 3, explaining how to calculate hash values for given key values and how to store them in the hash table using the division method. The paragraph illustrates the process of handling collisions by creating linked lists at indices where collisions occur.

10:09

πŸ” Implementing Linear Probing in Open Addressing

This paragraph explains the concept of linear probing as a default collision resolution technique in open addressing. It uses the same hash function and set of key values to demonstrate how to store them in a hash table of size 10. The process involves calculating the hash value for each key and then linearly searching for the next free slot in the hash table in case of a collision, thus ensuring that each key is stored in the first available position after the hashed index.

15:10

πŸ“ Calculating Total Probes and Element Order in Linear Probing

The fourth paragraph focuses on calculating the total number of probes required to store all elements in a hash table using linear probing. It also discusses how to determine the order of elements in the hash table after all insertions are complete. The explanation includes a step-by-step process for each key value, showing how to handle collisions by probing sequentially until an empty slot is found.

20:15

πŸ”’ Detailed Process of Linear Probing with Key Insertion

This paragraph provides a detailed explanation of how linear probing works, including the formula used to calculate the index for key insertion. It walks through the process of inserting keys into the hash table, showing how to handle collisions by incrementing the index and using modulo operation to wrap around the table until an empty slot is located. The paragraph also emphasizes the importance of maintaining the order of elements for potential examination questions.

25:16

πŸ‘‹ Conclusion and Preview of Upcoming Collision Resolution Techniques

The final paragraph wraps up the discussion on linear probing and teases the next video, which will cover quadratic probing as another method for resolving collisions in hash tables. It summarizes the basic idea of linear probing and sets the stage for further exploration of collision resolution strategies in hashing.

Mindmap

Keywords

πŸ’‘Hashing

Hashing is a technique used to map data of arbitrary size to fixed-size values. In the context of the video, it is used for efficient data retrieval with a time complexity of O(1), meaning constant time. The script discusses hashing as a method to store and retrieve data using a hash table and a hash function, which is central to the video's theme of data processing and optimization.

πŸ’‘Hash Table

A hash table is a data structure that implements an associative array, a structure that can map keys to values. The video script describes the hash table as a tool for storing data using the hashing technique, where the keys are mapped to specific indices or addresses within the table, which is crucial for the performance of the hashing method.

πŸ’‘Hash Function

A hash function is a function that takes an input (or 'key') and returns a fixed-size string of bytes. The script explains that the hash function is used to calculate a hash value or address for storing data in a hash table. It's a fundamental component of the hashing technique discussed in the video.

πŸ’‘Collision

Collision in hashing occurs when two different keys hash to the same index in the hash table. The script uses the example of keys 6 and 26 both hashing to index 6 in a table of size 10 to illustrate this concept. Collision resolution is a key topic in the video, as it impacts the efficiency of the hashing technique.

πŸ’‘Division Method

The division method is a specific way to calculate the hash value in a hash function, as mentioned in the script. It involves taking the key, multiplying it by a constant, adding another constant, and then modulo-ing by the size of the hash table. This method is used to distribute keys evenly across the hash table to minimize collisions.

πŸ’‘Open Addressing

Open addressing is a collision resolution technique where all elements are stored in the hash table itself. The script contrasts open addressing with separate chaining and explains that it involves methods like linear probing, quadratic probing, and double hashing to find the next available slot in case of a collision.

πŸ’‘Chaining Method

Chaining is a collision resolution method where each slot of the hash table points to a linked list of entries that have the same hash. The script describes chaining as a way to handle collisions by creating a separate linked list at each index of the hash table to store colliding elements.

πŸ’‘Linear Probing

Linear probing is an open addressing technique used to resolve collisions. The script explains that when a collision occurs, linear probing searches for the next free slot in the hash table by moving linearly through the table. It is the default method used when open addressing is specified.

πŸ’‘Quadratic Probing

Quadratic probing is another open addressing technique mentioned in the script. Unlike linear probing, it moves quadratically through the hash table when searching for an empty slot after a collision, thus reducing clustering and improving distribution of entries.

πŸ’‘Double Hashing

Double hashing is a more complex open addressing technique that uses a second hash function to determine the step size for probing. The script does not go into detail about this method, but it is listed as a technique for resolving collisions in a hash table.

Highlights

Hashing is a searching technique that provides constant time complexity for data retrieval.

Data structures like arrays, linked lists, and trees can be used for data storage in hashing.

Linear search and binary search are common data retrieval techniques with varying time complexities.

Hashing uses hash tables and hash functions to store and retrieve data in constant time.

Collision occurs when two keys hash to the same index in the hash table.

Different methods to calculate hash functions include division, folding, mid square, and modulo multiplication.

Division method for hash function is demonstrated with an example using modulo operation.

Open hashing and closed hashing are two types of hashing with different collision resolution techniques.

Chaining method is used in open hashing to resolve collisions by using linked lists.

Closed hashing uses techniques like linear probing, quadratic probing, and double hashing to minimize collisions.

Linear probing is a method of open addressing that searches for the next free location linearly.

Quadratic probing and double hashing are alternative methods to linear probing for collision resolution.

A detailed example demonstrates storing key values in a hash table using division method and closed addressing.

Chaining method creates a linked list to handle collisions when the same hash index is calculated for different keys.

Linear probing is explained with an example, showing how to find the next free location in case of collision.

The concept of total probes is introduced to measure the number of searches performed during the insertion process in hashing.

The order of elements in the hash table after all insertions is discussed, highlighting the sequence of stored keys.

The definition and process of linear probing are explained in detail, including the formula used for collision resolution.

Quadratic probing will be discussed in the next video as another method for collision resolution in hashing.

Transcripts

play00:00

welcome back today's topic is type of

play00:02

types of hashing okay so let me tell you

play00:06

something about hashing hashing is

play00:07

basically what it is a searching

play00:09

technique okay and in searching of some

play00:13

data if you use it this hashing

play00:15

technique then the time taken is that is

play00:18

a constant time but you can say order of

play00:20

one time taken is order of one see for

play00:25

storing some data obviously some data

play00:27

structure would be used may be array may

play00:29

be linked list may be tree okay and the

play00:31

main thing is in data processing is the

play00:34

main or the common paradigm is to store

play00:36

the data and after that to retrieve that

play00:38

data okay a post or we can now rock or a

play00:40

tree with a knife or some processing

play00:42

okay so for searching some date our for

play00:46

retrieving the data two types of

play00:49

searching technique I guess a possible

play00:51

path other one is linear search and one

play00:53

is binary search in linear search time

play00:55

taken is in the worst case the time

play00:57

taken is order of and and is that number

play01:02

of keys stored in that array or some

play01:05

data structure and in binary search if

play01:08

you use then order of log n time taken

play01:13

is order of log n so this time depends

play01:17

on the value of n means how many keys or

play01:19

how many you know a number of data you

play01:22

are supposed to you have inserted and

play01:24

you're supposed to retrieve from that

play01:26

data structure okay but we want some

play01:29

technique where the searching is you

play01:32

know searching takes takes constant time

play01:35

it does not depend on this number of

play01:37

keys and that technique is hashing

play01:40

technique okay the main concept is in

play01:43

this hashing technique we use some hash

play01:45

table and hash function using some hash

play01:48

function for storing some data we will

play01:51

calculate some hash value or you can say

play01:53

that address and that address we can

play01:56

store that key okay or that data in that

play02:00

hash table okay fine now suppose some

play02:05

policing occurs collision means if you

play02:08

see let us take an example we have six

play02:09

and twenty six these two keys we have

play02:11

and

play02:13

have their table of sorry the size of

play02:15

hash table is 10 we can store 10 values

play02:18

in that hash table and the hash function

play02:22

you are given is this you are supposed

play02:25

to use that division method three

play02:28

methods are there to calculate the hash

play02:31

function hash function that is division

play02:33

method one is folding method and one is

play02:35

mid square method and also another one

play02:38

is that modulo multiplication method

play02:40

also there okay so you are asked to use

play02:43

that division method division method

play02:44

McKevitt aapke hash function will be

play02:47

like this key whatever the key mode mm

play02:51

is size of hash table okay whether it is

play02:55

eight whether it is ten or eleven or

play02:57

fifteen whatever it is here in this

play02:59

example i am taking the size of hash

play03:01

table is ten now if you calculate the

play03:04

address to store this key value six

play03:07

using the hash function okay then what

play03:10

should be the value C K value is now six

play03:14

then six mod M value is in this example

play03:18

am value I am taking and it is just an

play03:21

example then the value would be six you

play03:26

can store the six where at six location

play03:32

or you can say the index should be six

play03:35

like this here we will have one hash

play03:38

table and from zero to nine because the

play03:42

size of hash table is what n so at some

play03:45

point we will have this index X and we

play03:48

can store this X at this place but

play03:50

suppose we have 26 another case 26 and

play03:53

the using the same method you are

play03:55

supposed to calculate the hash function

play03:57

or you can say the address for this 26

play03:59

now this address for 26 would be 26 mode

play04:04

mm value is 10 and this is also 6 okay

play04:09

but at sixth place we cannot store this

play04:12

26 because already 6 is there so this is

play04:15

known as policing when you know when you

play04:18

calculate some hash function or the

play04:21

location or you can say address for 2

play04:23

keys and using that same hash from

play04:26

that hash function will give you the

play04:28

same result same index but we cannot

play04:32

store two values at this place like 6

play04:34

and 26 this is the collision so to

play04:37

resolve these collision we have some

play04:40

techniques today I am going to discuss

play04:41

with you those techniques see and you

play04:44

can see types of hashing one is open

play04:47

hashing and one is closed hashing open

play04:49

hashing is also known as closed

play04:51

addressing and this closed hashing is

play04:55

also known as open addressing okay so in

play04:59

this method in first one this open

play05:02

hashing the method to resolve these type

play05:05

of collision okay is what that is

play05:09

chaining method but you can see separate

play05:11

chaining okay in this case the method

play05:16

would be to resolve the collision that

play05:19

is chaining method fine and in closed

play05:23

hashing three methods are there to

play05:27

resolve the collision see you cannot

play05:31

remove the collision you can only

play05:33

minimize the collision okay so three

play05:38

techniques are one is linear probing one

play05:42

is quadratic probing and the third one

play05:49

is double hashing technique right I'll

play05:56

discuss all these techniques with the

play05:58

help of example so in this video I am

play06:00

going to discuss with you this chaining

play06:02

method how to use this chaining method

play06:04

to resolve the collision okay through

play06:08

let us take one example now let us take

play06:15

one question suppose you are given these

play06:18

key values this one is suppose any and

play06:20

these key values are there three two

play06:22

nine six eleven thirteen seven twelve

play06:24

and you are supposed to store these key

play06:27

values and put into the hash table the

play06:29

size of hash table is given is N and the

play06:34

hash function vs. which is given is h

play06:36

case 2 k plus 3 in

play06:40

this question and you are asked to use

play06:43

division method and closed addressing

play06:47

technique to store these values now

play06:50

before you know solving these this

play06:53

question you must have the idea what is

play06:57

this division method and what is closed

play06:59

addressing do is in method we have

play07:01

already discussed how this method is to

play07:03

be used how the hash function hash

play07:06

values would be calculated the key and

play07:10

mod of a mode of size of hash table and

play07:15

what is closed addressing this is also

play07:17

known as open hashing and in this case

play07:19

what method is used to resolve the

play07:21

collision that is chaining method okay

play07:23

okay now let us we have one hash table

play07:28

this hash table and this hash table is

play07:32

of size 10

play07:41

zero two one two three four five six

play07:45

seven eight nine

play07:47

okay this is up to zero to nine okay

play07:56

this is our hash table of size and hash

play08:00

function is 2k plus three and you are

play08:03

supposed to use this division method now

play08:06

calculate the location proper position

play08:10

or you can say the address for these key

play08:13

values here we'll write down the

play08:16

location first key value is three find

play08:21

out the proper place to store this three

play08:23

in this hash table and how you will

play08:27

calculate that using hash function and

play08:29

hash function is given plus a which

play08:31

method you will use the division method

play08:32

or folding mat method or mid square

play08:34

method you are asked to use division

play08:36

method okay now calculate H for a method

play08:41

obviously you know ko5 mode M this is

play08:47

the method okay but here function has

play08:50

from a hash function is given to k plus

play08:52

3 so we cannot directly calculate that

play08:56

three more 10 and the value is 3 no we

play09:00

cannot directly put if this is not given

play09:03

to you then you can directly use this

play09:05

one okay if you are asked to use

play09:07

division method but here you are given

play09:09

this HK value 2 k plus 3 then how will

play09:12

calculate this value this would be like

play09:16

this 2 into the what is value of K here

play09:22

we have 3 okay plus 3 and then mod 10

play09:32

fine

play09:33

now here that a K is this one because

play09:37

hash function is given to k plus 3 now

play09:40

what is the value 6 plus 3 is 9 9 mod 10

play09:44

years 9 only because the result would be

play09:48

the remainder only so the location is 9

play09:51

at 9th index you can store this 3

play09:55

okay now find out the position for value

play09:58

to 2 into 2 plus 3 and now mod 10 4 plus

play10:08

3 7 & 7 more 10 is 7 only the where you

play10:13

can store this too at 7th place here we

play10:16

can store this too

play10:18

now find out this 1 4 9 have you'll find

play10:23

out the same method 2 into 9 plus 3 and

play10:27

then mode then what is the value 9 18 18

play10:33

plus 3 is 21 21 more 10 is 1 here at one

play10:39

position at one index you can store this

play10:42

9 now for 6 say method 2 into 6 plus 3

play10:48

more 10 what is the value 12 plus 3 is

play10:53

15 15 more 10 is 5 at fifth place you

play10:58

can store this value given you six now

play11:02

for 11 2 into 11 plus 3 mod 10 see for

play11:13

this one is 11 to 22 22 plus 3 is 25 25

play11:18

mod 10 is 5 now check what is the

play11:25

position for to store this 11 is 5 go to

play11:27

5 but here we have already the 6 this is

play11:31

the case of keynesian now in question

play11:35

you are given use closed addressing

play11:38

technique and enclosed addressing what

play11:41

is the technique you will use chaining

play11:42

method separate chaining method in

play11:44

chaining method what is there go to the

play11:47

fifth place already 6 is there then a

play11:50

linked list will be used like this fine

play11:54

and here 11 would be stored a chain

play12:01

would be created like this okay

play12:04

this is you can say linked list would be

play12:06

used to store

play12:08

the values in case of collision okay now

play12:14

for 13 what is the value two into 13

play12:19

plus 3 mod n 13 into 2 is 26 26 plus 3

play12:29

is 27 28 29 29 mode 10 is 9 now here

play12:35

also we have one collision go to the

play12:37

ninth place but we have already three at

play12:40

the space you cannot store 13 what

play12:42

method you use chaining method and

play12:44

chaining method making of the separate

play12:46

linked list would be used and here we

play12:48

will store what 30 now next is 7 2 into

play12:55

7 plus 3 mode and what is the value 1414

play13:03

plus 3 is 17 17 mode 10 is 7 he rolls

play13:11

will happily then go to the seventh

play13:12

place but here we have already what is

play13:15

stored that is 2 we cannot store the 7

play13:18

what is the method chaining method the

play13:20

chaining method making our separate link

play13:22

list will be created and the 7 would be

play13:25

stored at this place this is linked list

play13:28

link lachemann basically 1 node is

play13:31

having two part one is that information

play13:32

part and one is that address part that

play13:35

this link will or this pointer will

play13:37

contain the address of next node ok you

play13:42

can denote like this only now next is 12

play13:47

2 into 12 plus 3 mod 10 and what does

play13:56

this value 12 into 2 is 24 24 plus 3 is

play14:00

27 27 mod 10 is again 7 now go to

play14:07

seventh place find out this is not free

play14:11

you cannot store here go to the linked

play14:14

list part here also you cannot store we

play14:16

have 1 linked list

play14:17

now again 1 linked list or one node

play14:19

would be created fine

play14:22

and 12 would be stored at this place and

play14:25

this this you know this one this link or

play14:28

this pointer will contain the address of

play14:30

this node and this pointer would contain

play14:33

now this is also not this is not also

play14:35

not fine so this is the chaining method

play14:39

how the staining method can be used to

play14:42

resolve the collision the next video I'm

play14:45

going to discuss with you what does that

play14:46

how the linear probing method will be

play14:49

used to resolve the or to minimize the

play14:52

collision

play14:53

okay now let's kiss the linear probing

play14:56

method with the help of same question

play14:58

the same question is there these are the

play15:00

keys same hash function is there to k

play15:02

plus 3 same you have to use division

play15:04

method only the changes you're supposed

play15:06

to use open addressing fine to store

play15:10

these elements okay and size of hash

play15:12

table is 10 now whenever you are asked

play15:15

to use open addressing then by default

play15:18

you will use linear probing to resolve

play15:20

the or to minimize the collision okay

play15:24

then that is the tool if you are because

play15:27

this the open addressing few techniques

play15:29

are there linear probing quadratic

play15:31

probing and double hashing but by

play15:32

default you will use linear probing in

play15:35

case of say Putrajaya use quadratic

play15:37

probing in that case when you lose that

play15:39

one in case you're asked to use double

play15:41

hashing then you will use double hashing

play15:43

but by default you will use what linear

play15:45

probing okay now check the only changes

play15:50

the hair is we have open addressing same

play15:53

question is there okay for this three

play15:56

you have calculated the value that is

play15:59

nine okay I'm just going to write these

play16:03

values at ninth place we will use will

play16:05

store this three now what is the place

play16:08

for this key second this key value two

play16:12

here is seventh here you can store this

play16:15

to nine co-op can store Ikaruga here at

play16:19

one occasion here you can store nine six

play16:22

Co you can store at index fifth or fifth

play16:26

location here you can store six now

play16:29

problem comes in the case of eleven same

play16:33

hash

play16:34

hash value is being generated using this

play16:38

hash function okay that is five when you

play16:41

go to five but it is already there six

play16:43

is already there so collision is there

play16:45

now use linear probing what is C probing

play16:49

means what in simple English term

play16:51

probing means you know a synonymous

play16:53

searching or a coach karna so it will

play16:57

search the free place now where you can

play16:59

it can store the value okay now at fifth

play17:03

place we cannot store because already

play17:05

six is their Pelini linear probing

play17:07

linearly hamaji building it at the next

play17:11

place this is a simple technique okay

play17:13

next place

play17:15

check out this is free yes this is free

play17:17

throw you can store 11 at this place

play17:21

fine and sometime in question you are

play17:24

asked if we at last to store these

play17:28

elements using open addressing total

play17:31

props of kupatana how many total probes

play17:33

was there okay so such SATA maybe

play17:36

discuss contain four key to store this

play17:39

key three how many props are there

play17:40

obviously one probe is there now

play17:42

ix big they have omni search here ninth

play17:45

who searched or Nikki Anaya bar then one

play17:49

probe is there for two also one probe

play17:52

for nine also one province for six also

play17:54

one prom but to store this 11 how many

play17:58

probes you required one probe is encase

play18:02

them up to five Milla search five but

play18:06

this is already filled one probe is

play18:07

already there now again search the next

play18:10

location this is free yes this is free

play18:12

fine so two probes are there one is for

play18:15

this fifth one original one and next is

play18:17

for the next one so here two props for

play18:22

13 go to 9th but this is already filled

play18:26

then what you will do find out linearly

play18:31

the next place and next place would be

play18:33

this one zero okay because we have

play18:37

already say the size of this hash table

play18:40

is 0 to 9 then go backward and this one

play18:42

is 0 now where you can store this 13

play18:47

here we can store this 13 next is how

play18:51

many prompts for 32 probes 1 9 p ji apne

play18:55

search here 9 who then happening next

play18:57

place search here 13 then two proms are

play18:59

there for storing the seven go to the

play19:02

seventh place but this is already filled

play19:05

then the next place yes this is free we

play19:08

can store seven at this place and total

play19:10

number of probes are due for storing

play19:13

this 12 go to the seventh place this one

play19:16

is already filled we cannot store go to

play19:19

the next place this is already filled we

play19:21

cannot store go to the next place this

play19:24

is already filled we cannot cannot store

play19:26

the next place is this 1 0 0 this

play19:31

location but this was already filled the

play19:33

next go to the next place that isn't one

play19:37

that index 1 that is already filled we

play19:40

cannot store go to the next yes say

play19:44

linearly we are we are searching the

play19:47

free place linearly one by one we are

play19:49

not jumping like this I got a free Nieto

play19:52

will jump towards three locations no

play19:54

linearly up Azam canal that is why it is

play19:56

known as linear probing here we can

play19:58

store this to L okay now how many props

play20:03

for this - L 1 is we go to 7 7 company

play20:07

search here one probe one is for this

play20:09

one - one is for this 3 4 5 and finally

play20:14

6 6 problems now total Pro for this - LS

play20:20

6 pro now total Pro bhai hope calculate

play20:26

cursor go in case if you are asked to

play20:28

total prop give me way sometimes in net

play20:30

exam they are also asked he just find

play20:34

out just tell the order of the elements

play20:38

in the hash table after inserting all

play20:41

the elements what is the order of

play20:42

elements you are supposed to give the

play20:46

for multiple you know that choices the

play20:49

order of element is this this this or

play20:51

this this this now in this case what is

play20:53

the order of element in the hash table

play20:55

if you are asked then the order of

play20:57

element would be you has applicant start

play20:59

over from 0

play21:00

zero - please 13 then 9 then 12 then you

play21:06

will not write the sex directly one in

play21:09

two places are free one and two these

play21:12

are blank then six then 11 then two then

play21:16

seven and then three this is the order

play21:20

of element okay so in linear this was a

play21:25

shortcut

play21:26

yup just look out the hash table and

play21:29

finally next by next by search for

play21:31

Karenia if you write the proper you know

play21:34

definition of that linear probing then

play21:37

what is that that one is this is what

play21:43

happens in linear problem throbbing

play21:45

properly if you'll write insert ki like

play21:50

k1 k2 k3 these are keys at the first

play21:54

free location from you plus I both mode

play22:00

M where I will range from 0 to M minus 1

play22:04

now here is a path I bogan 0 to M minus

play22:07

1 M question media Haga that is 10 then

play22:11

that I would be 0 to 9

play22:13

what is this you you is what this

play22:16

address so you can say this location

play22:18

whatever whatever you have calculated

play22:20

this 9 7 1 using this hash function that

play22:23

would be the you now check out see if

play22:28

directly a poisoning knife you use this

play22:31

method or this definition and then check

play22:34

out for 11 will check out okay 11 Kelly

play22:42

in case of collision you will use this

play22:44

one insert kind of a pokey I acquired

play22:46

the very at the first free location from

play22:49

this one fine for 11 what is the value

play22:52

of U u plus I more 10 what is value of U

play22:55

for 11 what is value of u whatever what

play22:57

you have calculated that is 5 then 5

play23:01

plus I I will range from 0 to M minus 1

play23:06

of starting my Q value is 0 0 fine

play23:11

more mm value is

play23:14

ten and this would be five more ten that

play23:17

is five but this is not free place okay

play23:21

now increase value of Phi I is now 1

play23:23

then 5 plus 1 mod n 6 more and that is 6

play23:31

find out sixth place how many insert

play23:34

copy our key copy ksi 6 3 because sixth

play23:36

was free so here we have inserted this

play23:38

11 so this is the same definition insert

play23:42

key I add the first free location from

play23:45

this one first free location yeha say

play23:49

the very first free location was this

play23:52

one sixth okay in case of this 12 check

play23:56

out sea fort well what is when you of

play23:58

you the value of you is 7 calculate 7

play24:04

plus in starting value of I is 0 mod n 7

play24:11

would 10 is 7 7 this one is not free ok

play24:16

now 7 plus 1 mod 10 8 plus 8 more tennis

play24:24

8 more pen that is 8 this one is also

play24:27

not free because 7 is already there now

play24:30

7 plus increase IQ value 0 to M minus 1

play24:35

that is 0 to 9 7 plus 2 mode and that is

play24:39

nine nine more 10 is 9 this is also not

play24:42

free 7 then now I Q value is 3 7 plus 3

play24:46

mode 10 that is 10 more 10 10 more 10 is

play24:51

0 remainder would be 0 go to the zeroth

play24:54

place but this one is also not free

play24:55

because 13 is also there again check out

play24:58

the next location 7 plus 4 more 10 11

play25:02

more 10 that is 1 but 1 is also note

play25:05

free now 7 plus 5 more 10 that is 12

play25:10

mode n is 2 now go to the index - this

play25:15

one was free okay and here we have we

play25:17

can insert this 12 okay so using this

play25:21

formula formula also you can calculate

play25:23

these indexes or well you are same

play25:27

linear probing me up cohosh deviled egg

play25:29

nyan simply just look over the next

play25:30

place is free and free then insert it

play25:33

other nail top next Nick Nick Nick said

play25:34

y'all grab circle together so this is

play25:38

the basic idea of linear probing and

play25:41

next video I'll discuss how to use

play25:42

quadratic probing to find out that or

play25:46

you can see the to dissolve the

play25:48

collision till then bye bye

play25:49

take care

Rate This
β˜…
β˜…
β˜…
β˜…
β˜…

5.0 / 5 (0 votes)

Related Tags
Hashing TechniquesData StructuresCollision ResolutionLinear ProbingQuadratic ProbingHash FunctionsSearch TechniquesEfficiency OptimizationProgramming ConceptsComputer Science