STL and Big O Cheat Sheet


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)


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值