Solved

C++ selection sort and insertion sort

Posted on 2010-08-15
2
875 Views
Last Modified: 2013-11-17
I would like it if someone would check my answers to make sure I am understanding the sorts properly.  Please and thank you.

Consider the array based list of (10, 4, 8, 2, 7) as input for selection sort and insertion sort algorithms in the following questions:

The number of comparisons made by the selection sort is:   3
The number of comparisons made by the insertion sort is:   7
Note that each swap requires 3 moves.  The number of moves made by the selection sort is:   9
The number of moves made by the insertion sort is:   7
0
Comment
Question by:veeaechone
2 Comments
 
LVL 7

Accepted Solution

by:
jhp333 earned 500 total points
ID: 33443062
The number of comparison by selection sort is always n(n-1)/2, which is 10 when n=5.
0
 

Author Comment

by:veeaechone
ID: 33450472
Got it!  Thanks for your help!
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now