i need an algorithm to compare heapsort vs quicksort
Implement heapsort and quicksort yourself, and then time them or count the number of comparisons.
Try something like this: public static void main(String[] args) { int []a1={11,8,6,4,2,16,9,10,14,8,7}; int []a2={11,8,6,4,2,16,9,10,14,8,7}; long estimatedTime = System.nanoTime(); long startTime = System.nanoTime(); sortHeap(a1); //you will need to write this class estimatedTime = System.nanoTime()-startTime; System.out.print("Heap sort took :"+estimatedTime.toString); startTime = System.nanoTime(); sortQuick(a2); //you will need to write this class estimatedTime = System.nanoTime()-startTime; System.out.print("Quick sort took :"+estimatedTime.toString); //compare for(int i=0;i<a1.length;i++){ System.out.print(a1[i] + " "+ a2[i]); } } }
Join our real-time social learning platform and learn together with your friends!