[algogeeks] Re: Lower number

2006-05-26 Thread Sriram narasimhan
Sort the elements initially and then you can logically solve it..i don kno the logic..but do mail me if you get a logic.pls help me i m beginnin to learn computers...   Sriram.N  On 5/19/06, Terry <[EMAIL PROTECTED]> wrote: Hi,If i have an array like {1,4, 10, 15 , 20 , 30 }  of size n , now if iwa

[algogeeks] Re: Lower number

2006-05-25 Thread A S Grewal
I guess there is a slight mistake in the problem statement (or I am misunderstanding it). How can the numbers lie between 1 and n. For example, in the given array this would mean that all elements of the array would be between 1 and 6 ?? --~--~-~--~~~---~--~~ You

[algogeeks] Re: Lower number

2006-05-25 Thread Dhyanesh
Sorry it shud be int *pos = lower_bound(arr, arr + n, x ); x is the element you are searching for -Dhyanesh On 5/25/06, Dhyanesh <[EMAIL PROTECTED]> wrote: > If array is sorted just use STL > > int *pos = lower_bound(arr, arr + n ) ; > print *pos; > > -Dhyanesh > > On 5/21/06, adak <[EMAIL PR

[algogeeks] Re: Lower number

2006-05-25 Thread Dhyanesh
If array is sorted just use STL int *pos = lower_bound(arr, arr + n ) ; print *pos; -Dhyanesh On 5/21/06, adak <[EMAIL PROTECTED]> wrote: > > This is a "normal" binary search. You just need to have it return the > next lower number if a match is not found. > And of course, get rid of the super

[algogeeks] Re: Lower number

2006-05-21 Thread adak
This is a "normal" binary search. You just need to have it return the next lower number if a match is not found. And of course, get rid of the superflous database records. sr[] is the array of student records. /* Number_Search uses a binary search, to search for a record's student number. */ in

[algogeeks] Re: Lower number

2006-05-20 Thread Gene
Terry wrote: > If i have an array like {1,4, 10, 15 , 20 , 30 } of size n , now if i > want to search for number > > 25 , i should get 20 , if i search for number 11 i hould get 10 , if i > search for 4 i should get 4, if i search for a number and it doesn't > exist i should get the lower number

[algogeeks] Re: Lower number

2006-05-20 Thread Terry
Gene wrote: > Terry wrote: > > If i have an array like {1,4, 10, 15 , 20 , 30 } of size n , now if i > > want to search for number > > > > 25 , i should get 20 , if i search for number 11 i hould get 10 , if i > > search for 4 i should get 4, if i search for a number and it doesn't > > exist i s

[algogeeks] Re: Lower number

2006-05-19 Thread manu jose
If we have a temporary variable then the O(n) solution works. On 5/19/06, Karthik Singaram L <[EMAIL PROTECTED] > wrote:Wont this algo have complexity O(n lgn) whereas a simple linear search would have O(n) and it would suffice for the problem -- Manu Jose,mob :09844467453E-mail : [EMAIL PROTECT

[algogeeks] Re: Lower number

2006-05-19 Thread Karthik Singaram L
Wont this algo have complexity O(n lgn) whereas a simple linear search would have O(n) and it would suffice for the problem --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this grou

[algogeeks] Re: Lower number

2006-05-19 Thread manu jose
Quick sort technique. Element to search k. Sort(A, s,e, Key) {    pivot=A[s];    z= partition(A,s,e,pivot); //this will split the array in to two parts in which one part contains elemnents lesser than the pivot and other greater than pivot.    If (

[algogeeks] Re: Lower number

2006-05-19 Thread Deepak Babu
If I understand the problem right, how about going over all the elements of the array and store the largest number less that given number in a temp variable? - o(n) If we can preprocess the i/p - either sort, or store in a BST - (excluding the preprocessing time), we can reach to the solution in o