answersLogoWhite

0


Best Answer

Bubble sort will be able to sort the items lexicographically, if you first assign the strings a relative value. The way strcmp in the C library does this is by returning the difference of the first different characters between the strings. For instance, if you call strcmp("Hello", "Highway"), strcmp will return 'e'-'i'. The ascii value of e on a unix system is 101 and the ascii value of i is 105, so it is returning the value 101-105 = -4 which will tell you that "Hello" is lexicographically smaller than "Highway". Doing this, you should be able to use any algorithm you want to sort the strings.

User Avatar

Wiki User

13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Is it possible to use the bubble sort algorithm to sort strings?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Can you modify the bubble sort algorithm to search to sort an array of characters instead of array of integers?

The bubble sort algorithm can be applied to an array of characters. Every character can be translated to an integer equivalent via the ascii table


Bubble sort Extra or in space?

Bubble sort is an "in place" algorithm. Other than a temporary "switch" variable, no extra space is required.


What are the advantages for bubble sort?

Bubble sort has no practical applications other than that it is often cited as an example of how not to write an algorithm. Insert sort is the best algorithm for sorting small lists of items and is often used in conjunction with quick sort to sort larger lists. Like insert sort, bubble sort is simple to implement and is a stable sort (equal items remain in the same order they were input). However, insert sort uses copy or move operations rather than swaps (which is actually three operations per swap) and is therefore quicker. The only time a bubble sort will work quicker than insert sort is when the array is already sorted, which renders the entire algorithm redundant. A modified algorithm that specifically tests if an array is sorted or not would be more efficient than a single-pass bubble sort.


Is it trueThe biggest advantage of the bubble sort algorithm is that values move only by one element at a time toward their final destination in the array?

This is false. The movement described is a disadvantageof bubble sort.


In the bubble sort algorithm the second loop iterates ---------- for each of the unsorted array elements?

n-1 times


Why is the Bubble Sort algorithm also referred ro as Sink Sort?

Bubble sort got its name because if you could watch the way your data was changing, on each iteration you would see the greatest number "bubble" to the top.Similarly, you could said that you would see the lowest number "sink" to the bottom.


How do you sort an array of numbers?

Use a sorting algorithm. There are a bewildering number of sorting algorithms, both stable and unstable. To sort numbers, an unstable sort suffices. The algorithm you use will depend on how many numbers need to be sorted (a small or a large set), however a hybrid algorithm (a combination of two or more algorithms) can cater for both. Introsort (unstable) and timsort (stable) are the two most common hybrid sorting algorithms.


How do you write a c plus plus program to sort a vector of strings using MSD radix sort?

The standard library sort algorithm automatically uses MSD radix to sort strings: std::vector<std::string> vs = {"a", "b", "c" "d", "ab"}; std::sort(vs.begin(), vs.end()); After sorting, the order will be: {"a", "ab", "b", "c", "d"}


Did exchange method is possible in sorting algorithms in data structures?

yes....exchange checking are: bubble sort, selection sort , quick sort


What is a bubble sort used for?

Bubble sort, incorrectly referred to as sinking sort is a simple sorting algorithm (step by step procedure of calculations) that works to repeatedly step through list to be sorted. With the comparing of each adjacent items and swapping them into the correct order. This repeated until there are no swaps needed and the list of items are sorted.


What is another name for bubble sort?

Bubble sort is also known as sinking sort.


What is the minimum number of comparisons in bubble sort?

A bubble sort may have a range from O(n-1) for a pre-sorted array, to O(n2-n) for a poorly implemented bubble sort algorithm. Given 20 elements, a best case scenario is 19 comparisons, and the worst case is 380 comparisons.