Log in from a computer to take this course

You'll need to log in from a computer to start Introduction to Algorithms and Linear Data Structures in Swift. But you can practice or keep up your coding streak with the Codecademy Go app. Download the app to get started.

apple storegoogle store
Learn

We have a hash table implementation, but what happens when two different keys generate the same index? Run the code in HashTable.swift to see a collision in action.

Instead of returning "Marsh Plant" and "Wild Animal", we retrieve "Wild Animal" twice. This is because both key-value pairs are assigned to the same index 0 and the first value, "Marsh Plant" was overwritten.

When two different keys resolve to the same array index, this is called a collision. In our current implementation, all keys that resolve to the same index are treated as if they are the same key. This is a problem because they will overwrite one another’s values.

Instructions

1.

Run the code in the text editor to see the result of a collision between two keys and notice that the value "reed" and "deer" both return "Wild Animal".

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?