I currently have one AsyncTask that currently compares images using the bubble sort method using OpenCV. Let's say I have to compare 400 images with each other. This would mean comparisons of 400*401/2=80,200 . Suppose one comparison takes 1 second. So, 80,200 sec , which is around 22.27 hours , which is ridiculously long. So, I developed an algorithm of this type:
It divides 400 images into groups of 5 . Thus, in each group there are 80 images.
The first part of the algorithm is the images comparing themselves within the group members.
So, image1 will compare itself with image2-80 , which means there are 79 comparisons. image2 will have 78 comparisons and so on. Which makes comparisons 3,160 . Or 3,160 sec . Similarly, image81 will compare itself with image82-160 and so on. So, all the "group comparisons" were completed in 3,160 sec , because they are executed in parallel.
The second part of the algorithm will compare the elements of group 1 with the elements of group 2 , group 2 with group 3 , group 3 with group 4 and so on. This would mean that image1 would be compared with image81-160 , which corresponds to 80 , and therefore the general comparison between group 1 and group 2 would be 80*80=6400 comparisons. Is it possible that each image comparison is in parallel with group comparisons? That is, if image1 compares itself with image81-160 , then image2 should do the same and so on, while other groups do the same. So this part should only take 6400 sec .
Now group1 will be compared with group3 , group2 with group4 , group3 with group5 . → 6400 sec
After which group1 will be compared with group4 and group2 with group5 . → 6400 sec
So, all groups are compared.
Total time = 3160+6400+6400+6400=22,360sec . I understand that the more groups, the more time it will take. Therefore, I would have to increase the size of the group to reduce the time. In any case, this reduces the time to almost 1/4th actual time.
Is this algorithm unrealistic? If so, why? What are the disadvantages? How can i fix this? Is there a better algorithm for comparing a list of images faster? Obviously not quick sort , I cannot sort the images in ascending or descending order. Or can I?
If this algorithm is possible? What would be the best way to implement it? Thread or AsyncTask ?