{"id":20306950,"url":"https://github.com/ctoic/algorithm-visualizer-using-pygame","last_synced_at":"2025-04-11T15:06:22.275Z","repository":{"id":129336855,"uuid":"550802456","full_name":"Ctoic/Algorithm-Visualizer-Using-pygame","owner":"Ctoic","description":"This repository contains code for sorting algorithms and their visualization using pygame  library of python.","archived":false,"fork":false,"pushed_at":"2023-10-22T06:21:20.000Z","size":41,"stargazers_count":7,"open_issues_count":0,"forks_count":4,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-25T11:11:30.619Z","etag":null,"topics":["collaborate","communityexchange","github","github-codespaces","learn","python","sorting-algorithms","student-vscode"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Ctoic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2022-10-13T10:56:12.000Z","updated_at":"2025-03-11T11:50:02.000Z","dependencies_parsed_at":"2023-04-08T00:36:58.459Z","dependency_job_id":null,"html_url":"https://github.com/Ctoic/Algorithm-Visualizer-Using-pygame","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ctoic%2FAlgorithm-Visualizer-Using-pygame","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ctoic%2FAlgorithm-Visualizer-Using-pygame/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ctoic%2FAlgorithm-Visualizer-Using-pygame/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ctoic%2FAlgorithm-Visualizer-Using-pygame/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Ctoic","download_url":"https://codeload.github.com/Ctoic/Algorithm-Visualizer-Using-pygame/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248429078,"owners_count":21101782,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["collaborate","communityexchange","github","github-codespaces","learn","python","sorting-algorithms","student-vscode"],"created_at":"2024-11-14T17:15:38.469Z","updated_at":"2025-04-11T15:06:22.249Z","avatar_url":"https://github.com/Ctoic.png","language":"Python","readme":"# Algorithm-Visualizer-Using-pygame\n## Group Members and Task\n### 1. Najam Ali Abbas\n  1. Insertion sort\n  2. Bubble sort\n  3. Merge Sort\n  4. Quick Sort\n  5. Count Sort\n  ### 2. Jawad ur Rehman\n  1. Selection Sort\n  2. Heap Sort\n  3. Radix Sort\n  4. Bucket Sort\n# Pygame\nPygame is a set of Python modules designed for writing video games. Pygame adds functionality on top of the excellent SDL library. This allows you to create fully featured games and multimedia programs in the python language.\nPygame is highly portable and runs on nearly every platform and operating system.\nPygame itself has been downloaded millions of times.\nPygame is free. Released under the LGPL licence, you can create open source, freeware, shareware, and commercial games with it. See the licence for full details.\nFor a nice introduction to pygame, examine the line-by-line chimp tutorial, and the introduction for python programmers. buffer, and many other different backends... including an ASCII art backend! OpenGL is often broken on linux systems, and also on windows systems - which is why professional games use multiple backends.\nMulti core CPUs can be used easily. With dual core CPUs common, and 8 core CPUs cheaply available on desktop systems, making use of multi core CPUs allows you to do more in your game. Selected pygame functions release the dreaded python GIL, which is something you can do from C code.\n# About Project \nIn this project we have used python language because of it's extensive librarires and easy syntax. By using the pygame library we will visualize all the sorting algorithm. By looking at the graph how data is sorted we will analyze which sorting technique perform best under a specificc situatiion. Before writing the prgoram we will setup the Envirement for pygame and we will Install the pakages. The Gui will be provided by pygame. After installation we are good to run the python program to visualize sorting algorithms on the screen. \n1. Install Pygame\n2. Include library in the program\n3. Code for all the sorting Algorithm \n4. Run the above python file in any of your faviroite IDE and see the magic ;)\n5. You will see visualization of all sorting Algorithms\n### About the GUI and How it works\nWhen you will run the above code. A screen will pop up.\nThis screen contain name of all nine Algorithms , Set and resset button and also it provides you option to select Ascecending or Desecending.\nFor example if you want to Select Bubble Sort You havve to Press (B) and For Ascending (A) and then press SPACE.\nNow visualization will be start for the Random Data.\nIn these video clips you can see the GUI\n## Tools used \n\n1. Python \n2. Visual Studio\n3. pygame\n4. Github\n5. Canva \n6. Youtube\n\n# Visualization of Algorithms\nhttps://youtu.be/OTWB07hUS1U\n## Bubble sort \nBubble Sort is the simplest sorting algorithm that works by repeatedly swapping the adjacent elements if they are in the wrong order. This algorithm is not suitable for large data sets as its average and worst-case time complexity is quite high.\n\n\n\nhttps://user-images.githubusercontent.com/90936436/196022219-438cfbe2-14e9-4de6-adeb-1c4905cb6dda.mp4\n\n\n\n\n\n\n\n\n\n## selection sort\nThe selection sort algorithm sorts an array by repeatedly finding the minimum element (considering ascending order) from the unsorted part and putting it at the beginning. \nThe algorithm maintains two subarrays in a given array.\n\nThe subarray which already sorted. \nThe remaining subarray was unsorted.\nIn every iteration of the selection sort, the minimum element (considering ascending order) from the unsorted subarray is picked and moved to the sorted subarray. \n\nhttps://user-images.githubusercontent.com/90936436/195989847-161fb992-9a37-422f-bb99-b977b2437b42.mp4\n\n\n\n## Insertion sort \nInsertion sort is a simple sorting algorithm that works similar to the way you sort playing cards in your hands. The array is virtually split into a sorted and an unsorted part. Values from the unsorted part are picked and placed at the correct position in the sorted part.\n\nCharacteristics of Insertion Sort:\nThis algorithm is one of the simplest algorithm with simple implementation\nBasically, Insertion sort is efficient for small data values\nInsertion sort is adaptive in nature, i.e. it is appropriate for data sets which are already partially sorted.\n\n\nhttps://user-images.githubusercontent.com/90936436/196022262-14497326-7817-4ddf-adbf-1050fac9474e.mp4\n\n\n\n\n\n\n\n## Merge Sort\nThe Merge Sort algorithm is a sorting algorithm that is based on the Divide and Conquer paradigm. In this algorithm, the array is initially divided into two equal halves and then they are combined in a sorted manner.\nMerge Sort Working Process:\nThink of it as a recursive algorithm continuously splits the array in half until it cannot be further divided. This means that if the array becomes empty or has only one element left, the dividing will stop, i.e. it is the base case to stop the recursion. If the array has multiple elements, split the array into halves and recursively invoke the merge sort on each of the halves. Finally, when both halves are sorted, the merge operation is applied. Merge operation is the process of taking two smaller sorted arrays and combining them to eventually make a larger one.\n\n\n\n\nhttps://user-images.githubusercontent.com/90936436/196022278-5766f596-e63d-49b1-9afb-877d3adab88b.mp4\n\n\n\n\n\n## Quicksort\nQuickSort is a Divide and Conquer algorithm. It picks an element as a pivot and partitions the given array around the picked pivot. There are many different versions of quickSort that pick pivot in different ways. \nAlways pick the first element as a pivot.\nAlways pick the last element as a pivot (implemented below)\nPick a random element as a pivot.\nPick median as the pivot.\nThe key process in quickSort is a partition(). The target of partitions is, given an array and an element x of an array as the pivot, put x at its correct position in a sorted array and put all smaller elements (smaller than x) before x, and put all greater elements (greater than x) after x. All this should be done in linear time.\n\n\nhttps://user-images.githubusercontent.com/90936436/196022287-1cc0d03c-1e99-415a-b7ed-9b9e93201825.mp4\n\n\n\n\n\n\n\n## Heap Sort\nHeap sort is a comparison-based sorting technique based on Binary Heap data structure. It is similar to the selection sort where we first find the minimum element and place the minimum element at the beginning. Repeat the same process for the remaining elements.\nHeap sort is an in-place algorithm. \nIts typical implementation is not stable, but can be made stable (See this)\nTypically 2-3 times slower than well-implemented QuickSort.  The reason for slowness is a lack of locality of reference.\n\n\n\n\n\n\nhttps://user-images.githubusercontent.com/90936436/196022297-e179c7e1-1890-4433-b332-263167f32ec9.mp4\n\n\n\n\n## Radix Sort\nThe lower bound for the Comparison based sorting algorithm (Merge Sort, Heap Sort, Quick-Sort .. etc) is Ω(nLogn), i.e., they cannot do better than nLogn. Counting sort is a linear time sorting algorithm that sort in O(n+k) time when elements are in the range from 1 to k.\n\nWhat if the elements are in the range from 1 to n2? \nWe can’t use counting sort because counting sort will take O(n2) which is worse than comparison-based sorting algorithms. Can we sort such an array in linear time? \nRadix Sort is the answer. The idea of Radix Sort is to do digit by digit sort starting from least significant digit to most significant digit. Radix sort uses counting sort as a subroutine to sort.\n\n\n\nhttps://user-images.githubusercontent.com/90936436/196022304-ec8b5f0a-3737-44ea-a277-2004863a602f.mp4\n\n\n\n\n\n\n\n## Bucket Sort \nBucket sort is mainly useful when input is uniformly distributed over a range. For example, consider the following problem. \nSort a large set of floating point numbers which are in range from 0.0 to 1.0 and are uniformly distributed across the range. How do we sort the numbers efficiently?\nA simple way is to apply a comparison based sorting algorithm. The lower bound for Comparison based sorting algorithm (Merge Sort, Heap Sort, Quick-Sort .. etc) is Ω(n Log n), i.e., they cannot do better than nLogn. \nCan we sort the array in linear time? Counting sort can not be applied here as we use keys as index in counting sort. Here keys are floating point numbers.  \nThe idea is to use bucket sort. Following is bucket algorithm.\n\n## Counting sort\nCounting sort is a sorting technique based on keys between a specific range. It works by counting the number of objects having distinct key values (kind of hashing). Then do some arithmetic to calculate the position of each object in the output sequence. \nCharacteristics of counting sort:\nCounting sort makes assumptions about the data, for example, it assumes that values are going to be in the range of 0 to 10 or 10 – 99 etc, Some other assumptions counting sort makes are input data will be all real numbers.\nLike other algorithms this sorting algorithm is not a comparison-based algorithm, it hashes the value in a temporary count array and uses them for sorting.\nIt uses a temporary array making it a non In Place algorithm.\n\nhttps://user-images.githubusercontent.com/90936436/196022310-b4de35c3-858d-4d7a-a04f-0cf75c42700c.mp4\n\n\n# Links and Refrences \nhttps://www.geeksforgeeks.org/\n\nhttps://www.youtube.com/watch?v=twRidO-_vqQ\n\nhttps://stackoverflow.com/\n\nhttps://docs.python.org/3/\n\nhttps://www.pygame.org/docs/\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fctoic%2Falgorithm-visualizer-using-pygame","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fctoic%2Falgorithm-visualizer-using-pygame","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fctoic%2Falgorithm-visualizer-using-pygame/lists"}