Skip to content

Review/my mergesort bunsarak#2

Open
Bunsarak27 wants to merge 8 commits into
Goobahfish:mainfrom
Izak8:review/my_mergesort-bunsarak
Open

Review/my mergesort bunsarak#2
Bunsarak27 wants to merge 8 commits into
Goobahfish:mainfrom
Izak8:review/my_mergesort-bunsarak

Conversation

@Bunsarak27

Copy link
Copy Markdown

This PR does not change threading yet; it just ensures the sequential path is correct, and ready to be called when we stop spawning threads at the cutoff. What I changed

Added a recursive my_mergesort(int left, int right):
Base case: if (left >= right) return; (0 or 1 elementalready sorted).
Compute mid = left + (right - left)/2 (overflow).
Recurse on [left..mid] and [mid+1..right].
Call merge(left, mid, mid+1, right) to combine the two sorted halves.

This will ct as the fallback when the cutoff level is reached in the parallel version, and provide a baseline to compare speedups when we add threads later on. Issues I hit (and how I resolved them) i use a mac so, MacOS <error.h>: some forks include #include <error.h> (GNU extension). On macOS this header doesn’t exist; removing that include lets clang compile. i accidentally write if (left <= right) return;. Fixed to left >= right so we stop when the range has ≤1 element.

References: https://www.youtube.com/watch?v=b1n9T-Iy3SA
Operating Systems: Three Easy Pieces (Arpaci-Dusseau & Arpaci-Dusseau):
Standard mergesort recurrence and merge-procedure patterns (CLRS-style).

Izak8 and others added 8 commits October 24, 2025 14:16
Includes a partially-authored README file. However, there are still some changes to make, as there are sections which
we cannot fill out yet. This commit was accidentally authored under my university GitHub identity, woops.

---------

Co-authored-by: Izak Baldacchino <a1830164@student.adelaide.edu.au>
Follows the basic mergesort algorithm provided by the video shown
on the assignment description. Other sources accessed include:
cppreference.com (for memcpy).
Includes a Makefile based on a template I created for an old project
(which can be found here: github.com/Izak8/gl).

Build flags differ from original assignment; changed C standard from gnu89
to c11. gnu89 seems unecessarily limiting.
Just simply uses scopes to create predictable conditions.
If the test executable isn't aborted by a failed assertion, then it is
considered to pass.
…hat still has elements.Finish with a single memcpy from B[left..right] back to A

had to remove  <error.h> include so tests build locally
…hat still has elements.Finish with a single memcpy from B[left..right] back to A

had to remove  <error.h> include so tests build locally
…el_mergesort, No threading changes yet; parallel_mergesort() remains a stub,fix(sort): correct my_mergesort base case (use left >= right)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants