FAQ: Hash Maps: Conceptual - Open Addressing: Linear Probing

This community-built FAQ covers the “Open Addressing: Linear Probing” exercise from the lesson “Hash Maps: Conceptual”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Computer Science

Complex Data Structures

FAQs on the exercise Open Addressing: Linear Probing

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

“When do you think we would use probing over other strategies?”

Would you use probing when you have a known total amount of possible keys? That way, you aren’t wasting array space, and you have a worst case computation time of a linked list (when all the hash buckets are full, and your hash function computes an index that leads to the longest possible ‘probing’).

1 Like

So basically we can only use probing when we know the array size is more than the no. of keys to be inputted or else we wont be able to input all the keys as the array would be full right?

hello lovely people <3 can someone simply and shortly explain the concept of linear probing?(when, why) thank you!

Hi,
In the context of the exercise for Linear Probing, when I enter the Hash Code 7 and the Probing Sequence 3,
I got “Can’t Place” message as in the screenshot below.
I don’t understand what should this means ?

1 Like

I agree with @method6654567550 . Please explain it in the lesson. I am here trying to learn, but being asked where I would use this. I don’t know, that is what I am trying to learn. If you give more context to the lesson it will be less frustrating and help us see the road ahead.

With several parts of this course it is like you are teaching me what a wheel is, but without telling me that you are talking about a bike. Or giving me context that this rolling thing is to move an object. Just a little understanding of the big picture first will help me understand why it is important to learn about the part.

Why are we learning about hash maps? How are they used in programs? What is the importance of the Key? How do we decide what Key to use? Is this a permanent form of memory or will it get wiped out when our program ends?

10 Likes

It means that given your hash code and probing sequence, there is no ‘empty’ slot in this array where the value could fit. All possible locations in your diagram have 'x’s (=are full).

I know this won’t be relevant to you anymore, but I was having the same confusion so here’s what I think needs clarifying.

Linear Probing is where if we encounter an occupied index, we move to index + x where x is a fixed amount (commonly 1).

If we change the probing sequence, we change the increment with which we move through the hash map. For example with a sequence of 2, we will not check if index + 1 is available, but we will check the availability of index + 2.

The screenshot shows that with the probing sequence of 3, we cant insert at 7, so we try moving to index + 3 (10) which is occupied. Because of the modulus nature of hash maps, when we get to the end of the hash map we “loop” to the beginning. Starting from our previous value of 10 and doing index + 3, we arrive at the hash 1 (11, 0, 1). Because of the length of this array, we will be cycling over the same values again and again when we do index + 3, meaning we never find an index to place our data at.

Hope this helps anyone else :slight_smile:

Hi. Thanks for the explanation. It seems to me that only a sequence of 1 is optimal for Linear Probing, as it insures all indexes of the array will be taken, before trying to add more elements than the arrays length. Would you agree with that?