Giter Site home page Giter Site logo

gustavo-depaula / stalin-sort Goto Github PK

View Code? Open in Web Editor NEW
1.5K 10.0 175.0 1.06 MB

Add a stalin sort algorithm in any language you like ❣️ if you like give us a ⭐️

License: MIT License

JavaScript 2.29% C 10.42% Python 19.76% Go 3.54% Ruby 0.93% Kotlin 10.64% C# 9.99% Gnuplot 0.25% Haskell 1.25% Brainfuck 0.60% Java 6.01% Haxe 1.03% Perl 2.61% PHP 0.83% Swift 2.32% Erlang 0.60% Standard ML 1.42% C++ 22.61% Lua 1.52% Common Lisp 1.39%
stalin-sort hacktoberfest

stalin-sort's Introduction

Welcome to the Stalin Sort Repo 📋

poster

What is Stalin Sort? ❓

Introduction

Stalin Sort is an efficient sorting algorithm, serving as a systematic method for placing the elements of a random access file or an array in order. Stalin Sort is also know as the best sorting algorithm of all times because of its AMAZING capacity of always ordering an array with an O(n) performance.

How it works?

It's simple, all you need to do is iterate through the array, checking if its elements are in order. Any element that isn't in order you pull out, in other words, you send it to Gulag.

Step-by-step example

  1. (1 2 5 3 5 7) -> (1 2 5 3 5 7) Here the algorithm stores the first of element of the array
  2. (1 2 5 3 5 7) -> (1 2 5 3 5 7) Now it will compare the stored element with the second one, if this is bigger than the stored, it replaces the stored element by this
  3. (1 2 5 3 5 7) -> (1 2 5 3 5 7) Repeats step 2
  4. (1 2 5 3 5 7) -> (1 2 5 5 7) Since the 4th element is smaller than the 3rd one, the 4th element will be eliminated.
  5. (1 2 5 5 7) -> (1 2 5 5 7) Equal elements are preserved
  6. (1 2 5 5 7) Ordered array!

Pseudocode implementation

Keep in mind that this is pseudocode, and is just an example. We strongly encourage you to code a different approach.

FUNCTION stalinSort(A : list OF sortable items)
    n := length(A)
    bigger := 0
    B SET empty list

    FOR i := 0 TO n NOT inclusive DO
        IF A[i] >= bigger THEN
          bigger := A[i]
          B.push(A[i])
        END IF
    END FOR

    RETURN B
END FUNCTION

Want to help? 🙌

Please check the CONTRIBUTING.md

Give this Project a Star! ⭐

About

Stalin sort began first as a Hacktoberfest 2018 repo

Hacktoberfest is a program organised by Digital Ocean and Github, where you can easily win a T-Shirt just by making 5 pull requests in the month of October to any open source projects on Github.

stalin-sort's People

Contributors

89netram avatar alphya avatar antonrud avatar artoria2e5 avatar chunkybanana avatar deiuch avatar dxeoane avatar eboru avatar elliotwutingfeng avatar fsandhei avatar gabrielcarneiro97 avatar gaburielcasado avatar graudtv avatar gustavo-depaula avatar hy60koshk avatar julian-borbeck avatar kentarousuzuki avatar luksamuk avatar matteusan avatar mogron avatar nagataaaas avatar plokmijnuhby avatar robthree avatar seltyk avatar tmaxthomas avatar uhthomas avatar victorperin avatar vijiatjack avatar watosar avatar wpwoodjr 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

stalin-sort's Issues

Peer Review

It seems like you have implemented StalinSort in more than 30 languages. But have the source codes been peer reviewed enough so that they only contain generic template classes that permits the development of general programs, and do not depend on the underlying container.

I really like this idea because it avoids function overhead and pays strict attention to time complexity of algorithm (always O(N)). But I hope this repository actually provide a structured generic components that can actually be used in a seamless way.

More precise algorithm definition

As this project gets larger and larger, lol, we may need a less vague algorithm definition than a tweet so that it is easier to know if a PR is wrong.

Test folder

I belive that would be good to have a folder with some default inputs and outputs, so anyone that wants to add some solution in any given language must post with it the outputs of his code too, its kind important to have some sort of validation to the added codes.

My idea is to create a folder with numbered folders in it, related to the number of the test, so if exists 20 tests, the folder tests will contain 20 folders numbered from 1 to 20.

stalin-sort/tests/1...20

In each of this folders will exist 2 .txt files, one called input and other one called output. This files will contain numbers with pipes ( | ) between them.

EXAMPLE

stalin-sort/tests/1

input.txt

1|2|3|4|5|2

output.txt

1|2|3|4|5

Proposal: LeninSort

Example

  1. (1 2 5 3 5 7) -> total = 23, avg = 3.8
  2. (1 2 5 3 5 7) -> low < 3.8
  3. (1 2 5 3 5 7) -> high > 3.8
  4. (1 2 5 3 5 7) -> (1 2 3) save low in source, (5 5 7) move high to other container

Additional steps:
5. Try sort other containers with LeninSort
6. Merge all first containers
7. You can sort merged container with StalinSort

BogoStalinSort

I propose addition of a new sorting algorithm which combines the best features of both stalinsort and bogosort.

The algorithm is fairly simple:
Just randomly remove elements until the array is in order.

Complexity ranges from O(n) to O(n²)

Hope this will make the world a better place!

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.