Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 136,159 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,910 people online right now. Registration is fast and FREE... Join Now!




Sorting help

 
Reply to this topicStart new topic

Sorting help, bubble, selection, and insertion

kelliethile
10 Dec, 2007 - 04:22 PM
Post #1

New D.I.C Head
*

Joined: 22 Oct, 2007
Posts: 14


My Contributions
I don't know how to get comparisons of bubble sort... please help.

And are my answers correct?
Please advice and fix if you believe my answers are wrong... thanks! cool.gif
IMPORTANT: I don't need any codings. I just want to make sure my answers are correct or not.
Are my selection, insertion, and bubble sort--- are they sorted correctly?


Problem statement
Given the following array 4 2 7 3 5 1 6
List each *different* state of the array after sorting it in ascending order with:
A) Insertion sort
B ) Selection sort
C) Bubble sort

A. Original array_____________Destination array_______Comparisons
4 2 7 3 5 1 6 (Insertion sort)
2 7 3 5 1 6__________________--4--> 4___________________0
7 3 5 1 6____________________--2--> 2 4 _________________1
3 5 1 6_____________________--7--> 2 4 7 ________________2
5 1 6 ______________________--3--> 2 3 4 7_______________2
1 6________________________--5--> 2 3 4 5 7______________4
6__________________________--1--> 1, 2, 3, 4, 5, 7_________1
___________________________--6--> 1, 2, 3, 4, 5, 6, 7_______6
____________________________________________________= 16 comparisons

B. 4 2 7 3 5 1 6 (Selection sort)
1 2 7 3 5 4 6_________________(get min of 7 elems swap at 0)____7
1 2 7 3 5 4 6_________________(get min of 6 elems swap at 1)____6
1 2 3 7 5 4 6_________________(get min of 5 elems swap at 3)____4
1 2 3 4 5 7 6_________________(get min of 4 elems swap at 2)____3
1 2 3 4 5 6 7_________________(get min of 3 elems swap at 1)____1
______________________________________________________= 21 comparisons

4 2 7 3 5 1 6 (Bubble sort)
2 4 7 3 5 1 6_________________(swap if A[i] > A[i+1]) __________1
2 4 3 7 5 1 6_________________(swap if A[i] > A[i+1]) __________dunno
2 3 4 7 5 1 6_________________(swap if A[i] > A[i+1]) __________-
2 3 4 5 7 1 6_________________(swap if A[i] > A[i+1]) __________-
2 3 4 5 1 7 6_________________(swap if A[i] > A[i+1]) __________dunno
2 3 4 1 5 7 6_________________(swap if A[i] > A[i+1]) __________dunno
2 3 1 4 5 7 6_________________(swap if A[i] > A[i+1]) __________help!
2 1 3 4 5 7 6_________________(swap if A[i] > A[i+1]) __________help!
1 2 3 4 5 6 7_________________(swap if A[i] > A[i+1]) __________help!
________________________________________________________= help me find total comparisons of bubble sort

This post has been edited by kelliethile: 10 Dec, 2007 - 08:12 PM
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Sorting Help
10 Dec, 2007 - 07:01 PM
Post #2

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 8,983



Thanked: 125 times
Dream Kudos: 8625
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
I truly hope you're not expecting us to code that for you, as here at </dream.in.code> it is a forum rule to not do peoples homework, and thats a rule thats strictly enforced smile.gif
User is online!Profile CardPM
+Quote Post

kelliethile
RE: Sorting Help
10 Dec, 2007 - 08:11 PM
Post #3

New D.I.C Head
*

Joined: 22 Oct, 2007
Posts: 14


My Contributions
no... i don't want codings.
no coding involved.

i just want to see if i have the bubble, selection, and insertion sorted correctly....


NO CODES NEEDED!
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 11:47PM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month