# Thread: A new attemp to Sorting and Searching

1. Member
Join Date
Nov 2011
Posts
23
Rep Power
0

## 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
long endTime = System.currentTimeMillis();
System.out.println("Time Taken "+(endTime-startTime));
}
}```

2. ## 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

3. Member
Join Date
Nov 2011
Posts
23
Rep Power
0

## 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. ## Re: A new attemp to Sorting and Searching

Originally Posted by drakula941
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

5. Member
Join Date
Nov 2011
Posts
23
Rep Power
0

## Re: A new attemp to Sorting and Searching

Originally Posted by JosAH
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. ## Re: A new attemp to Sorting and Searching

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

kind regards,

Jos

7. Member
Join Date
Nov 2011
Posts
23
Rep Power
0

## Re: A new attemp to Sorting and Searching

Originally Posted by JosAH
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. ## Re: A new attemp to Sorting and Searching

Originally Posted by drakula941
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

9. Member
Join Date
Nov 2011
Posts
23
Rep Power
0

## Re: A new attemp to Sorting and Searching

Originally Posted by JosAH
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. ## Re: A new attemp to Sorting and Searching

Originally Posted by drakula941
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

11. Member
Join Date
Nov 2011
Posts
23
Rep Power
0

## Re: A new attemp to Sorting and Searching

Originally Posted by JosAH
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. ## 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

13. Member
Join Date
Nov 2011
Posts
23
Rep Power
0

## Re: A new attemp to Sorting and Searching

Originally Posted by JosAH
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. :)

#### Posting Permissions

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