开发者

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

开发者 https://www.devze.com 2023-04-13 07:55 出处:网络
I am trying to get a grasp on Big O notations.It seems pretty abstract.I selected the most common data structures - array, hash, linkedl list (single and double) and a binary search tree and guessed s

I am trying to get a grasp on Big O notations. It seems pretty abstract. I selected the most common data structures - array, hash, linkedl list (single and double) and a binary search tree and guessed somewhat at the Big O notation for 开发者_开发百科the most common operatons - insert and search. This is preparation for an inerview. I need to learn just the basics not read a whole text book on algorithms though this 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)


For Array, to get/return an element takes O(1), but to search for an element should take O(n). For Tree, I assume that you meant balanced binary search tree.


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, searching is O(log n).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号