1
1
{
2
2
"ArrayList" : {
3
- "addToFront" : {
4
- "name" : " Add to Front" ,
3
+ "Add to Front" : {
5
4
"best" : {
6
5
"big_o" : " O(n)" ,
7
- "explanation" : " You always have to shift every element to the left."
6
+ "explanation" : " You always have to shift $n$ elements to the right." ,
7
+ "example" : " [null, null, null, null] add 0"
8
8
},
9
9
"average" : {
10
10
"big_o" : " O(n)" ,
11
- "explanation" : " You always have to shift every element to the left."
11
+ "explanation" : " You always have to shift $n$ elements to the right." ,
12
+ "example" : " [1, 2, 3, null] add 0"
12
13
},
13
14
"worst" : {
14
15
"big_o" : " O(n)" ,
15
- "explanation" : " Resizing the array and shifting every element are each $O(n)$."
16
+ "explanation" : " Resizing the array and shifting $n$ elements are each $O(n)$." ,
17
+ "example" : " [1, 2, 3, 4] add 0"
16
18
}
17
19
},
18
- "addToBack" : {
19
- "name" : " Add to Back" ,
20
+ "Add to Back" : {
20
21
"best" : {
21
22
"big_o" : " O(1)" ,
22
23
"explanation" : " No shifting is needed because the array is not full."
30
31
"explanation" : " If the array is full, you have to resize it by making a new array."
31
32
}
32
33
},
33
- "removeAtIndex" : {
34
- "name" : " Remove at Index" ,
34
+ "Add at Index" : {
35
+ "best" : {
36
+ "big_o" : " O(1)" ,
37
+ "explanation" : " Adding to the back of the array."
38
+ },
39
+ "average" : {
40
+ "big_o" : " O(n)" ,
41
+ "explanation" : " Some elements will be shifted to the right; on average, $n/2$ will."
42
+ },
43
+ "worst" : {
44
+ "big_o" : " O(n)" ,
45
+ "explanation" : " Resizing the array and shifting every element are each $O(n)$."
46
+ }
47
+ },
48
+ "Remove from Front" : {
49
+ "all cases" : {
50
+ "big_o" : " O(n)" ,
51
+ "explanation" : " You always have to shift every element to the left."
52
+ }
53
+ },
54
+ "Remove from Back" : {
55
+ "all cases" : {
56
+ "big_o" : " O(1)" ,
57
+ "explanation" : " No shifting or resize is ever needed."
58
+ }
59
+ },
60
+ "Remove at Index" : {
35
61
"best" : {
36
62
"big_o" : " O(1)" ,
37
63
"explanation" : " If you remove the last element, you don't have to shift anything."
48
74
},
49
75
50
76
"Quicksort" : {
51
- "run " : {
77
+ "Quicksort " : {
52
78
"best" : {
53
79
"big_o" : " O(nlog(n))" ,
54
80
"explanation" : " The pivot is perfect (the median) in every partition." ,
55
81
"example" : " [3, 2, 4, 1, 5] with 3 as the pivot"
56
82
},
57
83
"average" : {
58
84
"big_o" : " O(nlog(n))" ,
59
- "explanation" : " On average, the data is split roughly in half each partition."
85
+ "explanation" : " On average, the data is split roughly in half each partition." ,
86
+ "example" : " [3, 2, 4, 1, 5, 6] with 3 as the pivot"
60
87
},
61
88
"worst" : {
62
89
"big_o" : " O(n²)" ,
63
- "explanation" : " The worst pivot (min or max) is chosen each partition, devolving into a selection sort."
90
+ "explanation" : " The worst pivot (min or max) is chosen each partition, devolving into a selection sort." ,
91
+ "example" : " [3, 2, 4, 1, 5] with 5 as the pivot"
64
92
}
65
93
}
66
94
}
67
- }
95
+ }
0 commit comments