Linked Lists and Hashmaps

Linked lists and hashmaps are different types of arrays that store elements differently. Hashmaps are sometimes called associated arrays. The way they store elements changes the way in which we access the elements in the arrays, and changes the performance of the program when accessing the data.

Linked lists are like typical arrays, every element is stored in a simple serial list. Each element have a link to the next element in the array, these links are used when traversing the list. When we get the 3rd element in a linked list, the element at index 2, the program must start at index 0 and use the links to traverse the array until it gets to the required index.

Hashmaps use a key value pairs to store items into an array. The keys used are Strings variables, but the values can be any other variable type. Some programming languages will have strict arrays, meaning all the values have to be the same variable type, whereas other languages will have dynamic value types. Meaning the variables can be any data type, meaning you could have integers and booleans in the same dynamic hashmap.

Below is a small amount of example code to show how linked lists and hashmaps work, in regards to initilising the values. The linked list has number indexing, whereas the hashmap uses string key value pairs.

Leave a Reply