Fix: Minor indentation Changes

This commit is contained in:
Riya Bansal 2019-10-12 16:20:51 +05:30 committed by GitHub
parent f509a08c36
commit f700d74ba1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -23,7 +23,7 @@ __Intuition__
The main idea is to represent a problem in terms of one or more smaller problems, and add one or more base conditions that stop the recursion.
_For example_, we compute factorial n if we know factorial of (n-1). The base case for factorial would be n = 0. We return 1 when n = 0.
-- --
Power
-----
@ -35,7 +35,7 @@ def pow(n, k):
if k == 0: return 1
return n*pow(n, k - 1)
```
__Time Complexity__: $O(n)$
__Time Complexity__: O(n)
__Optimised solution:__
```python
@ -54,7 +54,7 @@ To allow reuse of answers.
<img src="https://user-images.githubusercontent.com/35702912/66316190-d30e1f00-e934-11e9-8089-85c6dc69baa7.jpg" data-canonical-src="https://user-images.githubusercontent.com/35702912/66316190-d30e1f00-e934-11e9-8089-85c6dc69baa7.jpg" width="500" />
__Time Complexity__ (assuming all multiplications are O(1))? $O(\log_2 k)$
__Time Complexity__ (assuming all multiplications are O(1))? O(\log_2 k)$O(\log_{2}k)$
Break it into 3 parts? k//3 and take care of mod1 and mod2.
@ -71,7 +71,7 @@ The idea is to consider two cases for every element.
(i) Consider current element as part of current subset.
(ii) Do not consider current element as part of current subset.
Number of subsets? $2^n$
Number of subsets? $2^{n}$
Explain that we want combinations, and not permutations. [1, 4] = [4, 1]
@ -164,7 +164,7 @@ def subsets(A, i, aux, p):
no_take = subsets(A, i+1, aux, False)
```
__Time Complexity__: $O(2^n)$
__Time Complexity__: $O(2^n)$ <br>
__Space Complexity__: $O(n^2)$, because we're creating new aux arrays.
-- --
@ -228,7 +228,7 @@ def subsetSum2(A,N,cur_sum, i, target):
no_take = subsetSum2(A,N,cur_sum, i+1, target)
return take + no_take
```
__Time Complexity__ : $O(2 ** (Target/MinElement))$
__Time Complexity__ : $O(2 ** (Target/MinElement))$ <br>
__Space Complexity__: $O(Target/Min Element)$