Difference between revisions of "Template:List data structure comparison"
Jump to navigation
Jump to search
imported>Jonesey95 m (Fixing "CS1 errors: dates" in citation.) |
imported>Kxx |
||
| Line 1: | Line 1: | ||
<div class=tright align=right> | <div class=tright align=right> | ||
| − | {|class="wikitable" | + | {|class="wikitable" style="width:0" |
| − | ! | + | |+ Comparison of list data structures |
| + | ! | ||
| + | ![[Linked list]] | ||
| + | ![[Array data structure|Array]] | ||
| + | ![[Dynamic array]] | ||
| + | ![[Self-balancing binary search tree|Balanced tree]] | ||
| + | ![[Random access list|Random {{nowrap|access list}}]] | ||
|- | |- | ||
|Indexing | |Indexing | ||
| Line 10: | Line 16: | ||
|style="background:#ffffdd"|Θ(log n) | |style="background:#ffffdd"|Θ(log n) | ||
|- | |- | ||
| − | |Insert/delete at beginning | + | |{{nowrap|Insert/delete}} at beginning |
|style="background:#ddffdd"|Θ(1) | |style="background:#ddffdd"|Θ(1) | ||
|{{n/a}} | |{{n/a}} | ||
| Line 17: | Line 23: | ||
|style="background:#ddffdd"|Θ(1) | |style="background:#ddffdd"|Θ(1) | ||
|- | |- | ||
| − | |Insert/delete at end | + | |{{nowrap|Insert/delete}} at end |
| − | |style="background:#ffffdd"|Θ(''n'') | + | |style="background:#ffffdd"|Θ(''n'') when last {{nowrap|element is unknown}};<br/>Θ(1) when last {{nowrap|element is known}} |
|{{n/a}} | |{{n/a}} | ||
|style="background:#ddffdd"|Θ(1) [[Amortized analysis|amortized]] | |style="background:#ddffdd"|Θ(1) [[Amortized analysis|amortized]] | ||
| Line 24: | Line 30: | ||
|style="background:#ffffdd"|Θ(log ''n'') updating | |style="background:#ffffdd"|Θ(log ''n'') updating | ||
|- | |- | ||
| − | |Insert/delete in middle | + | |{{nowrap|Insert/delete}} in middle |
| − | |style="background:#ddffdd"|search time + | + | |style="background:#ddffdd"|search time + {{nowrap|Θ(1)}}<ref>Gerald Kruse. [http://www.juniata.edu/faculty/kruse/cs240/syllabus.htm CS 240 Lecture Notes]: [http://www.juniata.edu/faculty/kruse/cs240/linkedlist2.htm Linked Lists Plus: Complexity Trade-offs]. Juniata College. Spring 2008.</ref><ref>[http://channel9.msdn.com/Events/GoingNative/GoingNative-2012/Keynote-Bjarne-Stroustrup-Cpp11-Style ''Day 1 Keynote - Bjarne Stroustrup: C++11 Style''] at ''GoingNative 2012'' on ''channel9.msdn.com'' from minute 45 or foil 44</ref><ref>[http://kjellkod.wordpress.com/2012/02/25/why-you-should-never-ever-ever-use-linked-list-in-your-code-again/ ''Number crunching: Why you should never, ever, EVER use linked-list in your code again''] at ''kjellkod.wordpress.com''</ref> |
|{{n/a}} | |{{n/a}} | ||
|style="background:#ffdddd"|Θ(''n'') | |style="background:#ffdddd"|Θ(''n'') | ||
| Line 31: | Line 37: | ||
|style="background:#ffffdd"|Θ(log ''n'') updating | |style="background:#ffffdd"|Θ(log ''n'') updating | ||
|- | |- | ||
| − | |Wasted space (average) | + | |{{nowrap|Wasted space}} (average) |
|style="background:#ffdddd"|Θ(''n'') | |style="background:#ffdddd"|Θ(''n'') | ||
|style="background:#ddffdd"|0 | |style="background:#ddffdd"|0 | ||
Revision as of 17:35, 31 August 2014
| Linked list | Array | Dynamic array | Balanced tree | Random access list | |
|---|---|---|---|---|---|
| Indexing | Θ(n) | Θ(1) | Θ(1) | Θ(log n) | Θ(log n) |
| Insert/delete at beginning | Θ(1) | N/A | Θ(n) | Θ(log n) | Θ(1) |
| Insert/delete at end | Θ(n) when last element is unknown; Θ(1) when last element is known |
N/A | Θ(1) amortized | Θ(log n) | Θ(log n) updating |
| Insert/delete in middle | search time + Θ(1)[1][2][3] | N/A | Θ(n) | Θ(log n) | Θ(log n) updating |
| Wasted space (average) | Θ(n) | 0 | Θ(n)[4] | Θ(n) | Θ(n) |
References
- ↑ Gerald Kruse. CS 240 Lecture Notes: Linked Lists Plus: Complexity Trade-offs. Juniata College. Spring 2008.
- ↑ Day 1 Keynote - Bjarne Stroustrup: C++11 Style at GoingNative 2012 on channel9.msdn.com from minute 45 or foil 44
- ↑ Number crunching: Why you should never, ever, EVER use linked-list in your code again at kjellkod.wordpress.com
- ↑ Brodnik, Andrej; Carlsson, Svante; Sedgewick, Robert; Munro, JI; Demaine, ED (1999), Resizable Arrays in Optimal Time and Space (Technical Report CS-99-09) (PDF), Department of Computer Science, University of Waterloo