Skip to content

Commit e095cbe

Browse files
authored
Update time_complexities.json
1 parent 2837bf4 commit e095cbe

File tree

1 file changed

+41
-13
lines changed

1 file changed

+41
-13
lines changed

src/time_complexities.json

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
{
22
"ArrayList": {
3-
"addToFront": {
4-
"name": "Add to Front",
3+
"Add to Front": {
54
"best": {
65
"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"
88
},
99
"average": {
1010
"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"
1213
},
1314
"worst": {
1415
"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"
1618
}
1719
},
18-
"addToBack": {
19-
"name": "Add to Back",
20+
"Add to Back": {
2021
"best": {
2122
"big_o": "O(1)",
2223
"explanation": "No shifting is needed because the array is not full."
@@ -30,8 +31,33 @@
3031
"explanation": "If the array is full, you have to resize it by making a new array."
3132
}
3233
},
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": {
3561
"best": {
3662
"big_o": "O(1)",
3763
"explanation": "If you remove the last element, you don't have to shift anything."
@@ -48,20 +74,22 @@
4874
},
4975

5076
"Quicksort": {
51-
"run": {
77+
"Quicksort": {
5278
"best": {
5379
"big_o": "O(nlog(n))",
5480
"explanation": "The pivot is perfect (the median) in every partition.",
5581
"example": "[3, 2, 4, 1, 5] with 3 as the pivot"
5682
},
5783
"average": {
5884
"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"
6087
},
6188
"worst": {
6289
"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"
6492
}
6593
}
6694
}
67-
}
95+
}

0 commit comments

Comments
 (0)