- Home /
min move required to sort color balls in tubes
How can I get min move required to sort color balls in tubes.
Answer by Llama_w_2Ls · Dec 09, 2020 at 07:39 AM
Solution
It depends what sorting algorithm you're using. If you assign the colors a number (such as red = 1 and blue = 10) and sort the list using C#'s built-in sorting algorithm (intro-sort - a hybrid sorting algorithm of quicksort and heapsort) you can sort it very quickly. Like, very very quickly. (1 million items took me 0.1 seconds).
However, you won't be able to implement a method of counting how many moves you would need to sort the list, unless you implement your own quicksort/heapsort/mergesort/bubblesort and increment a counter value every time you move a number/coloured ball.
Sorting Algorithm to use
I would recommend learning mergesort or quicksort and implementing your own version, since they aren't as difficult to implement but are very effective, giving you the minimum number of moves. If you're using a small data set of like 16 numbers or less, bubble sort or insertion sort would work fine as well. They're very easy to implement but only solid for smaller data sets.
@mian_abdul
Your answer
Follow this Question
Related Questions
Comparing Two Arrays 1 Answer
How to sort a List by a class paramater 1 Answer
Two cameras depth-sorting correctly (for use with blur etc.) 0 Answers
Layers out of order can anyone help? 0 Answers