-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathData Structures Cheat Sheet.html
145 lines (139 loc) · 4.26 KB
/
Data Structures Cheat Sheet.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!-- saved from url=(0050)https://www.clear.rice.edu/comp160/data_cheat.html -->
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Data Structures Cheat Sheet</title>
<style type="text/css">
body
{
font-family: Arial, Helvetica, sans-serif;
max-width: 1024px;
}
a { color: blue; text-decoration: none }
a:hover { text-decoration: underline }
.nav { font-size: 70%; }
h1, div.nav { text-align: center; }
h1 { color: #09f; }
table { font-size: 10pt }
td,th { text-align: center; width: 11% }
td.bad { background-color: pink; color: #900 }
td.good { background-color: #9ec; color: green }
td.range { background-color: #fe9; color: #d73 }
td.na { background-color: #cff }
td.notes { text-align: left; font-size: 70% }
</style>
</head>
<body>
<h1>Data Structures Cheat Sheet</h1>
<div class="nav">[<a href="https://www.clear.rice.edu/comp160/data1.html">Data Structures I</a>]
[<a href="https://www.clear.rice.edu/comp160/data2.html">Data Structures II</a>]
[<a href="https://www.clear.rice.edu/comp160/data3.html">Data Structures III</a>]
[<a href="https://www.clear.rice.edu/comp160/data4.html">Data Structures IV</a>]
[<strong>Data Structures Cheat Sheet</strong>]</div>
<hr>
<table width="100%" cellspacing="0" cellpadding="10">
<tbody><tr>
<td></td>
<td>add to end</td>
<td>remove from end</td>
<td>insert at middle</td>
<td>remove from middle</td>
<td>Random Access</td>
<td>In-order Access</td>
<td>Search for specific element</td>
<th>Notes</th>
</tr>
<tr>
<td>Array</td>
<td class="bad">O(n)</td>
<td class="bad">O(n)</td>
<td class="bad">O(n)</td>
<td class="bad">O(n)</td>
<td class="good">O(1)</td>
<td class="good">O(1)</td>
<td class="bad">O(n)</td>
<td class="notes">Most efficient use of memory; use in cases where data size is fixed.</td>
</tr>
<tr>
<td>List<T></td>
<td class="range">best case O(1); worst case O(n)</td>
<td class="good">O(1)</td>
<td class="bad">O(n)</td>
<td class="bad">O(n)</td>
<td class="good">O(1)</td>
<td class="good">O(1)</td>
<td class="bad">O(n)</td>
<td class="notes">Implementation is optimized
for speed. In many cases, List
will be the best choice.
</td>
</tr>
<tr>
<td>Collection<T></td>
<td class="range">best case O(1); worst case O(n)</td>
<td class="good">O(1)</td>
<td class="bad">O(n)</td>
<td class="bad">O(n)</td>
<td class="good">O(1)</td>
<td class="good">O(1)</td>
<td class="bad">O(n)</td>
<td class="notes">List is a better choice, unless
publicly exposed as API.
</td>
</tr>
<tr>
<td>LinkedList<T></td>
<td class="good">O(1)</td>
<td class="good">O(1)</td>
<td class="good">O(1)</td>
<td class="good">O(1)</td>
<td class="bad">O(n)</td>
<td class="good">O(1)</td>
<td class="bad">O(n)</td>
<td class="notes">Many operations are fast,
but watch out for cache
coherency.
</td>
</tr>
<tr>
<td>Stack<T></td>
<td class="range">best case O(1); worst case O(n)</td>
<td class="good">O(1)</td>
<td class="na">N/A</td>
<td class="na">N/A</td>
<td class="na">N/A</td>
<td class="na">N/A</td>
<td class="na">N/A</td>
<td class="notes">Shouldn't be selected for
performance reasons, but
algorithmic ones.
</td>
</tr>
<tr>
<td>Queue<T></td>
<td class="range">best case O(1); worst case O(n)</td>
<td class="good">O(1)</td>
<td class="na">N/A</td>
<td class="na">N/A</td>
<td class="na">N/A</td>
<td class="na">N/A</td>
<td class="na">N/A</td>
<td class="notes">Shouldn't be selected for
performance reasons, but
algorithmic ones.
</td>
</tr>
<tr>
<td>Dictionary<K,T></td>
<td class="range">best case O(1); worst case O(n)</td>
<td class="good">O(1)</td>
<td class="range">best case O(1); worst case O(n)</td>
<td class="good">O(1)</td>
<td class="good">O(1)*</td>
<td class="good">O(1)*</td>
<td class="good">O(1)</td>
<td class="notes">Although in-order access time
is constant time, it is usually slower than other structures due to the over-head of looking up the key.
</td>
</tr>
</tbody></table>
</body></html>