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

without administrator right how to run iis services

0 Answers   V Angelz Technologies, Wonder Products,


Where i can get the ignou assignment solutions, ignou assignment answers, ignou mba assignments 2009

4 Answers   ABC, Ignou,


WHICH BOWLERS HAS SCORED TWO TEST CENTURIES IN THE TEST CRICKET?

2 Answers  


What are the advice on the services of <a href="indianastrologyhoroscope.com">indianastrologyhoroscope.com</a> According to them, they are : IndianAstrologyHoroscope. com provides Astrology readings and Indian Horoscope by expert Indian astrologers. The site is your resource for accurate Vedic astrology predictions. It has dedicated astrology services that are available for corporate astrology. The site has many interesting articles in case of KaalSarp Dosha, Manglik Dosha, or Kuja Dosha, Sarp Dosha, and ill effects on marriage.

0 Answers  


WHEN WORKING ON A COMPUTER, WHAT TO DO ? TO AVOID THE REPORT " WINDOWS MEMORY TOO LOW "

0 Answers  






hai im sandhya i need sbi previous question papers with answers pls send to email : www.manoja79@gmail.com

0 Answers  


I m selected in cag DEO pag gssa in kerla Obc category if anybody want kerla then call me 7275639235

0 Answers  


Does anybody know clearly when the sbi interview results will be declared?Please tell me.I have attended the interview on 26 may.

1 Answers  


Q. MULTINATIONAL IS : ANS. A COMPANY OPERATING IN SEVERAL COUNTRIES

1 Answers  


Which is the oldest mountain range in India?

3 Answers  


WHAT CAN BE THE EXPECTED CUT OFF FOR IDBI ASST MANAGER PAPER HELD ON 27 DEC 09.I ATTEMPTED 147 QUES IN ALL WITH 85 % ACCURACY..DO I HAVE A CHANCE

1 Answers  


i need information abbout mashroom cultivation,marketing please provide me information.

0 Answers   Satyam,


Categories