amolnayak311 / algorithms-illuminated Goto Github PK
View Code? Open in Web Editor NEWMy notes for Tim Roughgarden's awesome course on Algorithms and his 4 part books
My notes for Tim Roughgarden's awesome course on Algorithms and his 4 part books
There is a typo in Line 52 in the equation in the introduction.ipynb file in the discussion of the recursive implementation of multiplying two integer numbers. The original equation is (Line 52):
x.y = (10^ {n/2}.a + b) \times (10^ {n/2}.c + d) = 10^n.ab + 10^{n/2}.(a.d + b.c) + b.d
The correct equation should be:
x.y = (10^ {n/2}.a + b) \times (10^ {n/2}.c + d) = 10^n.ac + 10^{n/2}.(a.d + b.c) + b.d
I think the solution to problem 2.1 is wrong.
I believe the crux of the issue is that f(n) = O(g(n))
doesn't imply lg f(n) = O(lg g(n))
.
A counterexample is f(n) = 2
and g(n) = 1
for all n, then f(n) lg f(n)
equals 2
and g(n) lg g(n)
equals 0
and we cannot bound f(n) lg f(n)
from above by g(n) lg g(n)
.
If taking constant functions feels funny, try f(n) = 2 - exp(-n)
and g(n) = 1 + exp(-n)
.
Hi,
I tried to decrease in a matrix a value -1 - I made it -3, and result is giving me 9 as a local minima, which is surely not local minima:
import numpy as np
# Assumption is that the matrix has unique numbers
def localminima1(matrix):
m = matrix.shape[1] // 2 # Num cols
i_minval = np.argmin(matrix[:, m]) # Done in O(n)
min_val = matrix[i_minval, m]
# Comparison done in constant time, the recursive calls would be done log n times
left_val = matrix[i_minval, m - 1] if m > 0 else float("inf")
right_val = matrix[i_minval, m + 1] if m < matrix.shape[1] - 1 else float("inf")
if min_val < left_val and min_val < right_val:
return (m, i_minval)
else:
return (
localminima1(matrix[:, 0:m])
if left_val < min_val
else localminima1(matrix[:, (m + 1) :])
)
# fmt:off
array = np.matrix([
[1, 2, 5, 4],
[0, -2, 9, 6],
[7, -3, 3, 10],
[11, 12, 13, 14]
])
# fmt:on
print("Input is\n", array)
ix = localminima1(array)
print("\nA local minima is at", ix, "with value", array[ix])
Result:
[[ 1 2 5 4]
[ 0 -2 9 6]
[ 7 -3 3 10]
[11 12 13 14]]
A local minima is at (1, 2) with value 9
Hi,
What program did you use to make those diagrams and images?
ConventionalMultiplication.png
ConventionalMultiplication.png
MergeSortIllustration.png
Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.