Fastest sorting algorithm for an array of less than 10 elements

is it insert sort good enough? or it just doesn't matter here given the size of the array is too small? Thanks.

Arrays.sort()

Similar Messages

  • Condition for excluding Sales value less than or equal to 0

    Hello Experts,
    I have to create condition in the query designer to exclude Sales Value <=0, and that should be applied to all the column values and result values when we put active.
    Can anyone help ?
    Thanks in advance,
    Venky
    Duplicate Post
    Condition for excluding Sales value less than or equal to 0
    Edited by: Arun Varadarajan on Apr 13, 2010 8:57 PM

    Hello Naveen,
    Thanks for quick reply. I have created condition greater than zero and executed report, i can able to eliminate rows with sales value <=0, but we have other columns in the report say Quantity, Backlog... when we run the report without condition the values which showed are same when we put it in active aslo.
    After eliminating few rows which having some quantity value, that value should be deducted from the result of the quantity. I tried with applying apply to results opton, then also there is no change in the result value of the quantity.
    Our requirement is to apply condition to eliminate rows which are sales value <=0 and same the result values of the columns should effect.
    Is it possible in anyway, if yes please specify solution.
    Thanks,
    Venky

  • Is it possible for an Array to have zero element??

    As the subject stated, is it possible for an Array to have zero element apart from being null??
    because if I dont assign an Array to any amount of elements, the Array is always null. And, that is the reason why I never see Array.length being zero.
    Any body can explain??

    As the subject stated, is it possible for an Array to
    have zero element apart from being null??Well, let's see. new int[1] creates an array with one element, so if it IS possible to have an array with zero elements, how do you suppose you'd do that?
    Okay, right.
    Now, what happened when you put that into a .java file and compiled it?
    because if I dont assign an Array to any amount of
    elements, the Array is always null.If you don't assign a reference to an array to your array variable, (i.e. myArr = ... then it will be null (if it's a member variable, but undefined if it's a local).
    But null and empty are not the same thing. Remember, there's your variable, and there's the array it points to.
    Why do you think that the array it points to must have >= 1 elements?
    I'm not saying it's okay to have zero elemnts. And I'm not saying it's not.
    I'm asking you to examine your logic for why you think zero elements is not possible (said logic is faulty). And then I'm asking you to do an experiment to test your theory.
    And, that is the
    reason why I never see Array.length being zero.If you never see array.length being zero, it's because none of the arrays you looked at had zero elments. That doesn't tell you that arrays can't have zero elements.
    So far, you have neither theory nor observations to support either view.

  • Sort algorithm for LARGE amount of data?

    hi,
    i need a sorting scheme for the following situation:
    I have a data file where entries are in chunks of variable length. The size of each
    chunk is defined in the first 5 bytes as a string, so the length can be from
    00001-99999, though it is usually around 1000-3000 bytes long. In reality it is never
    over 10000 bytes, but it is possible for it to be.
    Anyways, I need to sort these files according to the data found in certain
    displacements in these chunks. I will be sorting anywhere from 200,000 to
    100,000,000 at a time. Time is an issue certainly, but if it takes a week to finish that is
    fine, i just need it to work.
    So, my problem is that none of the typical sorts will work for me (bubble, heap) as far
    as i can tell because in those sorts i need to have the data loaded into memory, and
    this much data will overload the system. I have used, in the past, a c method that
    feeds these chunks to the sort function a few at a time, then makes files. Hence, not
    all chunks need to be loaded at once. Does anyone know of any solution to this
    problem? Any sort algorithms or sort classes that can handle this much data? thanks!

    Ever tried the radix sort? it's got linear complexity.
    You can still work a chunk at a time, and simply separate the data into several different "buckets", each one identified by, oh, say, the unicode number for the first character in the chunk.
    You now have several smaller lists to sort, and when you're done, NO MERGING IS NECESSARY. Simply append the lists, because the main sets of lists are already sifted into different "buckets".
    Kinda like this:
    create 256 files, and store in each every record that contains a first character that corresponds to it's ascii value. Then create 256 files for each of the original 256 files, and store in each every recond that contains a second character that correstonds to it's second character.
    etc, etc, etc.
    This is very memery intensive for storage, but in terms of run time complexity, it is linear: You will make an explicit number of passes through the list of data. And, as you go along, the lists get shorter and shorter. So while it appears that you are making 256 ^ (max length of data) passes, you're really only making (max length of data) passes, with some additional overhead of creating extra multiple files.
    For that much data, I would definitely recommend a linear algorithm. Any other sorts would be extremely slow.

  • Ms Project 2013 report for resource name, tasks less than 100% complete within a date range I can set each time

    I have seen I can create a report for a resource name with a specified date range, and one that can show me for a resource name any incomplete tasks, but I want to do the following and cant work out how to state it in the report constructor:
    resource name equals - {I want to set a given resource in here}
    % complete is less than 100%
    start - date range is between [today -7 days] and [today +7 days]
    Please can someone show me how this is possible, I know it will be and it is me that has been defeated!!

    workspacedesign,
    Oops, my bad. I missed the point that the Name field for assignment rows will be the task name and that's not what you want. There is also a glitch in the date range filter. So, here's how to fix that.
    First, in the Resource Usage view, copy the Name field to Text1. Now select the resource line and do a fill down for all assignments under that resource. Do that for each resource. This could be automated with VBA, but for now, a manual setup should work
    fine.
    Second, instead of testing for the Name field in the filter, test for the Text1 field.
    Third, change the Finish test to be "less than or equal to".
    Now when you apply that filter, enter beginning date of your range and then the ending date of your range followed by the resource name. You should get the data you want.
    Unfortunately formulas in custom fields are not as flexible in Project as they are in Excel. For example, in Project a formula can only operate on data for that row. Further, even if you use the formula Today() +7 for your filter criteria, the first time
    the filter is used, Project will hard code today's date into the filter. The normal way around both of these shortcomings is to use VBA.
    Hope this helps.
    John

  • Validation for posting date is less than 7 days of current date

    Hi
    I want to create a validation wherein  system will validate every entry that whether posting date is less than 7 days of current date. If it is than check in a set is that user id available if not than show error message.
    If someone have any idea on this logic pls share with me.
    Regd
    Shiv

    Hi,
    That's certainly possible via usual OB28 validation. Define your prerequisites for the posting date (you will have to do it via user-exit (bkpf-budat greater then sy-datum less 7 days) , and check whether the user is in the set.
    Regards,
    Eli

  • Sorting Methods for an Array

    I'm trying to sort an object array of bank accounts based on their balance. JGRASP doesn't like my calling statement, which I don't think is correct.
    My question is am I calling the method correctly (trying to set the bankArray[counter].getBalance()) and am I using the sort method correctly?
    my call method
    bankArray = bankArray[counter].selectionSort(bankArray[counter].getBalance(), counter);My sort method:
    public static void selectionSort (double [] sort, int length)
    for (int i = length; i < 1; i--)
    double currentMax;
    int currentMaxIndex;
    currentMax = sort[0];
    currentMaxIndex = 0;
    for (int j = 1; j < i; j++)
    if (currentMax < sort[j])
    currentMax = sort[j];
    currentMaxIndex = j;
    }//End if
    }//End for

    There are some points to notice:
    Point 1: Your method receive an array of double and an int, as you passing a double and an int.
    Point 2: Your algorithm doesn't work properly. First of all, the selection sort works by selecting the smallest unsorted item remaining in the list, and then swapping it with the item in the next position to be filled. Also, note that you don't swap the array elements in any moment.
    Point 3: In Java, your selectionSort method don't need to receive a parameter to inform the array length. The array itself already have that information ("myArray.length").
    Point 4: About the call of your method, you made it as the selectionSort method returns an array of BankAccounts - Supposing that you represent a bank account through an BankAccount class and bankArray[i] is an array of [i]BankAccount objects. It's not true. As you can see, your selectionSort method returns void, or either, returns nothing.
    Observing those 4 first points, we can re-write your selectionSort method like this
         public static void selectionSort(double[] numbers) {
                for (int i = 0; i < numbers.length - 1; i++)
                  int minIndex = i;
                  for (int j = i + 1; j < numbers.length; j++)
                    if (numbers[j] < numbers[minIndex])
                      minIndex = j;
                  double temp = numbers;
              numbers[i] = numbers[minIndex];
              numbers[minIndex] = temp;
    Now, when I try to re-write the call, I noticed other important odd thing about your approach: The [i]selectionSort method was written to sort bankAccounts, but it receives an array of double values. Being thus, you must to previously create a double[] object filled with the accounts' balances and then sort it. But, once sorted, how can you return the balances to their proper account? There is no way to do it. You have to sort a bunch of BankAccount objects, instead of an array of balances...
    An intuitive implementation of this sorting cound be something like that:     public static void selectionSort(BankAccount[] accounts) {
              for (int i = 0; i < accounts.length - 1; i++) {
                   int minIndex = i;
                   for (int j = i + 1; j < accounts.length; j++) {
                        double
                             currBalance = accounts[j].getBalance(),
                             minBalance = accounts[minIndex].getBalance()                    
                        if (currBalance < minBalance)
                             minIndex = j;
                   BankAccount temp = accounts;
                   accounts[i] = accounts[minIndex];
                   accounts[minIndex] = temp;
    I noticed form your call that the [i]selectionSort method boleng to the BankAccount class. Once this method is static, It's strongly recomended that you invoke this method in a static way (from the class, instead of from an object).
    Here it goes a fictional BankAccount class and a TestBankAccount class. Read it, Run it, Study it, Understand it.
    package help.sun.imbrium;
    public class BankAccount {
         private double balance;
         private int number;
         public static void selectionSort(BankAccount[] accounts) {
              for (int i = 0; i < accounts.length - 1; i++) {
                   int minIndex = i;
                   for (int j = i + 1; j < accounts.length; j++) {
                        double
                             currBalance = accounts[j].getBalance(),
                             minBalance = accounts[minIndex].getBalance()                    
                        if (currBalance < minBalance)
                             minIndex = j;
                   BankAccount temp = accounts;
                   accounts[i] = accounts[minIndex];
                   accounts[minIndex] = temp;
         public BankAccount(int number, double balance) {
              this.balance = balance;
              this.number = number;
         public double getBalance() {
              return balance;
         public void setBalance(double balance) {
              this.balance = balance;
         public int getNumber() {
              return number;
         public void setNumber(int number) {
              this.number = number;
         public String toString(){
              return "[Account #" + number + " balance: $" + balance + "]";
    class TestBankAccount{
         public static void main(String[] args) {
              BankAccount[] accounts = {
                   new BankAccount(1, 154.23),
                   new BankAccount(2, 1554.23),
                   new BankAccount(3, 15.3),
                   new BankAccount(4, 854),
                   new BankAccount(5, -4.79),
              System.out.println("Unsorted:\n\t" + arrayToString(accounts, " "));
              BankAccount.selectionSort(accounts);
              System.out.println("Sorted:\n\t" + arrayToString(accounts, " "));
         private static String arrayToString(Object[] objs, String separator){
              StringBuilder sb = new StringBuilder();
              for (int i = 0; i < objs.length; i++) {
                   Object obj = objs[i];
                   sb.append(obj.toString());
                   if(i < objs.length - 1)
                        sb.append(separator);
              return sb.toString();

  • Sorting algorithm for search

    This is just my opinion, but the sorting of packages after searching, in AUR or the home page of Arch, seems unintuitive.  Personally, I think if the keyword matches part of a package name, that package should be at the top.  Then the results should be sorted according to how well the keyword matches the package description.  Finally, in the case of AUR, packages should be sorted according to the number of votes in descending order.  Just my opinion.

    you can get it to do votes in descending using the "sort by" option on your search. The rest I agree with to an extent, but perhaps a more advanced search page is needed, where one could search specific fields only.

  • Installation stuck now for four hours at "less than one minute remaining"

    I've seen this occasionally, but using a full OS X installer, I've now been stuck at the&lt;1 minute mark for several hours. I'm going to give it through the night, but I've often not seen this resolve. Should I continue?

    Press and hold the power button for a few seconds until the power shuts off, then release, wait a few more seconds, and press it again briefly to restart.

  • No refund for Mainstage 2 bought less than 30 days ago

    It's with major disappointment that I've received this answer from apple:
    "after reviewing the circumstances of your case, we determined that issuing you a refund for your unintentional purchase of "MainStage" is an appropriate exception to the iTunes Store Terms and Conditions, which state that all sales are final"
    so the "rule" read here in the community for which everyone is receiveing a refund if they bought Logic 9 or Mainstage 2 in the last 30 days is not true.
    Just to clarify I bought my Mainstage 10 days ago.

    my bad it seems that first part of email is standard and after I received the refund notification.
    So it seems (I've asked to clarify) that I'll receive the refund.

  • Paying for 10Mbps but getting less than 5Mbps since October

    My last post was about a constant disconnection issue which has kind of been fixed, meaning that it probably happens once or twice a day night and mostly during night time after 8PM PST. Tiny bit of progress, but not entirely remedied.
    That started back in Octorber, took a month and a lot of effort on my end trying to get Verizon's attention for that to be checked out, yet it's not 100% fixed. But since then my speeds have dropped below 5Mbps down, 540Kbps up. I used to be getting 9.3Mbps/860Kbps, from 2007 to 2009, two flawless years before the speeds began to gradually decrease in 2010, approximately 1~2% every 6 months or so, until the speeds became stuck at 7.3Mbps/728Kbps. Every Verizon agent I spoke to told me that my line is only good for up to 7.1Mbps so I'm actually getting more than I should. Do you even know how ridiculous that sounds? I'm only 1.7mile away from the Verizon station, and that does not lower my speeds that much. So why should I pay $60 for a 10Mbps enhanced package that gets me nowhere near 10Mbps? And how did I have speeds close to the advertised specs in the first place?
    Here's what I think. ASSIA Optimizer is just a sugar-coated name for "Bandwidth Throttling". It detects and measures the bandwidth usage of each line and if the load is higher than the pre-determined parameters it throttles the bandwidth and lowers the speeds, and Verizon has made sure that it's extremely difficult for any user to get some real support, and their employees have been told to avoid acknowledging the existence of "ASSIA Optimizer" as well as "Speed Profiles". Yea, Verizon agents told me that these things do not exist.
    I've lost count of how many tickets I've had all of which did absolutely nothing, but my speeds just keep getting worse with each call I make to Verizon support. As of now I am getting 2.06Mbps/460Kbps. And I've been paying $60 a month why??
    If you have a choice in your area, steer clear of Verizon, because you will never get any real support.

    Hi Crimsonite,
    We have reopened your Private Support Case. Please access your case through your profile page by following the instructions posted earlier.

  • Is CS3 better for working with RAW images than Elements 6?

    Hi all,
    I am trying to find out if it is worth buying CS3 in stead of elements 6. Surprisingly, nobody has been able to tell me what the difference exactly is.
    The best I got so far was that elements is a trimmed down version of CS3 but what more can I do with CS3?
    As I am in England, CS3 would cost me about $1100, as opposed to $650 in the US, which is a bit much if you don’t know exactly what you get for that amount.
    It says something on the adobe features section about BETTER raw processing, but not compared to what. Old version? Other software? Better than nothing?
    I will be running it under XP, and the only use will be to optimise images from a digital camera in RAW format, 90%, and a jpeg (10)%, partially for web use, partially for prints.
    The most common things are:
    Correcting exposure when pics are unevenly lit.
    Correcting color temperature.
    Removing unwanted parts of a picture e.g. somebody stepping into the picture, advertising signs or copyrighted material.
    Altering color of small parts of an image like that of a single flower in a bouquet.
    Removing blemishes in portraits.
    The photos will always stay single photos, I can not foresee any use for slide shows, animations, video or anything related.
    From what I have been able to find out so far, it seems that Elements 6 will do all this and I don’t need to spend the extra $1000, or should I?

    I have not used Photoshop Elements since version 2.0. In that version it was very similar to Photoshop as far as how the interface was designed. There were a few key elements that were missing such as the Curve adjustment. It is my understanding that there is a free download available from a third party source that will provide that capability.
    As far as Camera Raw is concerned, you only have the adjustments that are on the basic panel and the details panel. That means you don't have all of the hue/saturation/luminance adjustments, or lens correction, or the capability to create presets, or to calibrate ACR specifically for your camera. As I understand it, it is not possible to load multiple images into ACR so that you can apply changes to all of them at once. And I don't believe you have the option of working in ACR in 16-bit mode.
    With Photoshop Elements it is not possible to record actions to enable you to do batch processing of your images. What you have is a good quality basic single image photo editor.
    I cannot tell you which to purchase. I don't know what you are accustomed to, nor do I fully understand your expectations. There are trial versions of both programs that you can download and try for 30 days to see what you think. They are fully functioning programs for that trial period, which should be ample time for you to determine which program will give you the most value.

  • Radix sort algorithm

    You guys, I need a radix sort algorithm for java. I've worked on it for a while, and I cant get it. I have this so far:
    public void radixSort(int maxDigits)
              Vector temp = new Vector();
              int count = 1;
              while(count<(Math.pow(10,maxDigits)))
                   int c=0;
                   while(c<10)
                        for(int i=0;i<students.size();i++)
                             int per = ((MyStudent)students.elementAt(i)).getPercentage()/count;                         
                             if(per%10==count)
                                  temp.add((MyStudent)students.elementAt(i));
                        c++;
                   count*=10;
              students = temp;
    students is the main vector in the class, and percentage is the thing we are trying to sort. The accessor for percentage is (MyStudent)students.elementAt(i).getPercentage(). It has to be cast to (MyStudent) object.

    Sorry here is a formatted version of my question:
    You guys, I need a radix sort algorithm for java. I've worked on it for a while, and I cant get it. I have this so far:
    public void radixSort(int maxDigits)
              Vector temp = new Vector();
              int count = 1;
              while(count<(Math.pow(10,maxDigits)))
                   int c=0;
                   while(c<10)
                        for(int i=0;i<students.size();i++)
                             int per = ((MyStudent)students.elementAt(i)).getPercentage()/count;                         
                             if(per%10==count)
                                  temp.add((MyStudent)students.elementAt(i));
                        c++;
                   count*=10;
              students = temp;
         }students is the main vector in the class, and percentage is the thing we are trying to sort. The accessor for percentage is (MyStudent)students.elementAt(i).getPercentage(). It has to be cast to (MyStudent) object.

  • Would this sorting algorithm work?

    I'm writing a sorting algorithm for a class that implements the Comparable interface. The class (called Memo) has a field, 'entryDate' of type 'Date', which itself has int fields for day, month, and year. I want to have the class sorted by date, earliest to latest, and then (for entries on the same day) by 'priority' (a field of type int; can be 1, 2 or 3).
    The one I've written seems to work based on a few tests, but I just want to make sure it will work all the time:
    (btw, i have to use the 'getEntryDate()' method because entryDate is a private field in the Memo class' superclass.
    public int compareTo(Memo memo)
    int comparison = getEntryDate().getYear() - memo.getEntryDate().getYear();
    if(comparison != 0) {
    return comparison;
    comparison = getEntryDate().getMonth() - memo.getEntryDate().getMonth();
    if(comparison != 0) {
    return comparison;
    comparison = getEntryDate().getDay() - memo.getEntryDate().getDay();
    if(comparison != 0) {
    return comparison;
    return priority - memo.priority;
    }

    Generally when you simply subtract one int value from another in the compareTo() method, you'll have to take care that you don't run into an overflow situation (because comparing Integer.MIN_VALUE and (Integer.MIN_VALUE-1) would result in unpleasant surprises otherwise). But in your case you can probably safely assume that all your values are well within the safe range for int.
    Also: If you have the chance to modify the Date chance I'd simply make the Date implement Comparable<Date> and delegate that comparison to the Date class.
    Also: are two Memos at the same date with the same priority considered equal? Don't they have any other fields? It's important that objects that are not equals (i.e. a.equals(b) returns false) don't compare to be the same (i.e. a.compareTo(b) should only return 0 iff a.equals(b) returns true). Otherwise you might run into situations where objects are silently dropped because some Collection classes consider them to be equal (SortedSet implementations are tricky here).

  • Restrict the LONG RAW Column with less than 32760 bytes in the SELECT

    When i am trying to access a LONG RAW Dataype wchich has characters greter than 32760 bytes i am getting this error.
    Error -6502: ORA-06502: PL/SQL: numeric or value error
    I came to know that PL/SQL will only be able to access the first 32760 bytes of a LONG RAW. If we try to fetch a LONG RAW from the database into PL/SQL variable which exceeds the 32760 byte limit then we encountered the above error.
    Can anyone tell to avoid this error can we write a query to restrict the output to get only those records which has LONG RAW length less than 32760 bytes.
    Since we canot use utl_raw.length() in the Select Statement, is there any function to restrict the the records for less than 32760 Bytes only for LONG RAW datatype, so that i will not get any records for more than 32760 bytes and we will not get this error.
    REquest you to please help.

    Hi
    we do not have an option of migrating the LONG RAW to BLOB or any kind of ALTER to the table.
    We want to restrict the use of Records from the Table which has data for LONG RAW column less than 32760 bytes, so that we will not get the PL/SQL numberic Error
    any function for LONG RAW that can be used in SQL like for varchar2 we can use
    select length(NAME) < 100 from tb_emp+
    i.e it will get records only which has NAME less than 100 characters.

Maybe you are looking for