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 |
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.
Hello All, I am a indian lady married in aug,2006. In 2007 I asked one agent to apply for a passport for me. He filled up the form & I signed it. After few days I got the passport. Now there is one mistake he has done while filling my form. ****He has written my marital status as UNMARRIED in the form by mistake.*** Now I wanna go to US on B2 visa. Now I want to ask whethere I can face any legal action, because of wrong infromation in my passport application about the marital status earlier which is by mistake. What should I do?
if a material tested by titration and finish test by HPLC we can prepare working standard by which method.
0 Answers Aishwarya Healthcare,
Hi, It is really annoying for an aspirant of group1 exams, considering the uncertainity and sheer non transaparancy in the status of the supreme court judement pending..some body give a clear dates as to when it would be released.. and when would the next preliminary for group1 would be conducted.... Thanks in advance.. Please give the reliable and correct information....
SIR am studying B.pharmacy 3rd year now I want to know details regarding RRB pharmacist posts i.e 1.How to apply 2.Exams to be faced 3.Minimum qualification 4.Previous question papers pls do reply me my I.D : niranjanacrazyguy@gmail.com
QUESTION #1 It's the largest body of water surrounded by land within a familiar political entity. However, when compared to similar landforms in the region....it's all but a puddle. QUESTION #2 This eastern hemisphere (large) stream of water has the same name as a tiny town in the Bluegrass State, and a fishing pond in the Sunshine State. QUESTION #3 With a now-estimated 15 million plus residents, it's not even the largest metro area in its country. QUESTION #4 The rescue of a famous explorer happened in this indentation of a shoreline larger than a cove but smaller than a gulf. QUESTION #5 An important harbor city in the 14th century, it was repositioned in an effort to maintain its viability, a viability that remains to this day.
which type of questions are asked in interview related to warehousing profile. if anybody can support in this regard pls let us know?
how to decrease the rate of material?
can anybody tell me the syllabus for junior assistants in ttd
In Dena bank clerical recruitment, after making online application , All document should be sent by post only or also speed post or register AD should be done
Who is author of Indian struggles?
what is your strong point?