Skip to content

SwapnilGite/SortingAlgos

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SortingAlgos

This repository contains C implementations and analysis of two classic sorting algorithms: Selection Sort and Insertion Sort. It also includes utilities for generating random data and benchmarking the algorithms.

Contents

  • sort1.c: Implements Selection Sort and reads input data from a file.
  • sort2.c: Implements Insertion Sort and reads input data from a file.
  • file_handling.c: Generates a file (file.txt) with up to 100,000 random integers for testing.
  • Analysis.txt: Detailed time complexity analysis and practical performance comparison of both algorithms.
  • data: Empirical timing data for both sorts on various input sizes.

How to Use

  1. Generate Input Data

    • Compile and run file_handling.c to create file.txt with random numbers:
      gcc file_handling.c -o file_handling
      ./file_handling
      
  2. Run Sorting Algorithms

    • Compile and run either sort1.c (Selection Sort) or sort2.c (Insertion Sort):
      gcc sort1.c -o sort1
      ./sort1
      
      or
      gcc sort2.c -o sort2
      ./sort2
      
    • When prompted, enter the filename (e.g., file.txt) and the number of integers to sort.
  3. View Analysis

    • See Analysis.txt for theoretical and empirical analysis of both algorithms.

Algorithms

Selection Sort (sort1.c)

  • Repeatedly selects the minimum element from the unsorted part and moves it to the sorted part.
  • Time Complexity: O(n²)

Insertion Sort (sort2.c)

  • Builds the sorted array one element at a time by inserting each element into its correct position.
  • Time Complexity: O(n²) (but generally faster than Selection Sort for practical data)

Empirical Results

  • See the data file for timing results on various input sizes.
  • In practice, Insertion Sort (sort2.c) outperforms Selection Sort (sort1.c) for the tested data.
  • App Logo
  • App Logo

Notes

  • All programs expect the input file to contain one integer per line.
  • Maximum supported input size is 100,000 integers.
  • Output is printed to the console after sorting.

License

This project is for educational purposes.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages