Skip to content

Visualized sorting algorithms with performance testing and detailed implementation explanations

License

Notifications You must be signed in to change notification settings

ovenzeze/usualSortAlgorithm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

23 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Usual Sort Algorithm

GitHub stars License: MIT Language: JavaScript

Frontend implementation of common sorting algorithms, including examples, performance metrics, implementation ideas, and algorithm visualization

🌐 Online Demo | πŸ“– Algorithm Details


✨ Features

  • 🎯 10+ Sorting Algorithms: Covers classic algorithms including bubble sort, quick sort, selection sort, insertion sort, shell sort, merge sort, heap sort, counting sort, bucket sort, and radix sort
  • πŸ“Š Performance Testing: Real-time display of algorithm execution time, supports different data scales (20, 5000, 10000, 50000)
  • 🎨 Algorithm Visualization: Each algorithm comes with GIF animation demonstrations for intuitive understanding of the execution process
  • πŸ’‘ Implementation Ideas: Detailed explanation of the core concepts and implementation steps for each algorithm
  • πŸ” Array Deduplication: Provides 3 different array deduplication implementation methods
  • πŸš€ Zero Dependencies: Pure vanilla JavaScript implementation, no frameworks or libraries required

πŸš€ Quick Start

Method 1: Direct Online Demo

Visit the online demo to experience it directly.

Method 2: Local Development

  1. Clone the repository

    git clone https://github.com/clayz/usualSortAlgorithm.git
    cd usualSortAlgorithm
  2. Start a local server (Python recommended)

    # Python 3
    python -m http.server 8000
    
    # Or use Python 2
    python -m SimpleHTTPServer 8000
  3. Open in browser Visit http://localhost:8000/index.html


πŸ“– Supported Sorting Algorithms

Basic Sorting Algorithms

Algorithm Time Complexity Space Complexity Stability Description
Bubble Sort O(nΒ²) O(1) βœ… Stable Compare and swap adjacent elements
Bubble Sort (Optimized) O(nΒ²) O(1) βœ… Stable Uses flag to mark early termination
Selection Sort O(n²) O(1) ❌ Unstable Selects minimum element each time
Insertion Sort O(nΒ²) O(1) βœ… Stable Suitable for small-scale or nearly sorted data

Efficient Sorting Algorithms

Algorithm Time Complexity Space Complexity Stability Description
Quick Sort O(n log n) O(log n) ❌ Unstable Divide and conquer, most widely used in practice
Merge Sort O(n log n) O(n) βœ… Stable Divide and conquer, preferred for stable sorting
Heap Sort O(n log n) O(1) ❌ Unstable Utilizes heap data structure
Shell Sort O(n^1.3) O(1) ❌ Unstable Improved version of insertion sort

Special Sorting Algorithms

Algorithm Time Complexity Space Complexity Stability Description
Counting Sort O(n + k) O(k) βœ… Stable Suitable for integers with small range
Bucket Sort O(n + k) O(n + k) βœ… Stable Efficient when data is uniformly distributed
Radix Sort O(d(n + k)) O(n + k) βœ… Stable Sorts by digits, suitable for integers

Array Deduplication Methods

  • Temporary Array Method: Uses indexOf to check if element already exists
  • HashMap Method: Leverages object property uniqueness
  • IndexOf Method: Determines first occurrence through position index

πŸ› οΈ Tech Stack

  • Frontend Framework: Vanilla JavaScript (ES5+)
  • UI Framework: Material Design Lite
  • Styling: CSS3
  • Visualization: GIF animations (Source: Visualgo.net)

πŸ“Έ Screenshots

Main Interface

The project provides an intuitive interactive interface that supports:

  • Generate random arrays of different scales
  • Select different sorting algorithms
  • View sorting results and execution time in real-time
  • View algorithm visualization animations
  • Learn algorithm implementation ideas

Algorithm Visualization Examples

Bubble Sort

Bubble Sort

Quick Sort

Quick Sort

Merge Sort

Merge Sort

Visit the online demo for more visualization animations


πŸ“š Learning Value

Why Learn Sorting Algorithms?

  1. Algorithm Fundamentals: Sorting is one of the most fundamental problems in computer science
  2. Interview Essential: Common topic in technical interviews at major companies
  3. Performance Optimization: Understand the appropriate scenarios for different algorithms to optimize real-world projects
  4. Thinking Training: Develop algorithmic thinking and problem-solving skills

Project Highlights

  • βœ… Visual Learning: Intuitively understand algorithm execution through GIF animations
  • βœ… Performance Comparison: Real-time testing of different algorithms' performance at various data scales
  • βœ… Code Implementation: Complete JavaScript implementation for each algorithm
  • βœ… Idea Explanation: Detailed explanation of core concepts and steps for each algorithm

πŸ“Š Performance Testing

The project supports performance testing on arrays of different scales:

  • Small Scale (20 elements): Suitable for observing algorithm execution process
  • Medium Scale (5000 elements): Test basic algorithm performance
  • Large Scale (10000, 50000 elements): Compare algorithm performance on large datasets

⚠️ Note: Large-scale data testing may take a long time, please be patient.


πŸ“ Project Structure

usualSortAlgorithm/
β”œβ”€β”€ index.html          # Main page
β”œβ”€β”€ css/
β”‚   └── algorithm.css   # Stylesheet
β”œβ”€β”€ js/
β”‚   β”œβ”€β”€ algorithm.js    # Sorting algorithm implementations
β”‚   └── algorithm-idea.js # Algorithm idea explanations
β”œβ”€β”€ img/                # Algorithm visualization GIF images
β”œβ”€β”€ stylesheets/        # Third-party stylesheets
└── README.md          # Project documentation

🀝 Contributing

Issues and Pull Requests are welcome!

If you have new sorting algorithm implementations, performance optimization suggestions, or bug fixes, contributions are welcome.


πŸ“„ License

This project is licensed under the MIT License.


πŸ‘€ Author

Clay


πŸ™ Acknowledgments


⭐ Star History

If this project is helpful to you, please give it a ⭐ Star!

Star History Chart

About

Visualized sorting algorithms with performance testing and detailed implementation explanations

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published