What are the most common data structures and Big O for operations on them?

I'm trying to understand Big O concepts. It seems pretty abstract. I chose the most common data structures: an array, a hash, a linked list (single and double) and a binary search tree, and I guessed a bit in Big O notation for the most common operations - insert and search. This is a preparation for inerview. I need to learn only the basics that do not read the whole text on algorithms, although that would be ideal. Is the table below valid?

Data Structure Big O Search Big O Insert Array O(1) O(n) Hash O(1) O(1) Single Linked List O(n) O(1) Double Linked List O(n) O(1) Tree O(log n) O(log n) 
+6
source share
2 answers

For Array, O (1) is taken to get / return the element, but to search for the element, O (n) should be taken. For a tree, I assume that you had in mind a balanced binary search tree.

+2
source

For hash inserts, remember that O (1) is optimal. If your hash table is close to full, your efficiency will approach O (n).

Also, for a sorted array, the search is O (log n).

0
source

Source: https://habr.com/ru/post/899331/


All Articles