NeetCodeIO

Top 8 Data Structures for Coding Interviews.


You can download the high resolution version using the link at the bottom šŸ‘‡


1. Arrays

The most fundamental data structure. Arrays are stored contiguously in memory.

2. Linked Lists

These also store an ordered list of elements, but the values are not contiguous in RAM. Linked list nodes have pointers connecting them.

3. HashMaps

Probably the most useful data structure as well. They use a hash function to map keys to indexes within an array. This allows us to have an amortized time of O(1) for most operations.

4. Queues

Typically used to process elements in the same order as they are added. These follow a FIFO (first-in first-out approach). Queues can be double-ended, which allow you to add and remove elements from both the front and the back.

5. Trees

A Binary Tree is an ordered tree data structure where each node is connected to at most two more nodes (called the left and the right child). Being ordered means we can perform DFS and BFS in O(log n) time.

6. Tries/Prefix Trees

Here, each node represents a character in the alphabet and can have at most 26 children. This allows us to save space when inserting words. Tries are useful for auto-complete features and allow us to search for words using their prefix.

7. Heaps

Heaps are a nearly complete binary tree, with potentially the last level being not full. They are implemented with arrays under the hood. Heaps serve as priority queues, and always have the smallest (min-heap) or the largest (max-heap) item stored at the root node.

8. Graphs

A graph is a bunch of nodes (vertices) connected by edges. Linked Lists and Trees are also special type of graphs, but a more general graph can have an arbitrary number of vertices connected to it. A good way to represent graphs in interviews is through an adjacency list.


You can find the high resolution image & cheat sheet here: neetcode.io/courses/lessons/8-data-structures
(free & mobile friendly)

6 months ago | [YT] | 961



@shakibrahman

post lowkey linkedin coded

6 months ago | 7

@dukeofnorfolk1842

Hashmaps too overpowered

6 months ago | 0

@ipodtouch470

Everything is either a linked list or an array under the hood šŸ¤“

6 months ago | 0

@kamalchhimwal9362

for a hashmap it's best is O(1) and for worst case which occurs rarely it's O(n)

6 months ago | 0

@flaviomoreira01

It's unclear what you mean by O(n) time complexity on search on Map, do you mean searching the keys or values?

6 months ago | 5

@Preposterouss

What do you use to make these graphics?

6 months ago | 1

@sahanar5069

I’m confused! How is insert mid and remove mid for linked list O(1) ?

6 months ago | 8

@kamalchhimwal9362

lotsaa errors here

6 months ago | 0

@Baffah034.

ā¤

6 months ago | 0