Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

U have an array of +ve integers arranged in the descending
order . Write a functionb thast take an integer & an integer
array as an integer and returns the position of the given
integer in the array , if the integer is not present in the
array it should return -1 . the serching technique that u
use should be very efficient both in terms of time & memory.

Answer Posted / siddarth pillai

public class Test
{
public static void main(String args[])
{
int[] arr = {99,56,31,22,17,11,9,2};
int no=11;

int position = checkPos(arr,no);

if(position == -1)
System.out.println("No such number exists in the array.");
else
System.out.println("Number "+no+" is at position "+position);
}
public static int checkPos(int[] arr,int no)
{
int first = 0;
int last = arr.length;
int mid = (first+last)/2;
int LoopCount = 0;
int MaxLoopCount = arr.length/2;

System.out.println("first : "+first+" last : "+last+" mid : "+mid);

while((arr[mid]!=no) && (LoopCount<MaxLoopCount))
{
if(no>arr[mid])
{
first = 0;
last = mid;
mid =(first+last)/2;
System.out.println("first : "+first+" last : "+last+" mid : "+mid);
}
else if(no<arr[mid])
{
last=arr.length;
first = mid;
mid =(first+last)/2;
System.out.println("first : "+first+" last : "+last+" mid : "+mid);
}
LoopCount++;

}
if(no == arr[mid])
return mid;
else
return -1;

}
}

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

what is hashing and what are the various techniques of hashing?

1938


how to decrease the rate of material?

2031


which type of questions r asked in icici po interview?

2016


similarly boy propose girl but in this case girl propose boy?

1554


mention some of the major contribution made by you in present & previous jobs- Sales Representative

2084


What is differant about upload as opposed to download?

2050


hello everyone myself sumit doing b.com final please tell me various exams ,their procedure and qualification for getting jobs in excise,custom and taxtion field.

2026


hi friends, i completed MCA and searching for software jobs. but i cleared SBI clerical written and called for interview. at this time what is better? joining as clerk in SBI or to wait for some time and getting a job as a s/w engg ? please suggest me. will there be career growth in SBI?

2039


Hire Purchase System and Installments System.

1906


how to print the most continuously repeated character in a string?

2048


Order Management Questions on the Oracle applications. ================================================= A)Explain the basic flow of Order Management Regular Sales order cycle. B)Explain the difference between the pick release and Ship Confirm process. c)Explain the Credit Check functionality. d)Explain the Ship Confirm Rule e)Explain how the price can be given to an item. f)Explain how can we Generate an invoice once we booked the order for a shippable item. g)Explain the Pricing Entities 1)Modifiers 2)Qualifiers. h)If the Ship Confirm button is Greyed out from the Shipping Transactions form what could be the reason. i)Explain the KFF’s in Order management Inventory a)Explain types of move orders b)Explain the Planning Methods c)Explain the Difference between Purchasable and purchased attributes. d)Explain KFF’s In Oracle inventory. e)Explain the Lead times concept. f)What is cumulative lead time and Cummulative Mfg Lead time. g)Explain Standard Costing and Average Costing. h)How can the Lead times be setup in the Item Master. i)Explain how many levels of reservation can be done. Purchasing a)Explain the document types. b)Explain the KFF’s in Purchasing. c)Explain the balancing segment. d)Explain the returns on Purchase order concept. e)Explain the attributes used for the purchasing.

2797


Why do you want to be a Cabin Crew?

1737


i want to b join intellegence bueru for acio grade2 i graduction for b.a kya mai ib join kar sakta ho palese give a answera

2254


What other TCP setting can you modify besides MTU to shorten packets?

3850


Hi I am looking for Hadoop Cloudera certification dumps. Please contact me if you some one have any idea about it. nzkhum786@gmail.com

1770