Giter Site home page Giter Site logo

lucaspilla / sorting-algorithms-visualizer Goto Github PK

View Code? Open in Web Editor NEW
397.0 14.0 152.0 76.7 MB

Program made with Python and Pygame module for visualizing sorting algorithms

License: MIT License

Python 100.00%
pygame python sorting visualization algorithms

sorting-algorithms-visualizer's Introduction

Sorting-Algorithms-Visualizer

Program made with Python and Pygame module for visualizing sorting algorithms
Support this project by leaving a ⭐

Program

"Program Preview"

Some Algorithms

Bubble sort Bucket sort Cocktail sort
Counting sort Heap sort Insertion sort
Merge sort Quick sort Selection sort

Using the application

❗ Feel free to open an issue if you have some problem ❗

  • Clone GitHub repository git clone https://github.com/LucasPilla/Sorting-Algorithms-Visualizer.git
  • Install requirements: pip3 install -r requirements.txt
  • Run: python3 src/main.py

Contributors

sorting-algorithms-visualizer's People

Contributors

aewens avatar aolaria avatar apurvai007 avatar arturoemmanueltoledoaguado avatar aswarth123 avatar athelian avatar bdanzig avatar glacialblaze avatar jadenleake avatar kiyami avatar lucaspilla avatar lucasrafaldini avatar lucblassel avatar lwinkler-cloudflight avatar mikhaylov-yv avatar mugulmd avatar niharika11031997 avatar pedrodke avatar prmurphy avatar rx112358 avatar saisrichandra avatar serhiilikh avatar slefforge avatar squarebat avatar swarpatel23 avatar system1970 avatar velin-todorov avatar viveksoundrapandy avatar yashukalkar avatar yuchenliu15 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

sorting-algorithms-visualizer's Issues

Add default values

I got this error here: "ValueError: invalid literal for int() with base 10: ''"

main.py
32 display.numBars = int(display.sizeBox.text)

Tell me what am I doing wrong?

Program Interface

This is the current display:

image

This is my suggestion:

image

For algorithms:

  1. It does not overlap things at its back
  2. It is scalable when more algorithms are introduced
  3. It is more orderly and tidy

For the action buttons, the play becomes pause when sorting and vice versa. The stop button is always there so that at any state, the user can opt to finish it.

Implement Gnome Sort

  • Implement the algorithm
  • Insert it in a file gnomeSort.py inside algorithms directory
  • In algorithms/__init__.py:
    Add: from algorithms.gnomeSort import gnomeSort
    Add in __all__: "gnomeSort",
  • Add gnomesort to algorithmsDict in algs.py
    If you manage to use the handleDrawing function I would appreciate!

Turning Sorting Functions into Generators

@mugulmd

Let our first step be changing sorting functions into generators. Can we make a branch of the original code where only the functions are changed, so that we can see how the generators would perform on the original code?

Create a .gitignore file

Add a .gitignore file for python (and for vscode or any IDE you're using)

Reason:

  • Adding individual files for tracking becomes tedious as the repository grows
  • We don't need to track pycache folders and other IDE config files

How to do:

.gitignore files are readily available on the internet, all you have to do is look up the appropriate content and copy-paste it

Implement drop List to select algorithm

Currently you have to write the algorithm name to run it, eg: mergesort, the idea is to make a drop list that shows all algorithms and the user can select just by pressing it!
Use pygame preferably, but if you find a much easier and cleaner way do it!

Implement Strand Sort

I can not import my module strand sort in the file init.py, the terminal show import error

Make this pygame program a executable

If possible I would like to make this pygame program a unique executable, using pyinstaller for exemple!
I tried working with pyintaller but had no success.

Suggestion: Might need to add documentation on which version of python to run

Is the program intended to be run with python 3 or python 2?

As I was attempting to run the program for the first time, I had to change a few pieces of syntax to get the program to work with the python version 2.7.15 that I was using. Specifically, I had to make three changes:

1.) Changed any instance of the super() function in the display.py file from super() to super(subclassName, self)

2.) Changed a function definition in combSort.py from def get_gap(prev_gap) -> int: to def get_gap(prev_gap):

3.) Changed the order of the arguments in the shellSort() function in the shellSort().py file.

The program worked just fine after making those couple of syntax changes. I'm sure it would've worked fine if I was running python3, but you might want to add some documentation letting new users know which version of python to use with the program.

I'd be happy to add to the documentation if you think that's a needed addition!

Restructure the code

Currently:

  • There is a file "algs.py" with all algorithms in it.

How it should be:

  • Each algorithm in a unique file.
  • The file algs.py must contain the algorithmsDict and the function runAlgorithm, ONLY.

Implement Comb Sort

  • Implement the algorithm
  • Insert it in a file combSort.py inside algorithms directory
  • In algorithms/__init__.py:
    Add: from algorithms.combSort import combSort
    Add in __all__: "combSort",
  • Add combsort to algorithmsDict in algs.py
    If you manage to use the handleDrawing function I would appreciate!

[BUG]Array size input validation

Array Size input validation
Input size is not validate causing program to crash when input size of array is to big ~100000000 or 0 or none
labels: user-experience
assignees: 'Self-assigned'

I will change the code to make validation on the size to be in range (0,500000)

image

Implement OddEvenSort

from display import handleDrawing

def swap(array,i,j):
    temp = array[i]
    array[i] = array[j]
    array[j] = temp

def oddevenSort(array, *args):
    sorted = False
    while not sorted:
        sorted = True
        for i in range(1,len(array)-1,2):
            handleDrawing(array,i,i+1,-1,-1)
            if array[i] > array[i+1]:
                swap(array,i,i+1)
                sorted = False
        
        for i in range(0,len(array)-1,2):
            handleDrawing(array,i,i+1,-1,-1)
            if array[i] > array[i+1]:
                swap(array,i,i+1)
                sorted = False

Tested and works.

Create requirements.txt

  • A requirements.txt is helpful for other developers who wants to run this program to install the correct version of the packages

Do:

pip freeze > requirements.txt

Nit: Wrong Credit

Sorry to bother, just wanted to let you know the credit is wrong ( I did the one on the left):

image

Implement Wiggle sort

Wiggle sort:
An integer array nums, reorder it such that nums[0] < nums[1] > nums[2] < nums[3]....

Example 1:
Input: nums = [1,5,1,1,6,4]
Output: [1,6,1,5,1,4]
Explanation: [1,4,1,5,1,6] is also accepted.
Example 2:

Input: nums = [1,3,2,2,3,1]
Output: [2,3,1,3,1,2]

Implement [Quicksort L-R pointers]

I hereby present another version of quicksort using left-right pointers instead of the existing one based on left-left pointers.

from display import handleDrawing

def quickSort_LR(array, low, high):
    if low < high:
        p = partition(array, low, high)
        quickSort_LR(array, low, p)
        quickSort_LR(array, p + 1, high)

def partition(array, low, high):
    pivot = array[low]
    i = low - 1
    j = high + 1
    
    while True:
        i += 1
        while array[i] < pivot: i += 1
        
        j -= 1
        while array[j] > pivot: j -= 1
        
        handleDrawing(array, j, high, low, -1)
        if i >= j: return j
        array[i], array[j] = array[j], array[i]

Although I've tested it to be working fine, do check the handleDrawing especially and any other parts of the code for error.

Implement Cocktail Sort

Steps:

  • Insert your script in algs.py
  • Add in algorithmDict: 'algorithm Name : algorithm function'
  • Insert 'handleDrawing(redBar, redBar, blueBar, blueBar)' to the deepest section of the algorithm
    (The parameters are bars indexes)

Change the color selection for drawing the bars

Currently it is possible to draw 2 red bars and 2 blue bars, which are passed as parameters to the handleDrawing function.
The idea is to pass lists, maybe intervals, as parameters such that all the elements in it will assume a especific color.

Implement Bitonic Sort

  • Implement the algorithm
  • Insert it in a file bitonicSort.py inside algorithms directory
  • In algorithms/__init__.py:
    Import yout algorithm: from algorithms.bitonicSort import bitonicSort
    Add it to __all__: "bitonicSort",

If you manage to use the handleDrawing function I would appreciate!

Suggestion:- How about showing algorithm name, time complexity wise?

- DESCRIPTION
A feature in which you can choose time complexity(Average) from drop down menu which updates the algorithm list dynamically to accommodate only those algorithm with chosen time complexity!!!

-How it could be implemented?
Store Algorithm names and time complexity in algorithmDict, make a list(timeComplexityOpt) of various time complexities and update both of them in drop down menu box. Now check in every update, if Time Complexity box got some new TC, take current TC, and send it to returnAlgoList(current) which will compare and return all algorithm having that time complexity as list.

- Are you up to do it?-

  • I have already implemented this feature and sent a Pull Request.

-Note

  1. This is my first contribution to Github Repositories.
  2. You can see images in Pull Request " Show Algorithms according to selected time complexity(New Feature)".
  3. I can take care of minor fixes in new code.
  4. Really love to hear about my work. #feedback

Delay not changing when paused

The delay doesn't seem to change properly when changed while the spring algorithm is paused, it only changes visually.

Implement Radix Sort

Steps:

  • Insert your script in algs.py
  • Add in algorithmDict: 'algorithm Name : algorithm function'
  • Insert 'handleDrawing(array, redBar, redBar, blueBar, blueBar)' to the deepest section of the algorithm
    (The parameters are the array and bars indexes)

Implement Bogo Sort

Check Repository Wiki page, or algs.py, to see algorithms already implemented!
Steps:

  • Insert your script in algs.py
  • Add in algorithmDict: 'algorithm Name : algorithm function'
  • Insert 'handleDrawing(redBar, redBar, blueBar, blueBar)' to the deepest section of the algorithm
    (The parameters are bars indexes)

More Efficient List Creation

The following code snippet is the generation of a list:

image

One way would be numbers = [randint(10, 400) for i in range(display.numBars)]. This is more efficient than the function approach.

Distinguish algorithms with variants

  • Suggestion (@lucblassel )
    In algorithms with variants, like Shell Sort, should have a way to the user select an variant to be visualized.
  • How it could be implemented:
    Add a Input Box, like a drop list, in front of algorithm selection box.
  • Are you up to do it?
    I @LucasPilla will be working on this, feel free to contribute!

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.