GithubHelp home page GithubHelp logo

amolnayak311 / algorithms-illuminated Goto Github PK

View Code? Open in Web Editor NEW
158.0 16.0 95.0 21.46 MB

My notes for Tim Roughgarden's awesome course on Algorithms and his 4 part books

Jupyter Notebook 100.00%

algorithms-illuminated's People

Contributors

amolnayak311 avatar denisbogdanov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

algorithms-illuminated's Issues

typo in an equation in introduction.ipynb

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

Problem 2.1

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).

Local Minima is probably not working right.

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

Problem 1.3 seems correct, but justification seems wrong

The justification to problem 1.3 isn't squaring up for me:
image
For n=2 and k=4, (2*4(4 - 1)/ 2) = 12. But here's what I expect:
merge 1: 2 + 2
merge 2: 4 + 2
merge 3: 6 + 2
total: 18 operations

What gives? Thank you in advance!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.