answersLogoWhite

0

What are issues of binary sort?

Updated: 8/21/2019
User Avatar

Wiki User

7y ago

Best Answer

There's no such thing as a binary sort. You are possibly referring to a binary insertion sort which is based upon binary search.

The most efficient binary search makes use of a sorted array. This offers us constant-time random-access to any element. By keeping track of the upper and lower indices of a subset, we can easily calculate the middle element of that subset:

middle = (upper - lower) / 2 + lower

Given an array A of length n, we can search for a given value as follows:

unsigned search (const int* A, const unsigned n, int value) { int lower = 0;

int upper = n;

while (lower<upper) {

int middle = (upper - lower) / 2 + lower;

if (value == A[middle])

return middle;

else if (value < A[middle])

upper = middle;

else

lower = middle+1;

}

return n;

}

Note that we return the index of the value if found. If not, we return n, which is the index one-past-the-end of the array. We can use the algorithm as follows:

unsigned find;

const unsigned max = 10;

int X[max] = {3, 5, 7, 9, 11, 13, 15, 17, 19, 21}; // sorted array

find = search (X, max, 15); // search for value 15

assert (find==6);

find = search (X, max, 20); // search for non-existent value

assert (find==max);

We can modify the binary search algorithm such that we can locate the insertion point for a new value, thus creating a binary insertion sort. First, we locate the insertion point:

unsigned find_insert (const int* A, const unsigned n, int value) {

int lower = 0;

int upper = n;

while (lower<upper) {

int middle = (upper - lower) / 2 + lower;

if (A[middle]>value && (middle==0 A[middle-1]<=value))

return middle;

else if (value < A[middle])

upper = middle;

else

lower = middle+1;

}

return n;

}

Note that we're now looking for a value that is greater than our value such that the previous value is less than or equal to our value or there is no previous value.

With this algorithm in place, we can now perform the insertion:

unsigned insert (int* A, const unsigned n, int value) {

unsigned index = find_insert (A, n, value);

for (unsigned i=n; i>index; --i) A[i] = A[i-1];

A[index] = value;

return index;

}

Note that, prior to invoking the insertion, you must reserve one or more unused elements at the end of the array (at index n or beyond).

User Avatar

Wiki User

7y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What are issues of binary sort?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What are some sorting rules for math?

Binary sort and bubble sort are two.


Legal issues with waxing?

what sort of ethical issues are there when waxing ?


Why most all in digital be from binary?

Because the switches that are used are usually on/off switches. Notice: on + off = two settings. Binary = Two digits. To get something digital and non-binary (for example, trinary) you would need a switch that can be "on", "off", and "sort of on". In addition, you wold need logic gates that support this "sort of on" setting.


Which of the following cannot be implemented efficiently in linear linked list 1 quicksort 2 radix sort 3 polynomials 4 insertion sort 5 binary search?

radix sort


Is binary numbers is the internal language of computer?

A computer only understand binary, which is 0 as "off" and 1 as "on."


What is interpersonel issues?

An interpersonal relationship is any form of relationship having to do with love or like of any sort with any sort of committment. It can consist of family, church, friends, anybody. And also can consist of groups. So interpersonal issues is that of when you are having issues internally with those people.


What sort of health issues might chimney sweeps suffer from?

they might get some sort of deasie the the dust will contain and what they are breathing in when they go in the chimney.lol


Does Rosalie hale have anger issues?

sort of she doesn't like the fact that a human knows that they are vampires


How is a binary used?

Binary what? Binary numbers? Binary stars? Binary fission?


What is the benefit of paravirtualization?

The benefits of paravirtualization include reduced complexity, greater reliability, and improved performance issues with operating systems. Originally, an operating system used a binary method to translate computer languages. Paravirtualization removes the need to use the binary method.


Is there a .bat to .exe converter that also makes a dll with the .exe too?

No. A bat file is sort of a script. It cannot be compiled nor changed into binary executable.


What sort of safety issues are involved with free weight systems?

Serious bodily injury is your biggest concern.