Results 1 to 13 of 13
  1. #1
    drakula941 is offline Member
    Join Date
    Nov 2011
    Posts
    23
    Rep Power
    0

    Lightbulb A new attemp to Sorting and Searching

    I have recently done this code,can any one here just tell me whether this is something new and good? or has something similar or same has already been done.
    Java Code:
    class sort_search
    {
        public static void main(String arg[])
        {
            Random r = new Random();
            int[] x = new int[99999999];
            for (int i = 0; i < x.length; i++) {
                x[i] = r.nextInt(99999);
            }
            int largest=x[0];
            for(int q=0; q<x.length; q++){
                if(x[q]>largest){
                    largest = x[q];
                }
            }
            //--------X----DO NOT BOTHER MUCH TILL HERR----X-------- 
            //SORTING
            int arr[]=new int[largest+1];
            long startTime = System.currentTimeMillis();
            for(int i=0;i<x.length;i++)
            {
                arr[x[i]]++;
            }
            //SEARCHING
            int pos=100;
            if(arr[pos]>0)
                System.out.println(pos+"*"+arr[x[pos]]);
            else
                System.out.println("Search not found");
            long endTime = System.currentTimeMillis();
            System.out.println("Time Taken "+(endTime-startTime));
        }
    }
    please share your opinions!!!

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,302
    Blog Entries
    7
    Rep Power
    20

    Default Re: A new attemp to Sorting and Searching

    So for a two element array { 1, 99999999 } you need a 99999999 element auxiliary array to increase the search speed by 50% at best ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    drakula941 is offline Member
    Join Date
    Nov 2011
    Posts
    23
    Rep Power
    0

    Default Re: A new attemp to Sorting and Searching

    the aux array structure will be same as the originall array structure. :) so what would you conclude sir? is it good and new?(interms of time efficiency only)
    Last edited by drakula941; 09-18-2012 at 09:43 PM.

  4. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,302
    Blog Entries
    7
    Rep Power
    20

    Default Re: A new attemp to Sorting and Searching

    Quote Originally Posted by drakula941 View Post
    the aux array structure will be same as the originall array structure. :) so what would you conclude sir? is it good and new?(interms of time efficiency only)
    In line #18 of your code you create a new array proportional to the largest element in your original array, so (given my example) you create an array of size 99999999 for an original array with 2 elements.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    drakula941 is offline Member
    Join Date
    Nov 2011
    Posts
    23
    Rep Power
    0

    Default Re: A new attemp to Sorting and Searching

    Quote Originally Posted by JosAH View Post
    In line #18 of your code you create a new array proportional to the largest element in your original array, so (given my example) you create an array of size 99999999 for an original array with 2 elements.

    kind regards,

    Jos
    So.. you are suggesting me to create a multi dimensional array? like "[2][99999999]" this?

  6. #6
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,302
    Blog Entries
    7
    Rep Power
    20

    Default Re: A new attemp to Sorting and Searching

    Quote Originally Posted by drakula941 View Post
    So.. you are suggesting me to create a multi dimensional array? like "[2][99999999]" this?
    Nope, I didn't suggest anything.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    drakula941 is offline Member
    Join Date
    Nov 2011
    Posts
    23
    Rep Power
    0

    Default Re: A new attemp to Sorting and Searching

    Quote Originally Posted by JosAH View Post
    so (given my example) you create an array of size 99999999 for an original array with 2 elements.

    kind regards,

    Jos
    so what exactly do you mean by this? please explain properly. :) and please do conlude whether it is new and good or not,with a reason. :)

  8. #8
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,302
    Blog Entries
    7
    Rep Power
    20

    Default Re: A new attemp to Sorting and Searching

    Quote Originally Posted by drakula941 View Post
    so what exactly do you mean by this? please explain properly. :) and please do conlude whether it is new and good or not,with a reason. :)
    I already gave you the reason and your approach is not new and it's only 'good' if the range of the numbers more or less equals the number of numbers.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  9. #9
    drakula941 is offline Member
    Join Date
    Nov 2011
    Posts
    23
    Rep Power
    0

    Default Re: A new attemp to Sorting and Searching

    Quote Originally Posted by JosAH View Post
    I already gave you the reason and your approach is not new and it's only 'good' if the range of the numbers more or less equals the number of numbers.

    kind regards,

    Jos
    ohk!! thankyou for your review :) can you tell me my approach is similar to which kind of sort or search which already exists? because of which you say its not new. :)

  10. #10
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,302
    Blog Entries
    7
    Rep Power
    20

    Default Re: A new attemp to Sorting and Searching

    Quote Originally Posted by drakula941 View Post
    ohk!! thankyou for your review :) can you tell me my approach is similar to which kind of sort or search which already exists? because of which you say its not new. :)
    It is a form of 'bucket sorting'; Donald Knuth's 'Searching and Sorting' discusses it; it has limited applicability.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  11. #11
    drakula941 is offline Member
    Join Date
    Nov 2011
    Posts
    23
    Rep Power
    0

    Default Re: A new attemp to Sorting and Searching

    Quote Originally Posted by JosAH View Post
    It is a form of 'bucket sorting'; Donald Knuth's 'Searching and Sorting' discusses it; it has limited applicability.

    kind regards,

    Jos
    can you tell me where its application is limited?? so that i can look on too it... :) please give me some good cases where there are limitations. :) I am desperately waiting for a reply to this... to work on the limitations :D

  12. #12
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,302
    Blog Entries
    7
    Rep Power
    20

    Default Re: A new attemp to Sorting and Searching

    I already gave you one of its most severe limitations (see reply #2): if the range of the elements is larger than the number of elements, it needs way too much storage. Your implementations can't handle negative numbers either.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  13. #13
    drakula941 is offline Member
    Join Date
    Nov 2011
    Posts
    23
    Rep Power
    0

    Default Re: A new attemp to Sorting and Searching

    Quote Originally Posted by JosAH View Post
    I already gave you one of its most severe limitations (see reply #2): if the range of the elements is larger than the number of elements, it needs way too much storage. Your implementations can't handle negative numbers either.

    kind regards,

    Jos
    Thanks for that... i will try to work on the negative thing... i doubt the {1,99999999} problem can b solved.. but still ill try to think of some new method and report the solution. :)

Similar Threads

  1. regarding searching in jsp
    By jazz2k8 in forum JavaServer Pages (JSP) and JSTL
    Replies: 4
    Last Post: 04-16-2012, 11:02 AM
  2. sorting and searching
    By Dave013 in forum New To Java
    Replies: 1
    Last Post: 12-09-2011, 12:19 PM
  3. Sorting/Searching Objects with multiple types.
    By gcampton in forum New To Java
    Replies: 20
    Last Post: 10-21-2009, 11:58 PM
  4. Replies: 2
    Last Post: 10-07-2009, 06:24 PM
  5. Replies: 0
    Last Post: 04-14-2008, 08:39 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •