Giter Site home page Giter Site logo

fossabot / algorithm-implementations Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gregismotion/algorithm-implementations

0.0 1.0 0.0 28 KB

I always update this repository with algorithm implementations from "Introduction to algorithms (Third Edition)".

License: GNU General Public License v3.0

Python 100.00%

algorithm-implementations's Introduction

Algorithm-implementations

insertion-sort.py

How does it work?

Insertion Sort algorithm visualisation FOSSA Status

Insertion Sort (I'm going to call it "the algorithm", I don't want to type too much), sort one element at the time. It's not efficient on a large number of data.

Then where you can use it?

  • If you have an almost sorted data set, it will be a lot faster than any algorithm.
  • It can sort the data set while it receives it.
  • It's really simple to implement, you can create a three-line version of it in C.
for (i = 1; i < n; i++)
  for (j = i; j > 0; j--)
    if (a[j] < a[j-1]) swap(a[j], a[j-1])

Example

$: python insertion-sort.py 1 7 3 4 8 2 3 5 9 10 
[1, 7, 3, 4, 8, 2, 3, 5, 9, 10]
[1, 2, 3, 3, 4, 5, 7, 8, 9, 10]

insertion-sort-nonincreasing.py

It's the same as the 'insertion-sort.py', just it puts the array in decreasing order.

Example

$: python insertion-sort-nonincreasing.py 1 3 3 5 4
[1, 3, 3, 5, 4]
[5, 4, 3, 3, 1]

License

FOSSA Status

algorithm-implementations's People

Contributors

fossabot avatar

Watchers

 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.