Giter Club home page Giter Club logo

algorithms-sedgewick-python's Introduction

Python 3.6 Python 3.7 Python 3.8 Python 3.9

algorithms-sedgewick-python

        Algorthms(4th edition) by Robert Sedgewick and Kevin Wayne exercises in python, all modules can be executed with doctest. Current Python Version is 3.6+, Python 2 will be not supported soon, if you're using Python 2, please switch to Python 3. Those non-programming exercises are not excluded, more exercises will be added in the future.

       More python algorithms can be found in here

       To excute doctest test cases in modules. Please run python -m doctest -v module_x_y.py.

algorithms-sedgewick-python's People

Contributors

cfsmile avatar changemyusername avatar timgates42 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

algorithms-sedgewick-python's Issues

TernarySearchTries -> Keys wrong?

Hallo .

Refering to chapter_5/module_5_2.py section TernarySearchTries I tried the keys()-method.

I inserted: ['she', 'sells', 'sea', 'shells', 'by', 'the', 'sea', 'shore'].

the result from keys() -> ['ea', 'ells', 'he', 'hells', 'hore']

Can you pls help me?

BR Johann

Wrong solution for stack copy

In the test example of 1.3.12 exercise, the first(or head) element of the stack should be 4, not 1. The copy of the stack is done in reverse, breaking it's structure:

I suppose it should be done through another temporary stack to ensure structure integrity:


    # 1.3.12 practice
    @classmethod
    def copy(cls, old_stack: Stack) -> None:
        """
        Copy existing stack and return new stack.
        Args:
            cls: Stack class
            stack (Stack): existing stack
        Returns:
            Stack: new stack
        >>> s = Stack()
        >>> s.push(1)
        >>> s.push(2)
        >>> s.push(3)
        >>> s_copy = Stack.copy(s)
        >>> s_copy._first.val
        3
        >>> s_copy.size()
        3
        >>> for item in s_copy:
        ...     print(item)
        ...
        3
        2
        1
        """
        s_tmp = cls()
        s_copy = cls()
        if isinstance(old_stack, Stack) and not old_stack.is_empty():
            for item in old_stack:
                s_tmp.push(item)
            for item in s_tmp:
                s_copy.push(item)
        return s_copy

O(N) time is expected.
But O(N) space, I don't think we can avoid that.

And I guess the constructor here should be changed too, because it has the same behaviour:

Maybe even make the option to make a copy in 'init' if there is a 'Stack' in 'args'.

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.