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 between which it lies. All numbers
> are bound to lie between 1 and n.
>
> Can you tell me a easy way to do it.

If the array is always sorted you can modify a standard binary search
to get job done in O(log n) time.  This looks like homework.

X-Google-Language: ENGLISH,ASCII-7-bit
Received: by 10.11.53.63 with SMTP id b63mr74645cwa;
        Fri, 19 May 2006 19:06:20 -0700 (PDT)
X-Google-Token: b5wVigwAAACc8E5kIeSoDVGLD_0jUMhD
Received: from 70.101.174.178 by j73g2000cwa.googlegroups.com with HTTP;
        Sat, 20 May 2006 02:06:20 +0000 (UTC)
From: "Gene" <[EMAIL PROTECTED]>
To: "Algorithm Geeks" <algogeeks@googlegroups.com>
Subject: Re: Lower number
Date: Sat, 20 May 2006 02:06:20 -0000
Message-ID: <[EMAIL PROTECTED]>
In-Reply-To: <[EMAIL PROTECTED]>
References: <[EMAIL PROTECTED]>
User-Agent: G2/0.2
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET 
CLR 1.1.4322),gzip(gfe),gzip(gfe)
Mime-Version: 1.0
Content-Type: text/plain

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 between which it lies. All numbers
> are bound to lie between 1 and n.
>
> Can you tell me a easy way to do it.

If the array is always sorted you can modify a standard binary search
to get job done in O(log n) time.  This looks like homework.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---

Reply via email to