Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6148089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:13:08+00:00 2026-05-23T19:13:08+00:00

I have a linked list implementation and I’m experimenting with both MergeSort and QuickSort

  • 0

I have a linked list implementation and I’m experimenting with both MergeSort and QuickSort algorithms.

What I don’t understand is why the sort operation in std::list is so fast.
Looking at the std::list under Linux and it appears to be linked list as well, not an array based list.

The merge sort I tried almost identical to Dave Gamble’s version here:
Merge Sort a Linked List

Also, I thought I’d try a simple quicksort based on this code:
http://www.flipcode.com/archives/Quick_Sort_On_Linked_List.shtml

Surprisingly, to sort 10 million random numbers using std::list and sort was around 10 times quicker than either of those others.

And for those that are asking, yes I need to use my own list class for this project.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T19:13:09+00:00Added an answer on May 23, 2026 at 7:13 pm

    I’ve been taking a look at the interesting libstdc++ (GCC) implementation for list::sort (source code) and it doesn’t seem to implement a traditional merge sort algorithm (at least not one I’ve ever seen before).

    Basically what it does is:

    1. Creates a series of buckets (64 total).
    2. Removes the first element of the list to sort and merges it with the first (i=0th) bucket.
    3. If, before the merge, the ith bucket is not empty, merge the ith bucket with the i+1th bucket.
    4. Repeat step 3 until we merge with an empty bucket.
    5. Repeat step 2 and 3 until the list to sort is empty.
    6. Merge all the remaining non-empty buckets together starting from smallest to largest.

    Small note: merging a bucket X with a bucket Y will remove all the elements from bucket X and add them to bucket Y while keeping everything sorted. Also note that the number of elements within a bucket is either 0 or 2^i.

    Now why is this faster then a traditionnal merge sort? Well I can’t say for sure but here are a few things that comes to mind:

    • It never traverses the list to find a mid-point which also makes the algorithm more cache friendly.
    • Because the earlier buckets are small and used more frequently, the calls to merge trash the cache less frequently.
    • The compiler is able to optimize this implementation better. Would need to compare the generated assembly to be sure about this.

    I’m pretty sure the folks who implemented this algorithm tested it thoroughly so if you want a definitive answer you’ll probably have to ask on the GCC mailing list.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a linked list that I want to sort part of, eg: std::sort(someIterator,
I have written my own linked list implementation in C, and it works fine
I have a generic linked list implementation with a node struct containing a void*
I have the following very simplistic implementation for a single linked list in C:
I have a pretty standard implementation of a circular, two-way linked list. For arrays
This is my implementation of insertion sort in java for doubly linked list. I
I have a linked list, which stores groups of settings for my application: typedef
Say you have a linked list structure in Java. It's made up of Nodes:
I have implemented a linked list as a self-referencing database table: CREATE TABLE LinkedList(
I have the following function defined inside my linked list class. The declaration in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.