Skip to content

A clean C++98 implementation of the Ford-Johnson algorithm (also known as Merge-Insertion Sort). This educational project focuses on the algorithm's core principle: minimizing comparisons. It features instrumentation to count exact comparisons and benchmark performance across different containers.

Notifications You must be signed in to change notification settings

mtelek/Ford-Johnson-Algorithm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

9 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Ford-Johnson Algorithm (Merge-Insertion Sort)

A C++ implementation of the Ford-Johnson algorithm, also known as Merge-Insertion Sort.

πŸ“‹ About

The algorithm is a hybrid sorting algorithm, famous for using a clever insertion sequence to minimize the number of comparisons.
It's particularly interesting because it was one of the first algorithms proven to achieve the optimal number of comparisons for sorting.

For a detailed explanation and a step-by-step visualization of the Ford-Johnson sorting algorithm, see this article:
https://dev.to/emuminov/human-explanation-and-step-by-step-visualisation-of-the-ford-johnson-algorithm-5g91

πŸš€ Features

  • Implemented in C++98 standard
  • Handles integer sorting
  • Tracks the exact number of comparisons performed
  • Measures and compares sorting performance across containers
  • Educational implementation with clear code structure
  • Makefile for easy compilation

πŸ› οΈ Building

To compile the project:

make

This will create an executable called algorithm.

πŸ’» Usage

The current build configuration limits the sorting algorithm to around 3000 integers.
To increase this capacity, modify the LIMIT macro definition within the Makefile to the required size.

Run the program with a list of integers to sort:

./algorithm [numbers...]

Example

./algorithm 10 5 7 3 8 2 9 1 4 6

πŸ“š Algorithm Details

  • Time Complexity: O(n*log(n)) comparisons
  • Space Complexity: O(nΒ²)
  • Method: Specialized recursive algorithm using Jacobsthal number sequencing with binary search insertion

πŸ”§ Requirements

C++98 compatible compiler (g++, c++)
Make

About

A clean C++98 implementation of the Ford-Johnson algorithm (also known as Merge-Insertion Sort). This educational project focuses on the algorithm's core principle: minimizing comparisons. It features instrumentation to count exact comparisons and benchmark performance across different containers.

Topics

Resources

Stars

Watchers

Forks