answersLogoWhite

0

How do you input 10 English alphabet in insertion sort?

Updated: 8/19/2019
User Avatar

Wiki User

10y ago

Best Answer

Starting with an array of 10 elements, maintain a count, c, of used elements and initialise to zero. During an insertion, if c is zero, simply place the data in element zero and increment c. If c is non-zero, assign c to a "hole" variable, h. While h is non-zero, compare the data at array[h-1] with the new data. If it is greater, copy array[h-1] to array[h] and decrement h. Continue until h is zero or the data at element array[h-1] is not greater than the new data. Assign the new data to element array[h].

Note that it does not matter what the array contains, the principal is exactly the same. The only difference is in the comparison routine. To compare integrals, you can simply use the greater_than operator (>). For strings, you will typically store pointers to the string objects and indirectly call the string object's greater_than operator. You may store the strings themselves, but this is less efficient due to the inefficiencies incurred when copying strings. For primitive character arrays, you will typically call an external function, such as the strcmp() function in the C++ standard library, to compare the character arrays. For more complex sorting, such as radix sorting (such that the string "2" comes before the string "10") you may need to use 3rd party libraries if such functionality is not built in, or write your own comparison function. Ultimately, the exact functions you use will depend on which language you are writing your code in.

User Avatar

Wiki User

10y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you input 10 English alphabet in insertion sort?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you write a program that accepts 50 integer values and sort them in basic programming?

Create an array with 50 elements and input the integers one a time, filling the array. Use an insertion sort on the array for each input except the first. Alternatively, input the values first and then use insertion sort.


Who is best merge sort or insertion sort?

Merge sort is good for large data sets, while insertion sort is good for small data sets.


Why comparisons are less in merge sort than insertion sort?

the main reason is: Merge sort is non-adoptive while insertion sort is adoptive the main reason is: Merge sort is non-adoptive while insertion sort is adoptive


Using doublelinked list insertion sort in c language?

using doublelinked list insertion sort in c language


Explain and illustrate insertion sort algorithm to short a list of n numburs?

Explain and illustrate insertion sort algorithm to short a list of n numburs


How do you sort a link list?

You copy the list, while using an insertion sort criteria.


Which algorithm is more efficient- insertion sort algorithm or merge sort algorithm?

On average merge sort is more efficient however insertion sort could potentially be faster. As a result it depends how close to reverse order the data is. If it is likely to be mostly sorted, insertion sort is faster, if not, merge sort is faster.


Is Greek language hard to learn?

No it's not hard to learn. It's really easy.... If You're Greek. Or half Greek or at least have some sort of Greek in you. You need to know the alphabet. The Greek Alphabet does not have al of the English alphabet. So you can't really write down all the alphabet in English and in Greek... Unless you are especially talented at the Greek alphabet like me then you can learn very easily.


Who invented insertion sort?

There are no records of when insertion sort was invented because people have been sorting things using the insertion sort and selection sort algorithms since before records began; they are ancient algorithms. You cannot be credited for creating an algorithm that already exists. Shell sort, which is a refinement of insertion sort, was developed much later, in 1959 by Donald Shell. His algorithm can be credited because it takes advantage of a computer's processing abilities, whereas insertion sort and selection sort rely purely on a human's processing abilities.


What are the advantages of insertion sort?

It is less efficient on list containing more number of elements. As the number of elements increases the performance of the program would be slow. Insertion sort needs a large number of element shifts.


Suppose you are comparing implementations of insertion sort and merge sort on the same machine For inputs of size n insertion sort runs in 8n2 steps while merge sort runs in 64n lg n steps For which v?

we can give the delay function to the faster processing sort we can give the delay function to the faster processing sort


What is the main idea behind insertion sort?

The main idea of insertion sort is to consider each element at a time into an appropriate position relative to the sequence of previously ordered elements,such that the resulting sequence is also ordered.