Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,379 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,039 people online right now. Registration is fast and FREE... Join Now!




2 Instances of Quicksort?

 
Reply to this topicStart new topic

2 Instances of Quicksort?

JediSpam
28 Sep, 2006 - 11:48 PM
Post #1

New D.I.C Head
Group Icon

Joined: 6 Sep, 2006
Posts: 42


My Contributions
Hello,
I'm having trouble trying to understand what my teacher is asking on the upcoming homework. He says we need to have to separate instances of quicksort in one source file. Here is his words:
QUOTE


Design and implement two versions of QuickSort over a set of input integers. The first version should choose the pivot as the first array location. The second version should choose the pivot as the middle value of the triple

< first value, last value, (first+last)/2-th value >

Count the number of comparisons performed by the partition function for each version.


He also posted this:
QUOTE

A script file showing you running the test program for:

* Partition 1 with array of size 10
* Partition 2 with array of size 10
* Partition 1 with array of size 20
* Partition 2 with array of size 20


i e-mailed him asking about the comparisons and this was his response:
QUOTE

It is the number of comparisons of array elements needed to sort the array. So you will
need to add up all of the comparisons done in recursive calls.



What does he mean by counting the number of comparisons? is the number of comparisons going to be a value going through both instances of the quicksort or each one indvidually? and how do i make a script file showing the information he wants? i have never had experience with making a script file. thanks
User is offlineProfile CardPM
+Quote Post

JediSpam
RE: 2 Instances Of Quicksort?
29 Sep, 2006 - 09:19 AM
Post #2

New D.I.C Head
Group Icon

Joined: 6 Sep, 2006
Posts: 42


My Contributions
someone pleasee sad.gif i can show the code i have if you want
User is offlineProfile CardPM
+Quote Post

supersloth
RE: 2 Instances Of Quicksort?
29 Sep, 2006 - 02:35 PM
Post #3

serial frotteur
Group Icon

Joined: 21 Mar, 2001
Posts: 19,654



Thanked: 12 times
Dream Kudos: 2147483647
Expert In: being gentlemanly

My Contributions
QUOTE
[16:15] JediSpam: hey
[16:17] itssupersloth: yo
[16:17] JediSpam: do you think you could check out my post on the c++ category? i need help
[16:22] itssupersloth: ill check it out later
[16:22] itssupersloth: im busy pushing some code at work right now
[16:22] JediSpam: ah ok
[16:22] JediSpam: thats cool
[16:22] itssupersloth: the quicksort thread?
[16:22] JediSpam: yeah
[16:23] JediSpam: i've made one completely that works but i need help on trying to figure out using 2 in one source file
[16:23] JediSpam: and what my professor is asking
[16:24] itssupersloth: just create two functions
[16:26] JediSpam: but i have to count the number of comparisons.. i have ONE set of 10 values going through both of them? i don't get it
[16:27] itssupersloth: you would just have each function take a look at the original array
[16:27] JediSpam: ah.. so the number of comparisons is all of the comparisons combined i guess?
[16:27] itssupersloth: take the first function with your pivot and have it look at the original array
[16:27] itssupersloth: get its output
[16:28] itssupersloth: then take the second function with the original array
[16:28] itssupersloth: the point of the exercise as far as i can tell
[16:28] JediSpam: ah i see
[16:28] JediSpam: is comparing the two
[16:28] itssupersloth: is to show you how the pivot affects the number of times it sorts the array
[16:28] JediSpam: i would think that too.. but we're only printing out one set of comparisons? doesn't make sense
[16:28] itssupersloth: because one will have many more iterations to output the same result
[16:29] itssupersloth: email your teacher again asking if this information is correct
[16:29] itssupersloth: does that make sense though??
[16:29] JediSpam: yeah i see what you're saying


[16:29] JediSpam: and i understand the point is to see which uses less comparisons
[16:30] itssupersloth: koo
[16:30] JediSpam: but on the example of the program's output it does this:

The original order is: 22 13 54 12 26 43 38 19 28 14
The sorted order is: 12 13 14 19 22 26 28 38 43 54
The number of comparisons required is: 15
[16:30] JediSpam: how come it wouldn't have two different sets of comparisons.. one for the first quicksort and one for the second
[16:30] itssupersloth: its adding to the counter everytime it swaps a spot in the array
[16:31] JediSpam: ahhhh ok
[16:31] JediSpam: i think i understand
[16:31] itssupersloth: i think he means one comparison for each function
[16:31] itssupersloth: so you should have a number for qs1 at 10, qs1 at 20, qs2 at 10 and qs2 at 20
[16:31] JediSpam: ahh
[16:32] JediSpam: so how does the script file work? i've never written one
[16:32] itssupersloth: that way you can see how the pivot affects the number of comparisons
[16:32] JediSpam: yeah
[16:32] itssupersloth: i think he just means a text file of your output
[16:32] JediSpam: yeah
[16:32] itssupersloth: BUT for that you will have to ask him
[16:32] JediSpam: ok
[16:32] itssupersloth: which i would do to verify
[16:33] itssupersloth: is it allright if i post this conversation?
[16:34] JediSpam: sure
[16:34] JediSpam: copyright jedispam,sloth

User is offlineProfile CardPM
+Quote Post

JediSpam
RE: 2 Instances Of Quicksort?
29 Sep, 2006 - 02:37 PM
Post #4

New D.I.C Head
Group Icon

Joined: 6 Sep, 2006
Posts: 42


My Contributions
thanks man cool.gif i appreciate the help
User is offlineProfile CardPM
+Quote Post

skyhawk133
RE: 2 Instances Of Quicksort?
29 Sep, 2006 - 02:56 PM
Post #5

Head DIC Head
Group Icon

Joined: 17 Mar, 2001
Posts: 14,974



Thanked: 48 times
Dream Kudos: 1650
Expert In: Web Development

My Contributions
LOL @ copyright. Glad Josh could help you out JediSpam!
User is offlineProfile CardPM
+Quote Post

JediSpam
RE: 2 Instances Of Quicksort?
29 Sep, 2006 - 04:01 PM
Post #6

New D.I.C Head
Group Icon

Joined: 6 Sep, 2006
Posts: 42


My Contributions
this ended up being way easier than I thought. I am master of sorting now cool.gif
User is offlineProfile CardPM
+Quote Post

DeeViLiSh
RE: 2 Instances Of Quicksort?
29 Sep, 2006 - 09:48 PM
Post #7

D.I.C Head
Group Icon

Joined: 25 Jul, 2006
Posts: 175



Thanked: 1 times
Dream Kudos: 575
My Contributions
=O oh me gosh, I wanna talk to super-sexy-sloth =(
Where that log bez from?
User is offlineProfile CardPM
+Quote Post

Dark_Nexus
RE: 2 Instances Of Quicksort?
1 Oct, 2006 - 02:19 PM
Post #8

or something bad...real bad.
Group Icon

Joined: 2 May, 2004
Posts: 1,309



Thanked: 3 times
Dream Kudos: 625
My Contributions
i am going to say his hard drive
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/5/08 01:44AM

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