Loading...
Logo
Processing Forum

sorting algoritms? Java or c++?

in General Discussion  •  Other  •  10 months ago  
Hi, 

I'm doing some research on sorting large arrays.   I'm talking millions of entries. Which of the two should I choose.  I'm trying to sort, adjust, count on vertexes.

Replies(4)

It shouldn't matter, sorting algorithms are language independent and then implemented in a particular language as needed. The code for either language would probably look nearly identical and should run in n log n time regardless of which is chosen.
There are 2 questions here
  1. sorting algorithms?
  2. Java or C++;
When you are considering millions of entries then you want to avoid the selection sort, bubble sort etc as these work in at O(n 2)  speed which means the time to sort them proportional to the square of the number of elements in the array i.e. doubling the array size quadruples the time to sort. A possibility is the Quick Sort O(n log 2n) which is very fast.
The alternative is to maintain the data in a sorted data structure for example a Binary Search Tree (self balancing) or If the data is held on disc you might consder a B Tree structure

C++ is invariably faster than Java.


I'm trying to sort, adjust, count on vertexes
I assume that you mean a position in 3D space. Now to sort the data elements it must be possible to compare two elements and determine if they are equal or if one is greater/lesser than the other. So how planning on comparing two vertex positions?

I was allready busy with adjusting the vertexes optically, so that the sortening algoritms for hashMaps and arraylists could be used. Using distances of vertexes and rotating the shapes, would be simple steps to adjusting the vertex arrays for better comparison. The database is building information of all the buildings in the Netherlands.  Here an example:
 
" C++ is invariably faster than Java."
Not always...
Someone can code poorly C++ and have mediocre performance.
Beside, on critical loops, the HotSpot JIT compiler can generate highly optimized native code which can be faster than manually written C++ (inlining code, unrolling loops, etc.)