Skip to content

Commit ce0bbc7

Browse files
authored
Time complexity of both pop() and append() and O(1)
1 parent f39a8cd commit ce0bbc7

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

[2018] Python Heaps-ters/python-heaps-ters.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -934,8 +934,8 @@
934934
" else:\n",
935935
" maximums.sort(reverse=True) # O(k log k)\n",
936936
" if n > maximums[-1]: # the minimum\n",
937-
" maximums.pop() # O(k)\n",
938-
" maximums.append(n) # O(k)\n",
937+
" maximums.pop() # O(1)\n",
938+
" maximums.append(n) # O(1)\n",
939939
" return maximums\n",
940940
"\n",
941941
"find_maximums(\"lots-of-numbers.txt\", 3)"
@@ -945,7 +945,7 @@
945945
"cell_type": "markdown",
946946
"metadata": {},
947947
"source": [
948-
"- Each loop is $\\mathcal{O}(k \\log k) + \\mathcal{O}(2k) = \\mathcal{O}(k \\log k)$\n",
948+
"- Each loop is $\\mathcal{O}(k \\log k) + \\mathcal{O}(2) = \\mathcal{O}(k \\log k)$\n",
949949
"- Total complexity: $\\mathcal{O}(k \\log k) \\times n = \\mathcal{O}(k \\log k \\times n)$"
950950
]
951951
},

0 commit comments

Comments
 (0)