answersLogoWhite

0


Best Answer

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

User Avatar

Wiki User

13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Can you modify the bubble sort algorithm to search to sort an array of characters instead of array of integers?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

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

n-1 times


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.


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.


Is it possible to use the bubble sort algorithm to sort strings?

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.


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.

Related questions

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 different types of algorithm?

insertion,bubble,quick, quick3, merge, shell,heap, selection sorting


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

n-1 times


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.


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.


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.


Is it possible to use the bubble sort algorithm to sort strings?

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.


What are the characters in adventure time?

fin,jake,princes bubble gum,ice king, and marsolene.


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.


What kind of a garment is a bubble dress?

A bubble dress is a dress with a bubble hem. This means that the bottom of the dress bubbles out and flows instead of laying flat like most dresses with normal hems do. The bubble hem is actually an elastic band that gathers the excess fabric at the bottom of the dress


Algorithm of a programme of bubble sort?

The algorithm for bubble sort, also know as pair exchange...Set a swap flag falseLoop for the first N-1 elementsCompare each element with the following elementIf the two elements are in the correct order, continue to next loop iterationOtherwise, swap the two elements and set the swap flag trueAt loop end, if the swap flag is true, repeat starting at step 1Otherwise, sort completedBubble sort is so named because out of order elements "bubble" to the end of the array, moving one step per inner loop iteration.As stated above, the algorithm is slow because it takes a while for a significantly out of order element to reach its final point when it needs to come closer to the beginning of the array. It can be improved by introducing a "distance" parameter, initially set to one half of the array size, and using that distance in step 3 to choose the second element. After the algorithm is completed for that distance, the distance is halved, and we iterate the entire algorithm until the distance is only one. (This variation is more formally known as merge exchange, but it still retains the "bubble" characteristic.)


Lyrics for bazooka zooka bubble gum?

They say:Mi mama me dio a mi un pesopara comprar un dulcepero yo no quiero dulceyo quiero bubble gumBazooka Bubble GumBazooka Bubble GumMi mama, me dio una pesetapara comprar una paletapero yo no quiero paletayo quiero bubble gumBazooka Bubble GumBazooka Bubble GumMi mama, me dio a mi 10 centavospara comprar un limonpero no quiero limonyo quiero bubble gumBazooka Bubble GumBazooka Bubble GumMi mama me dio 5 centavospara comprar un heladopero no quiero heladoyo quiero bubble gumThat translated into English is:My mom gave me one peso [[mexican coin]]to buy some candybut I don't want candyI want a bubble gumBazooka Bubble GumBazooka Bubble GumMy mom gave me a peseta [[old spanish coin]]to buy some hambut I don't want hamI want a bubble gumBazooka Bubble GumBazooka Bubble GumMy mom gave me 10 centsto buy a lemonbut I don't want a lemonI want a bubble gumBazooka Bubble GumBazooka Bubble GumMy mom gave me 5 centsto buy some ice creambut I don't want an ice creamI want a bubble gum