Code Monkey home page Code Monkey logo

algos's Introduction

Practical Algorithms and Data Structures

Build Status

Practical Algorithms and Data Structures is a book originally adapted from Problem Solving with Algorithms and Data Structures Using Python which was written by Brad Miller and David Ranum and published under a Creative Commons license.

To build, run ./run build-book. Publishing occurs automatically via Travis.

To develop, first install wach and rld globally: npm install -g wach rld then ./run dev.

algos's People

Contributors

awillborn avatar bharatagarwal avatar caseros avatar chhhris avatar ekeric13 avatar elenasharma avatar ghabs avatar greg-finley avatar jcrben avatar jsgoller1 avatar michaelrbock avatar ozan avatar robertdapice avatar robot-dreams avatar samypesse avatar smart-alek avatar whatrocks avatar zackproser 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

algos's Issues

In parse tree example, enable multi-digit numbers

In the parse tree example, only expressions with single-digit integers are permitted. This is not made clear, so the example just breaks confusingly if tried with multi-digit numbers. It may be straightforward to modify the example to enable multi-digit numbers, without complicating the tokenization logic too much.

The issue for Shortest Path with Dijkstra’s Algorithm

Thanks for sharing this amazing work.

I feel like the algorithm in Shortest Path with Dijkstra’s Algorithm is not correct.
Since heapq won't update(sort) automatically after you update the value.

For example,
if I rename 'Z' to be 'A', it will first pop 'X' and then pop 'Z'. However, the distance to Z now is infinite. In this case it will work, but if we add another node 'B" which the shortest path from 'X' to 'B' is 'X' -> 'Z' -> 'B', then this algorithm won't work out.

example_graph = {
    'B': {'A': 9},
    'U': {'V': 2, 'W': 5, 'X': 1},
    'V': {'U': 2, 'X': 2, 'W': 3},
    'W': {'V': 3, 'U': 5, 'X': 3, 'Y': 1, 'A': 5},
    'X': {'U': 1, 'V': 2, 'W': 3, 'Y': 1},
    'Y': {'X': 1, 'W': 1, 'A': 1},
    'A': {'W': 5, 'Y': 1, 'B':9}
}
# calculate_distances(example_graph, 'X')
# => {'A': 2, 'B': inf, 'U': 1, 'V': 2, 'W': 2, 'X': 0, 'Y': 1}

Dijkstra's algorithm implementation is wrong in heapq usage

In "Shortest Path with Dijkstra’s Algorithm", the implementation used "entry_lookup[neighbor][0] = distance" to change entry value in heap.

This will not work because heap will not reorganize after this modification. One correct way to reorganize this heap is using heapq._siftdown function. You can find some reference here.

Implement language switching functionality

Readers should be able to switch between languages when reading a section of the book. The language switcher should determine which languages are available for a given section and present these options to the reader. The reader's latest choice should be remembered and considered the default.

Add a small meta section

Perhaps in the introduction, we should have a section which:

  1. References the original "Problem Solving with Algorithms and Data Structures Using Python" book and credits Brad Miller and David Ranum
  2. Notes that the book is Creative Commons
  3. Provides some guidance on how to report issues and make contributions
  4. Lists the current contributors
  5. Mentions and links to Bradfield

Remove redundant captions

Currently, almost all figures have a caption. This is a vestige of the original book; most of the captions add little value so should just be removed.

Add exercises

It may be useful to add a section to each chapter with corresponding exercises.

Representation of empty unordered list feels wrong

I have a feeling that the representation of an empty linked list shown here is wrong.

image

When declaring empty Unordered List with the definition given here: https://bradfieldcs.com/algos/lists/implementing-an-unordered-list/#the-unordered-list-class

class UnorderedList(object):

    def __init__(self):
        self.head = None

along with the definition of Node here:
https://bradfieldcs.com/algos/lists/implementing-an-unordered-list/#the-node-class

class Node(object):
    def __init__(self, value):
        self.value = value
        self.next = None

Declaring an UnorderedList, like so:

my list = UnorderedList()

The image seems to indicate that the item at the head is a grounded node. However, there is no notion of next when declaring self.head = None.

When adding a value to the list using add,

    def add(self, item):
        temp = Node(item)
        temp.next = self.head
        self.head = temp

This is the first time the notion of a node is introduced to the list. The type of head changes from None to Node, and my feeling is that an associated arrow is now justified.

I've sketched this out:

IMG_1745

Request to talk about how deque is implemented in Python

I've noticed a significant performance in the hot potato problem between using the naive implementation of Queue v/s the solution that uses collections.deque.

The naive implementation of Deque has similar performance issues, with insert and remove from left/rear requiring the whole array to move over.

CPython has an implementation using double linked lists, which could be worth talking about once the "Lists" section has been covered.

Move away from CDN

There are some assets that are currently served via a CDN. This introduces a new point of failure, and also makes it difficult to work on the book without internet access. We should move these to locally hosted copies.

Clarify list vs array language

Via @robertdapice in #48 :

  • The Binary Heap section is described as being implemented with the ‘list’ data structure. Should this be renamed to an ‘array’ data structure, given you’ve already addressed lists as an abstract data type (that itself is not, in fact, implemented with an array)?

Fix KaTeX subscript formatting

Via @robertdapice in #48 :

  • Markdown rendering is broken in a few places. Doesn't seem to be invalid markdown; could there be a bug in the markdown -> HTML library you're using? See example of putting Hexadecimals in number coding:
    markdown

Move all trees and graphs to svg

For consistency, ease of modification and scaling to high resolution, all of the tree and graph diagrams should be rendered with svg. There is proof-of-concept for this in the dynamic programming chapter.

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.