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
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 |
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 |
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 |
Does anybody know clearly when the sbi interview results will be declared?Please tell me.I have attended the interview on 26 may.
Can someone please help me out with interview Questions for SBI management executive exam? Is it expected to be same as SBI PO Interview, or it is expected to be a higher level interview? Please guide. Thanks in advance.
0 Answers State Bank Of India SBI,
as you finished hotelmanagement why you want to work sales and marketing.
How many states are in VXVM plex?
sir, i completed my diploma at 2009,den i joined in a degree course but i didnt completed my btech due to some problem.so now 2012, dat means three years gap.i want a job in it sector.but in most companies,they want btech candidate.so wat type of problem'll come if i produce fake btech critificate???? they'll varify my qualification? and wat'll happen if they found my critificate's r false after getting job?
china is not a member of 1---WTO 2---ARF 3---APEC 4---UN
how many name can u make of this ' Hena'
generaly , it is asked by the interviewer that why should we select you only rather than others , Pl suggest it answer
Why do so many people not recycle or seem to care about the environment and how can we get families to be more involved?
can the same motherboard installed with a 32 bit vista operating system be used with a x64 bit operating system,and be upgraded to 8gb of memory,or is there a motherboard issue here that wont allow this upgrade.
Why should i select u for this company? Why not others?
How to check the memory failures in soalris?