您的位置:首页 > 其它

STL and Big O Cheat Sheet

2015-10-27 18:53 316 查看
Name: list

Purpose:Linked list

Usage: list<int> x; x.push_back(5);

Insertingan item (top, middle*, or bottom):
O(1)

Deletingan item (top, middle*, or bottom): O(1)

Accessingan item (top or bottom):
O(1)

Accessingan item (middle): O(n)

Findingan item:
O(n)

*Butto get to the middle, you may have to first iterate through X items, at cost
O(x)

Name: vector

Purpose: Aresizable array

Usage: vector<int>v; v.push_back(42);

Insertingan item (top, or middle):
O(n)

Insertingan item (bottom): O(1)

Deletingan item (top, or middle):
O(n)

Deletingan item (bottom): O(1)

Accessingan item (top, middle, or bottom):
O(1)

Findingan item:
O(n)

Name: queue
and stack

Purpose:Classic stack/queue

Usage: queue<long> q; q.push(5);

Insertinga new item: O(1)

Poppingan item: O(1)

Examiningthe top: O(1)

Name: map

Purpose: Mapsone item to another

Usage: map<int,string>m; m[10] = “Bill”;

Insertinga new item: O(log2n)

Findingan item: O(log2n)

Deletingan item: O(log2n)

Name: set

Purpose:Maintains a set of unique items

Usage: set<string> s; s.insert(“Ack!”);

Insertinga new item: O(log2n)

Findingan item: O(log2n)

Deletingan item: O(log2n)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: