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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:55:57+00:00 2026-05-10T22:55:57+00:00

I have a list of input words separated by comma. I want to sort

  • 0

I have a list of input words separated by comma. I want to sort these words by alphabetical and length. How can I do this without using the built-in sorting functions?

  • 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. 2026-05-10T22:55:58+00:00Added an answer on May 10, 2026 at 10:55 pm

    Good question!! Sorting is probably the most important concept to learn as an up-and-coming computer scientist.

    There are actually lots of different algorithms for sorting a list.

    When you break all of those algorithms down, the most fundamental operation is the comparison of two items in the list, defining their ‘natural order’.

    For example, in order to sort a list of integers, I’d need a function that tells me, given any two integers X and Y whether X is less than, equal to, or greater than Y.

    For your strings, you’ll need the same thing: a function that tells you which of the strings has the ‘lesser’ or ‘greater’ value, or whether they’re equal.

    Traditionally, these ‘comparator’ functions look something like this:

    int CompareStrings(String a, String b) {    if (a < b)       return -1;    else if (a > b)       return 1;    else       return 0; } 

    I’ve left out some of the details (like, how do you compute whether a is less than or greater than b? clue: iterate through the characters), but that’s the basic skeleton of any comparison function. It returns a value less than zero if the first element is smaller and a value greater than zero if the first element is greater, returning zero if the elements have equal value.

    But what does that have to do with sorting?

    A sort routing will call that function for pairs of elements in your list, using the result of the function to figure out how to rearrange the items into a sorted list. The comparison function defines the ‘natural order’, and the ‘sorting algorithm’ defines the logic for calling and responding to the results of the comparison function.

    Each algorithm is like a big-picture strategy for guaranteeing that ANY input will be correctly sorted. Here are a few of the algorithms that you’ll probably want to know about:

    Bubble Sort:

    Iterate through the list, calling the comparison function for all adjacent pairs of elements. Whenever you get a result greater than zero (meaning that the first element is larger than the second one), swap the two values. Then move on to the next pair. When you get to the end of the list, if you didn’t have to swap ANY pairs, then congratulations, the list is sorted! If you DID have to perform any swaps, go back to the beginning and start over. Repeat this process until there are no more swaps.

    NOTE: this is usually not a very efficient way to sort a list, because in the worst cases, it might require you to scan the whole list as many as N times, for a list with N elements.

    Merge Sort:

    This is one of the most popular divide-and-conquer algorithms for sorting a list. The basic idea is that, if you have two already-sorted lists, it’s easy to merge them. Just start from the beginning of each list and remove the first element of whichever list has the smallest starting value. Repeat this process until you’ve consumed all the items from both lists, and then you’re done!

    1     4        8     10        2     5  7     9 ------------ becomes ------------>  1  2  4  5  7  8  9  10 

    But what if you don’t have two sorted lists? What if you have just one list, and its elements are in random order?

    That’s the clever thing about merge sort. You can break any single list into smaller pieces, each of which is either an unsorted list, a sorted list, or a single element (which, if you thing about it, is actually a sorted list, with length = 1).

    So the first step in a merge sort algorithm is to divide your overall list into smaller and smaller sub lists, At the tiniest levels (where each list only has one or two elements), they’re very easy to sort. And once sorted, it’s easy to merge any two adjacent sorted lists into a larger sorted list containing all the elements of the two sub lists.

    NOTE: This algorithm is much better than the bubble sort method, described above, in terms of its worst-case-scenario efficiency. I won’t go into a detailed explanation (which involves some fairly trivial math, but would take some time to explain), but the quick reason for the increased efficiency is that this algorithm breaks its problem into ideal-sized chunks and then merges the results of those chunks. The bubble sort algorithm tackles the whole thing at once, so it doesn’t get the benefit of ‘divide-and-conquer’.


    Those are just two algorithms for sorting a list, but there are a lot of other interesting techniques, each with its own advantages and disadvantages: Quick Sort, Radix Sort, Selection Sort, Heap Sort, Shell Sort, and Bucket Sort.

    The internet is overflowing with interesting information about sorting. Here’s a good place to start:

    http://en.wikipedia.org/wiki/Sorting_algorithms

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

Sidebar

Ask A Question

Stats

  • Questions 69k
  • Answers 69k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer <s:textfield> only creates a text field (input tag) and doesn't… May 11, 2026 at 12:42 pm
  • added an answer You should know when each customer arrived in the queue.… May 11, 2026 at 12:42 pm
  • added an answer You don't want to use the ping command, but you… May 11, 2026 at 12:42 pm

Related Questions

I have an algorithm that generates strings based on a list of input words.
I have a list of integers, List<Integer> and I'd like to convert all the
I have a List of Foo. Foo has a string property named Bar. I'd
I have a list of 2-item tuples and I'd like to convert them to
Let me preface this by saying I'm a complete amateur when it comes to
In a pretty typical scenario, I have a 'Search' text box on my web
I wrote a quick and dirty wrapper around svn.exe to retrieve some content and

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.