How can i decide which sorting method to use in c ( Ex : Bubble Sort, Merge Sort)

Well Friends, to deside which method shout be used you should ask Some important questions you should ask yourself are:

- How expensive are comparisons?
- Are comparisons monolithic, or is there a useful notion of partial comparison?
- How many items are there to sort?
- Are the items basically in random order?
- How limited is memory?
- How bad are cache misses?

To use the answers to those questions, you'll need to be familiar with sorting methods. I'm not going to teach you; there's lots of accessible literature on the subject. But some quick examples of how these criteria might influence your choice of algorithm:

- If there are very few items, then the fast algorithms don't pay for the overhead. Insertion sort is probably the way to go.
- If the cost of comparisons dwarfs everything else, then you may want to minimize the number of comparisons. It's hard to do better than something like insertion sort with binary search to find the insertion location.
- But if you can do partial comparisons, like with strings, then radix methods are an obvious candidate.
- If the problem has no outstanding characteristics, then quicksort is a good first choice, but it has some gotchas. You can read about that in a textbook.

Related Links :

No comments:

Post a Comment

If you face any Problem in viewing code such as Incomplete "For Loops" or "Incorrect greater than or smaller" than equal to signs then please collect from My Web Site CLICK HERE

More Useful Topics...


History Of C..

In the beginning was Charles Babbage and his Analytical Engine, a machine
he built in 1822 that could be programmed to carry out different computations.
Move forward more than 100 years, where the U.S. government in
1942 used concepts from Babbage’s engine to create the ENIAC, the first
modern computer.
Meanwhile, over at the AT&T Bell Labs, in 1972 Dennis Ritchie was working
with two languages: B (for Bell) and BCPL (Basic Combined Programming
Language). Inspired by Pascal, Mr. Ritchie developed the C programming

My 1st Program...

void main ()
clrscr ();
printf ("\n\n\n\n");
printf ("\t\t\t*******Pankaj *******\n");
printf ("\t\t\t********************************\n");
printf ("\t\t\t\"Life is Good...\"\n");
printf ("\t\t\t********************************");
getch ();

Next Step...


void main ()
clrscr ();
printf ("\n\n\n\n\n\n\n\n");
printf ("\t\t\t --------------------------- \n\n");

printf ("\t\t\t | IGCT, Info Computers, INDIA | \n\n");
printf ("\t\t\t --------------------------- ");

getch ();