GithubHelp home page GithubHelp logo

amanattar / dsa Goto Github PK

View Code? Open in Web Editor NEW

This project forked from thisisshub/dsa

0.0 0.0 0.0 344 KB

A DSA repository but everything is in python.

Home Page: http://thisisshub.github.io/DSA

License: MIT License

Python 100.00%

dsa's Introduction

DSA

Status

Travis (.org) Codacy grade Donateย  GitHub repo size Lines of code

GitHub pull requests GitHub issues GitHub forks GitHub Repo stars GitHub watchers GitHub

Contents

Ugh, not another DSA repository but anyway. What the fork is this?

This repository is the implementation of the contents DSA self paced series by yours truly but in Python

Aren't we supposed to learn DSA in say C++?

YOU SHOULD but we both know you won't or can't write C++

So, what's up with your code? Why should I look into it?

Yours truly for each topic he came across has written the code in 1-2 or more than 2 methods which perform the exact same task. So that you could choose whichever method works for you. Each method is tested under the tests/ with pytest

So what's the difference between method 1 and 2?

Well, if you look closely, I mean really closely you could see the timeit module in __main__ which shows the time taken by that particular function to run

def method1(n: int) -> int:
    return len(str(n)) if n >= 0 else len(str(n)) - 1


def method2(n: int) -> int:
    import math

    return int(math.log10(n) + 1 if n > 0 else (1 if n == 0 else math.log10(-n) + 1))


if __name__ == "__main__":
    """
    from timeit import timeit
    print(timeit(lambda: method1(1234567890), number=10000)) # 0.0022839140001451597
    print(timeit(lambda: method2(1234567890), number=10000)) # 0.004222848001518287
    """

So is the time taken by timeit reliable?

Fork no, but still for the best result I ran the methods 10 thousand times each. My machine is Asus-UX425JA with Fedora 33 on kernel 5.9 with several stackoverflow tabs and a spotify tab open when I ran each timeit

TODO:

Contributors

dsa's People

Contributors

thisisshub avatar amanattar avatar theprogrammergod avatar sangeetasingh17 avatar

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.