Results 1 to 13 of 13
- 09-18-2012, 08:49 PM #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.
please share your opinions!!!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)); } }
- 09-18-2012, 09:25 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,400
- Blog Entries
- 7
- Rep Power
- 17
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,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 09-18-2012, 09:35 PM #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.
- 09-19-2012, 06:51 AM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,400
- Blog Entries
- 7
- Rep Power
- 17
Re: A new attemp to Sorting and Searching
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 09-19-2012, 11:03 AM #5
Member
- Join Date
- Nov 2011
- Posts
- 23
- Rep Power
- 0
- 09-19-2012, 12:56 PM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,400
- Blog Entries
- 7
- Rep Power
- 17
- 09-19-2012, 01:41 PM #7
Member
- Join Date
- Nov 2011
- Posts
- 23
- Rep Power
- 0
- 09-19-2012, 03:24 PM #8
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,400
- Blog Entries
- 7
- Rep Power
- 17
Re: A new attemp to Sorting and Searching
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 09-19-2012, 03:37 PM #9
Member
- Join Date
- Nov 2011
- Posts
- 23
- Rep Power
- 0
- 09-19-2012, 04:44 PM #10
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,400
- Blog Entries
- 7
- Rep Power
- 17
- 09-19-2012, 07:05 PM #11
Member
- Join Date
- Nov 2011
- Posts
- 23
- Rep Power
- 0
- 09-19-2012, 09:05 PM #12
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,400
- Blog Entries
- 7
- Rep Power
- 17
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,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 09-20-2012, 02:13 PM #13
Member
- Join Date
- Nov 2011
- Posts
- 23
- Rep Power
- 0
Similar Threads
-
regarding searching in jsp
By jazz2k8 in forum JavaServer Pages (JSP) and JSTLReplies: 4Last Post: 04-16-2012, 11:02 AM -
sorting and searching
By Dave013 in forum New To JavaReplies: 1Last Post: 12-09-2011, 12:19 PM -
Sorting/Searching Objects with multiple types.
By gcampton in forum New To JavaReplies: 20Last Post: 10-21-2009, 11:58 PM -
Having trouble insert/sorting array values w/ binary searching.
By bh-chobo in forum New To JavaReplies: 2Last Post: 10-07-2009, 06:24 PM -
Sorting, Searching, and Inserting into a sorted array
By Java Tip in forum java.langReplies: 0Last Post: 04-14-2008, 08:39 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks