if array a conatins 'n' elements and array b conatins 'n-1'
elements.array b has all element which are present in array
a but one element is missing in array b. find that
element.
Answer Posted / argho chatterjee
// Assuming arrays are sorted in ascending order
/*
it is not efficient if the number is found at the start of
the array.
It tries to break the array and find the position from the
middle and then again breaks till it find the position of
the array.
*/
public static void main(Array mainArray , Array
missingArray) {
int pointer = mainArray.length /2; // default is 0
return findMissingElement
(mainArray ,missingArray,pointer);
}
int findMissingElement(Array mainArray , Array
missingArray,pointer) {
if(mainArray[pointer] ==
missingArray[pointer] ) {
pointer = pointer + pointer /2;
return
findMissingElement
(mainArray ,missingArray,pointer);
}
else {
return mainArray[mainArray.length/i];
}
}
Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
What do you mean by invalid pointer arithmetic?
What is the acronym for ansi?
When I tried to go into a security sites I am denied access and a message appeared saying 'applet not initialize'. How can I rectify this problem.
What are the types of c language?
What is indirection in c?
Is a pointer a kind of array?
write a c program to calculate sum of digits till it reduces to a single digit using recursion
What is a null pointer in c?
What is character set?
Write a program to produce the following output: 1 2 3 4 5 6 7 8 9 10
Explain how do you use a pointer to a function?
Devise a program that inputs a 3 digit number n and finds out whether the number is prime or not. Find out its factors.
main() { int i = 10; printf(" %d %d %d ", ++i, i++, ++i); }
What is meant by inheritance?
What is the function of volatile in c language?