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.

Answers were Sorted based on User's Feedback



U have an array of +ve integers arranged in the descending order . Write a functionb thast take an..

Answer / argho

function desc
begin
Ineger i;
Array a[n];
x=1;
y=n;

1. for k=1 , loop from x to y while array[n] / 2;

temp[a]= a[n]/2

if temp[a] < i
call step 1 with argument x=1 y=n/2
else if temp[a] > i
call step 1 with argument x=(n/2)+1 y=n
else
return position
end

Is This Answer Correct ?    4 Yes 0 No

U have an array of +ve integers arranged in the descending order . Write a functionb thast take an..

Answer / 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

U have an array of +ve integers arranged in the descending order . Write a functionb thast take an..

Answer / sonu

int array[]={13,232,234,12,34,56,73,21,230,240};
int max ;
max = 230;
for (int i=1;i<array.length;i++){
if (array[i]==max ){
System.out.println
("Position of no"+max +"in array is "+i);
}else {
System.out.println("-1");
}
}

Is This Answer Correct ?    2 Yes 12 No

Post New Answer

More Everything Else AllOther Interview Questions

Hi !!! Iam Palvannan. I am 28 yrs old married. I am working as a senior Merchandiser in apparel export industry. I have done Post diploma in textile technology - 4 1/2 yrs after my 10th std.I have got about 8 yrs of exp in this field. But i found the industry is narrowing down & i really feel to change my career to software testing as it is booming very rapidly. I need a serious help in changing my career. I was enouraged by some group & was threatened by some. Please help me to sort this.

0 Answers  


who is current supreme court jedge

1 Answers  


why all the measurments in ship is in current only?

1 Answers  


Could u tell how is coaching in National School of Banking, Ameerpet, Hyderabad for bank pos.

5 Answers  


when will sbi clerical final result out?????? interview held in the months of april and may 2010

0 Answers  


What are the differences between decision-making statements and loop statements?

1 Answers   Everest Online,


how do i begin my interview with a manufacturer to earn their transportation business ?

0 Answers  


Can you tell me which coaching classes is best for banking in chennai?

0 Answers  


Describe a challenging and difficult project which you have undertaken. What did you do? Explain your reasons for the same & what was the outcome?

0 Answers   Hindustan Unilever Limited,


ELECTRONIC VOTING MACHINE WAS FIRST USED IN INDIA AT WHICH STATE? (A) KERELA (B) CHENNAI (C) DELHI (D) BANGALORE

1 Answers  


who is the prime minister of londan

4 Answers   NIFT,


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?

0 Answers  


Categories