Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

PmergeMe

A fresh implementation of the Ford-Johnson / Merge-Insertion sort for CPP Module 09.

This project is a restart of my earlier attempt. My previous version sorted data, but I misunderstood part of the algorithm, especially the role of the Jacobsthal sequence and the insertion order of pending elements. This rewrite focuses first on correctness and clarity before optimisation.

Goal

Implement a correct version of Ford-Johnson sort using:

  • recursive pairing
  • alpha / beta separation
  • main-chain construction
  • bounded insertion of betas
  • Jacobsthal-guided insertion order
  • support for both std::vector and std::deque

What I misunderstood before

My main confusion was about where the Jacobsthal sequence should be applied.

I originally mixed up these ideas:

  • the order of elements in the current sorted mainChain
  • the original pairing order of the pending betas
  • the partner relation between each beta and its alpha

Correct idea

At each recursion level:

  1. Values are grouped into pairs.
  2. In each pair:
    • alpha = larger value
    • beta = smaller value
  3. The alphas are recursively sorted to form the mainChain.
  4. The alphas key a record of its betas.
  5. The Jacobsthal sequence is used to choose the order of beta insertions from the mainChain list.
  6. Each beta is inserted by binary search only in the range before its partner alpha in the main chain.

So the Jacobsthal order is applied to the ordered mainChain

Why

Alphas move during recursion, at each level, the number of returning mainChain will be made up of the alphas that was passed earlier.

Output

The program:

  • prints the input before sorting
  • prints the sorted result
  • measures time for std::vector
  • measures time for std::deque

About

Rebuild of my CPP09 PmergeMe / Ford-Johnson sort. This version focuses on a clean and correct implementation of recursive pairing, main-chain construction, and Jacobsthal-guided beta insertion, after mistakes in my previous attempt around insertion order and comparison logic.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages