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 7934317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:36:43+00:00 2026-06-03T21:36:43+00:00

How does selection sort work with strings? I’ve done some searching and can’t seem

  • 0

How does selection sort work with strings? I’ve done some searching and can’t seem to find a definitive answer. If I had 4 names [Rob, Adam, Tom, Thomas] – how would a selection sort, sort these? Would it just simply sort by the first letter? If so, would it sort like the following: [Adam, Rob, Thomas, Tom].

Thanks.

  • 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-03T21:36:44+00:00Added an answer on June 3, 2026 at 9:36 pm

    All sorting algorithms use some kind of comparison function to determine the order of elements. It’s generally independent of particular sorting algorithm you select.

    Most languages try to guess the comparison function, depending of the type of sorted data. For example comparison on numbers simply checks which number is greater. Comparison function on strings uses dictionary order which compares consecutive letters. Some examples (GT – greater than, LT – less than):

    • Compare numbers:

      > compare 1 2
      LT
      
    • letters:

      > compare 'R' 'A'
      GT
      
    • strings (it compares letters internally, think how):

      > compare "Rob" "Adam"
      GT
      

    Sorting function uses this comparisons internally ([1,2,3] is a list of three numbers). You don’t know which sorting algorithm is used internally, but as long as the same comparison function is used, results shouldn’t vary:

    > sort [3,1,2]
    [1,2,3]
    
    > sort ['t', 'h', 'o', 'm', 'a', 's']
    ['a', 'h', 'm', 'o', 's', 't']
    
    > sort ["Rob", "Adam", "Tom", "Thomas"]
    ["Adam","Rob","Thomas","Tom"]
    

    You can even define your own comparison function, to sort by some more sophisticated criteria:

    • Sort list of numbers by count of prime divisors.

      First custom comparison function:

      > numOfPrimeDivs 30
      3
      
      > numOfPrimeDivs 6
      2
      
      > let compareNumOfPrimeDivs n1 n2 = compare (numOfPrimeDivs n1) (numOfPrimeDivs n2)) 
      
      > compareNumOfPrimeDivs 30 6
      GT
      
      > sortBy compareNumOfPrimeDivs [2,210,30,2310,6]
      [2,6,30,210,2310]
      
    • Sort by length of strings

      Comparison function:

       > length "Rob"
       3
      
       > length "Adam"
       4
      
       > let compareLength s1 s2 = compare (length s1) (length s2)
      
       > compareLength "Rob" "Adam"
       LT
      
       > sortBy compareLength ["Rob", "Adam", "Tom", "Thomas"]
       ["Rob","Tom","Adam","Thomas"]    
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given this HTML: <div class=OpenIDSelector>some text</div> Why does this JQuery selector match it on
Does anyone have any idea what this jQuery selector will do? object.find('td:eq(1) div div');
There are some section in the table that does not contain any data and
I've been doing some research and testing on how to do fast random selection
One can use a CRITICAL_SECTION variable to get mutual exclusion. My question is: does
Is there a sorting algorithm that is named binary sort? Like merge sort, selection
Problem: How can I tell if a selection of text in the CRichEditCtrl has
In a genetic algorithm, when selecting members for crossover using roulette-wheel selection method, does
Yesterday at work I set out to figure out how to sort numbers without
What is the difference between straight selection sort vs. exchange selection sort ? I

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.