Skip to content

Commit 3bf33f0

Browse files
committed
adding time complexity for divide and conquer
1 parent 1d6dcf8 commit 3bf33f0

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

ipython_nbs/essentials/divide-and-conquer-algorithm-intro.ipynb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,19 @@
374374
"print(lst5[::-1], '->', majority_ele_dac(lst=lst5[::-1]))"
375375
]
376376
},
377+
{
378+
"cell_type": "markdown",
379+
"metadata": {},
380+
"source": [
381+
"In algorithms such as binary search that we saw at the beginning of this notebook, we recursively break down our problem into smaller subproblems. Thus, we have a recurrence problem with time complexity\n",
382+
"\n",
383+
"$T(n) = T(\\frac{2}{n}) + O(1) \\rightarrow T(n) = O(\\log n).$\n",
384+
"\n",
385+
"In this example, finding the majority element, we break our problem down into only 2 subproblems. Thus, the complexity of our algorithm is\n",
386+
"\n",
387+
"$T(n) = 2T (\\frac{2}{n} + O(n) \\rightarrow T(n) = O(n \\log n).$"
388+
]
389+
},
377390
{
378391
"cell_type": "markdown",
379392
"metadata": {},

0 commit comments

Comments
 (0)