V
V
VZVZ2016-04-18 17:50:23
Algorithms
VZVZ, 2016-04-18 17:50:23

Is it true that the more “scattered” an array of numbers is, the longer it will take to sort it (say, with a bubble)?

Let's say if I sort 2 separate arrays, then merge them into one by adding elements of one between the elements of the other (like braiding a pigtail), and then sort the resulting array again, then this last sort will take less time than if I initially had 1 array?
If you don't feel like answering the second question, answer the first.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
U
uvelichitel, 2016-04-18
@uvelichitel

For bubble sort
For the above approach (separately sort the parts then merge), merge-sort is used.

M
MiiNiPaa, 2016-04-18
@MiiNiPaa

1. In general, no.
2. Maybe yes, maybe not. Strongly depends on the used algorithm and elements of arrays.

A
abcd0x00, 2016-04-19
@abcd0x00

Very similar to merge sort and heapsort. In order not to invent these sorts (which, of course, are faster than bubble sort), it is better to find their description and implement each separately.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question