Data comparisons and movements

I have a Heap Sort using the following code, and I cannot seem to figure out how many data comparisons and data movements there are as the heap is sorted. Does anybody know how to count the number of comparisons and movements?? Please let me know....much appreciated...Thanks :)
import java.io.IOException;
import java.util.*; // Calender Class for timing
public class Heap {
private MyNode[] heapArray;
private int maxSize;
private int currentSize; // number of items in array
public Heap(int mx) {
maxSize = mx;
currentSize = 0;
heapArray = new MyNode[maxSize];
public MyNode remove()
MyNode root = heapArray[0];
heapArray[0] = heapArray[--currentSize];
trickleDown(0);
return root;
public void trickleDown(int index) {
int largerChild;
MyNode top = heapArray[index];
while (index < currentSize / 2)
int leftChild = 2 * index + 1;
int rightChild = leftChild + 1;
// find larger child
if (rightChild < currentSize
heapArray[leftChild].getKey() < heapArray[rightChild]
.getKey())
largerChild = rightChild;
else
largerChild = leftChild;
if (top.getKey() >= heapArray[largerChild].getKey())
break;
heapArray[index] = heapArray[largerChild];
index = largerChild;
heapArray[index] = top;
public void displayHeap() {
int nBlanks = 32;
int itemsPerRow = 1;
int column = 0;
int currentIndex = 0;
while (currentSize > 0)
if (column == 0)
for (int k = 0; k < nBlanks; k++)
System.out.print(' ');
System.out.print(heapArray[currentIndex].getKey());
if (++currentIndex == currentSize) // done?
break;
if (++column == itemsPerRow) // end of row?
nBlanks /= 2;
itemsPerRow *= 2;
column = 0;
System.out.println();
else
for (int k = 0; k < nBlanks * 2 - 2; k++)
System.out.print(' '); // interim blanks
public void displayArray() {
for (int j = 0; j < maxSize; j++)
System.out.print(heapArray[j].getKey() + " ");
System.out.println("");
public void insertAt(int index, MyNode newNode) {
heapArray[index] = newNode;
public void incrementSize() {
currentSize++;
public static void main(String[] args) throws IOException {
int size, i;
size = 500;
Heap theHeap = new Heap(size);
for (i = 0; i < size; i++) {
int random = (int) (java.lang.Math.random() * 5000);
MyNode newNode = new MyNode(random);
theHeap.insertAt(i, newNode);
theHeap.incrementSize();
System.out.println(size+" random numbers are currently being generated...");
for (i = size / 2 - 1; i >= 0; i--)
theHeap.trickleDown(i); // creates the heap
System.out.print("\nRandom Numbers in a Heap: ");
theHeap.displayArray(); // prints the heap
long time1000start = new Date().getTime() ; // this makes a new Date object and then sets the long integer value of the Date object
// ******************* START - sorting numbers *******************
for (i = size - 1; i >= 0; i--)
MyNode biggestNode = theHeap.remove();
theHeap.insertAt(i, biggestNode);
// ******************* END - sorting numbers *******************
long time1000end = new Date().getTime() ; // this makes a new Date object and then sets the long integer value of the Date object
double timediff1000m = (time1000end - time1000start); // difference of time in milliseconds
double timediff1000s = ((time1000end - time1000start) / 1000); // difference of time in seconds
System.out.print("\nRandom Numbers in a Sort: ");
theHeap.displayArray(); // prints the numbers in increasing order
System.out.print("\nStart Time of Sort: "+time1000start);
System.out.print("\nEnd Time of Sort: "+time1000end);
System.out.print("\nTime to Complete Sort: "+timediff1000m+" milliseconds or "+timediff1000s+" seconds.");
} // end main method
} // END project :)

I never miss class....my instructor gave us the assignment of making a heap sort and he told us to use code off the internet as a resource because the only sorting we have done so far is bubble.....this was a research project, for my instructor to see if we can use the internet as an effective resource to put together a program and learn about a differnet type of sorting.....everyone in the class got a different type of sort (merge, quick, insertion, etc...). i have put the program together and customized it to my needs based on my knowledge.....the last thing i am having trouble with is my counting of comparisons and data movements. Can you please help me finish up my program.

Similar Messages

  • Data comparison and deletion of duplicates

    I have moved all of my data over to the mac from my PC. Everything has been fairly smooth, but I have a question for some of you regarding data duplication which I have not found a work around yet. Currently, I own a mac mini running 10.4.3 and I also picked up a copy of Filemaker Pro 7 along with MS Office 2004. I needed a database program for the Mac to keep my email lists up to date, but I haven't had time to tinker with Filemaker 7. So my problem is as follows:
    There are two .txt files. One with current email address's and the second with outdated email address's. I need to compare both files together and when I find a match between the current and bad email address I need to delete the address in the current email txt file.
    I am not fluent enough in Filemaker 7 to figure out how to do a comparison between the 2 tables and then delete the appropriate data when there is a match. I had this set up available on MS Access on my PC, but I need to replicate this process on the Mac. What options do I have available or if someone can help me in the right direction to a possible solution. I would assume that Automator could do this. Maybe there is something in Excel that I can create a workaround.
    Thanks again.
    Dankman

    FileMaker Pro has some support options where you might be able to find some more help:
    http://www.filemakerpro.com/support/mailinglists.html
    -Doug

  • Data comparison and update/insert between two schemas in same database

    Hi all,
    I have requirement like this. In one database, i am having two users, user1 and user2. Both users is having same tables and structure wise also same. In user1, data will be populated by job.
    Now, what i want to do is, i have to find out difference between user1 and user2 data and the Difference data will be updated/inserted into the user2.
    Any ideas please...
    Thanks in advance,
    Pal

    Will trigger help you ... ie. for every update/insert on user1 will do on user2-- it is heavy to do for all table...
    --svmg                                                                                                                                                                                                                                                                   

  • How do I create a permanent backup of all my iTunes data, and movies?

    I'm confused about how to effectively backup and share my data.  And know others must have wrestled with this one too - so help please!
    Our family works across several platforms (PC, MacBookPro, 2 iPads, iPods, 2 iPhones and appleTV) and want to have a method to effectively share and save (i.e. permanently backup) our data (iTunes, other documents and movies).   We use HomeSharing, iCloud and iTunes Match, which work most of the time.  All the devices are linked to a single iTunes library.
    I understand that iCloud serves to synchronise data and share it between devices. Great.  But how do I create a permanent backup of the data?  I could get a third party online service (e.g. Box.net) or use external harddrives.  Is there a simpler approach that apple provides, that I've missed?  I'd lke to make teh solution a simple to use (i.e. upload data and share it), reliable without paying the earth! 

    Have you considered this...
    Backup iTunes to an External Drive  >  http://support.apple.com/kb/HT1751
    And there is this  >  ..Most commonly used backup methods

  • Having arranged some scanned pictures in an album in I-Photo how can I keep them in the order I have chosen when I move the album. They all have the scan date and not the taken date and move to new positions if I move them from one album to another.

    Having arranged some scanned pictures in an album in I-Photo how can I keep them in the order I have chosen when I move the album. They all have the scan date and not the taken date and move to new positions if I move them from one album to another.
    Is there any way to re-number them in the order I have chosen so that they can then be sorted by number? The scans are all from pre-digital images that I wish to move to a photobook and I don't want to have to organise them twice!
    Thanks for any suggestions.

    I was a bit short, Chris, sorry. It is limited, what can be posted, when typing on an iPad.
    Now I am back on my Mac. I meant the following:  Batch Change the date for a large range of photos, that should have a date stepped in increments.
    Select all Photos at once and use the command "Photos > Batch Change".
    Then set the date for the first photo and select an increment, e.g. one minute.
    Now all photos will get a new date assigned, incremented by one minute, in the sequence you have selected. So you will be able to sort them by date.  This way it will be unnecessary to change the titles or filenames.

  • How can I stop music and movies from being automatically deleted from my phone and saved on the cloud? I've just tried to watch a movie on my 2 hour commute, but yet AGAIN it has been removed. I do NOT want to spank all of my data allowance

    How can I stop music and movies from being automatically deleted from my phone and saved on the cloud? I've just tried to watch a movie on my 2 hour commute, but yet AGAIN it has been removed. I do NOT want to spank all of my data allowance downloading it again, especially because (believe it or not) I added it to my phone because that's precisely where I wanted it!! Any help much appreciated

    FYI I had to put this link into firefox to reply - because **** back safari just wouldn't register my clicks to any of the links on the post... Despite reloadeing and even restarting my computer. Totally annoying and a massive pain in the ***.
    But in terms of my initial query; thanks for responding. But no, this is NOT the cause of the problem. I have auto sync and sync over wifi activated, but have also selected manually manage music and videos. Plus, all of my music and videos are on my macbook, absolutely all of it, so if it my phone was syncing with my macbook everything would still be on the phone. Life would be peachy if my phone jsut copied everything that was on my macbook, but unfortuantely it keeps deleting tracks for no apparent reason.
    Any thoughts greatly welcomed, because at the moment i can only conclude that my iphone is crap.

  • How do you transfer iTunes music and movies from an old PC to a new PC.  I have all data svaed on an external hard drive.

    How do you transfer iTunes music and movies from an old PC to a new PC.  I have all data svaed on an external hard drive.

    This article should outline the options
    http://support.apple.com/kb/HT4527

  • I just put a solid state hard drive in my mac book pro and used super duper to copy the hard drive and move the data over to thew new ssd, but most of my music isn't in iTunes when I turned it on? How do I get my music to show up in my new drive?

    I just put a solid state hard drive in my mac book pro and used super duper to copy the hard drive and move the data over to thew new ssd, but most of my music isn't in iTunes when I turned it on? How do I get my music to show up in my new drive?

    Many thanks lllaass,
    The Touch Copy third party software for PC's is the way to go it seems and although the demo is free, if you have over 100 songs then it costs £15 to buy the software which seems not a lot to pay for peace of mind. and restoring your iTunes library back to how it was.
    Cheers
    http://www.wideanglesoftware.com/touchcopy/index.php?gclid=CODH8dK46bsCFUbKtAod8 VcAQg

  • I just used stellar phoenix mac data recovery and it seemed to work but now my files won't open.  Even though they are "jpeg, mov" files the error message is  could not be opened. The movie's file format isn't recognized. "  Any help or are they corrupted

    I just used stellar phoenix mac data recovery and it seemed to work but now my files won't open.  Even though they are "jpeg, mov" files, the error message is  "could not be opened". The movie's file format isn't recognized. "  Any help or are they corrupted?

    Sounds to me like the file is probably corrupt. If you had hard drive corruption or damage, that could easily result in recovered files not being fully intact. If you were trying to recover accidentally deleted files, it's possible they might have been partially overwritten before recovering. There are never any guarantees with file recovery.
    Without more information on the circumstances that led you to try recovery, it's hard to give advice on what to try from here. You could always try another file recovery tool, like Data Rescue 3. Just be sure you're taking appropriate precautions when doing recovery. See Recovering deleted files.

  • Insert or Cut Time and move automation data - how to do it?

    Hi when I cut or insert time it moves the regions but not the automation data. I have tried switching nn 'move automation with regions' but it doesn't move the automation that goes past the end f regions eg plug in settings like delay feedbacks etc.
    a) this seems to me to be really crazy - why if you had done a lot of detailed automation programming at the end of a song would you not want it to move if you cut 4 bars from earlier on in the song?
    any ideas appreciated very much!!
    best
    tommy b

    after using logic for years I have discovered a new bit and something very weird.
    New Bit:
    As well as Cut/Insert Time in the Region Menu
    there is a Cut/Insert Time in the Edit menu.
    if I start here:
    http://www.applebananacarrot.com/downloads/pre.jpg
    if I do the region Cut ( from the region menu on the arrange window):
    look what happens to the automation data on track 21
    http://www.applebananacarrot.com/downloads/postregioncut.jpg (track 21 data didn't move)
    and compare it to this one doing everything else the same but using the Cut from the main logic edit menu.
    http://www.applebananacarrot.com/downloads/posteditcut.jpg Track 21 automation data did move.
    That to me seems wrong....
    whaddya think?
    best
    tommy banana

  • Unable to do the (CCR in APO) comparison/reconciliation of transaction data PO and PR in APO

    Hi Gurus,
    Unable to do the (CCR in APO) comparison/reconciliation of transaction data PO and PR in APO Due to the error 181-Schedule line does not exist in APO ,Error code 182-Schedule line without external number does not exist in R/3.
    kindly suggest me ,what we need to do corrective action from ECC side and APO side.
    Regards,
    Babu

    Hi Babu,
    First make sure that order is not set with deletion flag, you can check some random orders for this.
    Steps to be followed:
    1) for all entries with error "181-Schedule line does not exist in APO" click on "Send to APO". similarly for entries with error "182-Schedule line without external number does not exist in R/3" click on "Send to R/3", most likely this type of issue get resolved with this step only, if not.
    2) Next you need to go to transaction code /n/sapapo/cq, check what all messages you are getting there. Correct the error if you are able to understand it from here i.e. rfc connection is not set, no active IM exists etc..
    3) In case you are not able to understand or correct the issue from CQ, then you need to go and check in transaction code CFG1 in ECC, and /n/sapapo/c3 in APO, check in ECC with object CIF and log class "only very important logs".
    In APO object "CIFSCM" and log class "only very important logs".
    Most probably you will be able to get exact or directional reason of the issue.
    Hope this helps.
    Rgds
    Sourabh

  • Open and move files follow by date

    How do I open files follow by date for button 1 and move the files follow by date for button 2?
    Thanks

    Try something like this
    Imports System.IO
    Public Class Form1
    Const oldFolder As String = "c:\temp"
    Const newFolder As String = "c:\temp1"
    Dim count As Integer = 0
    Dim oldFiles As String()
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    'open follow by the file names
    If count < oldFolder.Count Then
    Dim ps2 As Process = Process.Start(oldFiles(count))
    count += 1
    End If
    End Sub
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
    'get files
    Dim info As New DirectoryInfo(oldFolder)
    oldFiles = info.GetFiles("*.jpg").AsEnumerable() _
    .OrderBy(Function(x) x.LastWriteTime) _
    .Where(Function(x) x.LastWriteTime.Date = Now.Date) _
    .Select(Function(x) x.FullName).ToArray()
    count = 0
    End Sub
    End Class
    jdweng
    Joel, there are nothing happen after run your codes
    Imports System.IO
    Public Class Form1
    Const oldFolder As String = "C:\Users\hwai\Desktop\Capture"
    Const newFolder As String = "C:\Users\hwai\Desktop\ New folder(3)"
    Dim count As Integer = 0
    Dim oldFiles As String()
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    'get files
    Dim info As New DirectoryInfo(oldFolder)
    oldFiles = info.GetFiles("*.jpg").AsEnumerable() _
    .OrderBy(Function(x) x.LastWriteTime) _
    .Where(Function(x) x.LastWriteTime.Date = Now.Date) _
    .Select(Function(x) x.FullName).ToArray()
    count = 0
    End Sub
    End Class
    Thanks

  • Time "and" Date Comparison

    Hi,
    I am trying to get the difference between two sets of time.
    This also involves a Date comparison because sometimes the times span more than one day.
    Here is an example of what I'm trying to accomplish. I have searched the forum archives but have not yet found time and date comparisons together.
    startRun = "10/26/01 4:30 PM";
    endRun = "10/27/01 7:45PM";
    I want to process these two times and get the difference.
    The result would be:
    totalRunTime = "27 hours 15 minutes";
    I am stumped. Is this type of process even possible? Any help would be grealty appreciated.
    Best,
    Christian Velez
    Senior Software Engineer
    Research Institute of America, Inc.
    [email protected]

    try this ...
            String startRun = "10/26/01 4:30PM";
            String endRun = "10/27/01 7:45PM";
            SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy hh:mma");
            try {
                Date startDate = sdf.parse(startRun);
                Date endDate = sdf.parse(endRun);
                System.out.println("Start date/time = " + startDate);
                System.out.println("End   date/time = " + endDate);
                long differenceInMillis = endDate.getTime() - startDate.getTime();
                long differenceInSecs = differenceInMillis / (1000);
                long differenceInMins = differenceInMillis / (1000 * 60);
                long differenceInHours = differenceInMillis / (1000 * 60 * 60);
                System.out.println("Millis = " + differenceInMillis);
                System.out.println("Seconds = " + differenceInSecs);
                System.out.println("Minutes = " + differenceInMins);
                System.out.println("Hours   = " + differenceInHours);
                //What you want
                System.out.println("Total run time = "
                    + differenceInHours + " hours "
                    + (differenceInMins % 60) + " minutes");
            } catch (ParseException pe) {
            }

  • Regarding  DATA and MOVE statments with respect to performance

    Hi All ,
       I have a small clarification regarding using the DATA and MOVE  statements in  WEBDYNPRO ABAP /ABAP .
    *Is there any differnce between below declaration regarding performance.
    =========================================================================
    DATA lv_num1 type i.
    DATA lv_num2 type i.
    DATA : lv_num1 type i,
           lv_num2 type i.
    ===================================================================
    MOVE lv_num1 to lv_num2.
    MOVE lv_num2 to lv_num3.
    MOVE : lv_num1 to lv_num2 ,
           lv_num2 to lv_num3.
    thanks
    cb
    Moderator message: please try yourself and search for available information before asking.
    Please Read before Posting in the Performance and Tuning Forum
    locked by: Thomas Zloch on Aug 11, 2010 2:45 PM

    Hi  Preyansh ,
    thanks a lot for your reply,
    but are you sure about the "
    Hence if we write without chin statement it would be fater for compiler to execute the code.
    (same applies for MOVE statement as well)
    i have to give some analysis of an application .that is why i am concern over this.
    Regads
    CB

  • Question on How to Use LI and NP Data Comparison Report

    Hi,
    We are trying to figure out how to make the Transaction Code PC00_M42_LLPD (LI and NP Data Comparison Report) work. What file type (.xls, .txt, etc) should be used?  Anyone who is familiar with the transaction, please help.
    Best Regards,
    Bry

    Somewhere in the Oracle 8.0 documentation it is stated that one
    enviroment per each thread is required if I want to ensure
    complete concurrency of different threads accessing databases.
    But isn't this a waste of resources since only Handle Alloc &
    Free functions use Enviroment handle, hence they should be
    mutexed for access from concurrent threads.
    But the most time-consuming functions are ServerAttach &
    SessionBegin which shouldn't be mutexed since they have each
    their own Server/Session handle.
    So my question is if a single OCI Enviroment is enough for the
    most demanding tasks or should I create one enviroment per
    thread?
    Most folks are happy with a single environment. The mutex on the
    env handle is only taken when the OCI library is allocating some
    memory for internal operations.
    Tomislav.

Maybe you are looking for

  • Adding Credit Notes with reference to Invoice

    Hi Experts, B1 Version: 2007 PL: 41 Im having a difficulty posting a CreditNote with reference to an Invoice. For example I have an Invoice with 3 line items, and this customer returned 1 material. How do I post this Credit Note with only 1 material

  • Bookmark from Forms 11g

    Hello Seniors, I want to call microsoft word with all bookmark from forms 10g. (we have Visual basic application with word template ,all word template have bookmark and we want to call all bookmark directly from forms 10g). I am able to call microsof

  • Can I now delete/uninstall Logic Pro 9 safely now that I have Logic Pro X?

    Is it ok to delete the application Logic Pro 9 now that X is installed without affecting anything?

  • Problem with Illustrator CS5

    I am using Illustrator CS5 on a server, while creating a four layer piece of artwork I have suddenly found that I cannot edit anything, the direct selection tool cannot find a handle or a bezier at all.even in outline view I can see everything in its

  • How do I activate the 3G

    How do I activate the 3G on my new Iphone??