Hi. I have a program where I have to sort a list using three different sorts (quick, heap, and merge). I have all the done but now the problem is that I have to calculate the exact complexity on each. IF anyone can help me with how to code that into the program that would be great. Obviously you'd have to have some kind of counts but I don't know the calculations.

William Hemsworth commented: Urgent? -1

If you're counting the operations, there's not really much calculation to do. You should keep separate counters for the comparisons and the exchanges/assignments. Be sure to do your tests with the same data set to each sort function. Then display the counts of compares/assignments.

Note that these results will vary with different data sets, but should demonstrate the relationships of the Big O of the different sorts.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.