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

  • Home
  • SEARCH
  • 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 9069849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:32:09+00:00 2026-06-16T17:32:09+00:00

I have been looking at the Scala documentation but so far I have found

  • 0

I have been looking at the Scala documentation but so far I have found no answer to my question, namely what sorting algorithm is used by the method

scala.collection.immutable.Vector.sorted

The documenation says it is a stable sort, but not the actual algorithm used. Is it a merge sort?

  • 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-06-16T17:32:10+00:00Added an answer on June 16, 2026 at 5:32 pm

    The sorted method is implemented in SeqLike, and seems to use java.util.Arrays.sort for its sorting. It builds an array from the vector, then invokes Arrays.sort and then converts it back, it seems. According to the Java 6 documentation, it therefore uses quicksort:

    The sorting algorithm is a tuned quicksort, adapted from Jon L. Bentley and M. Douglas McIlroy’s “Engineering a Sort Function”, Software-Practice and Experience, Vol. 23(11) P. 1249-1265 (November 1993). This algorithm offers n*log(n) performance on many data sets that cause other quicksorts to degrade to quadratic performance.

    For Java 7, the algorithm seems to have change (again, citing the docs):

    The sorting algorithm is a Dual-Pivot Quicksort by Vladimir Yaroslavskiy, Jon Bentley, and Joshua Bloch. This algorithm offers O(n log(n)) performance on many data sets that cause other quicksorts to degrade to quadratic performance, and is typically faster than traditional (one-pivot) Quicksort implementations.

    Scala’s SeqLike#sorted source (taken from GitHub):

    /** Sorts this $coll according to an Ordering.
       *
       *  The sort is stable. That is, elements that are equal (as determined by
       *  `lt`) appear in the same order in the sorted sequence as in the original.
       *
       *  @see [[scala.math.Ordering]]
       *
       *  @param  ord the ordering to be used to compare elements.
       *  @return     a $coll consisting of the elements of this $coll
       *              sorted according to the ordering `ord`.
       */
      def sorted[B >: A](implicit ord: Ordering[B]): Repr = {
        val len = this.length
        val arr = new ArraySeq[A](len)
        var i = 0
        for (x <- this.seq) {
          arr(i) = x
          i += 1
        }
        java.util.Arrays.sort(arr.array, ord.asInstanceOf[Ordering[Object]])
        val b = newBuilder
        b.sizeHint(len)
        for (x <- arr) b += x
        b.result
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been looking for an answer to this on Stack Overflow, but I
I have been looking into scala and AKKA for managing an obviously parallelisable algorithm.
Have been looking on some tutorials for drawing canvas using SurfaceView, but the only
I have been looking online to find documentation for the function in QTP and
I have been looking everywhere but could not find a tutorial for this. I
I'm sure this is covered in the documentation somewhere but I have been unable
I have been looking at the Scala web framework Lift. I recently saw something
I have been looking for an advanced levenshtein distance algorithm, and the best I
I have been looking around, but most of them point to a java TreeMap.
I have been looking around for a visualization framework that would aid graph visualization

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.