1 Crore+ students have signed up on EduRev. Have you? Download the App 
What is the index of the first element in an array with N elements?
Which of the following statements is true about passing arrays to functions in C++?
Which of the following is the correct syntax to declare a 1D array of integers in C++?
What is the time complexity of searching an element in an array using binary search (iterative method)?
Which of the following is the correct formula to calculate the middle index in binary search?
Binary search can be applied on which of the following types of arrays?
What is the index range of elements in an array with 10 elements?
What is the output of the following code snippet?
#include <iostream>
using namespace std;
int main() {
int arr[] = {1, 2, 3, 4, 5};
cout << arr[2];
return 0;
}
What is the output of the following code snippet?
#include <iostream>
using namespace std;
int main() {
int arr[5] = {1, 2, 3, 4, 5};
cout << arr[5];
return 0;
}
What is the output of the following code snippet?
#include <iostream>
using namespace std;
void modifyArray(int arr[]) {
arr[0] = 100;
}
int main() {
int arr[] = {1, 2, 3, 4, 5};
modifyArray(arr);
cout << arr[0];
return 0;
}
What is the output of the following code snippet?
#include <iostream>
using namespace std;
void printArray(int arr[], int size) {
for (int i = 0; i < size; i++) {
cout << arr[i] << " ";
}
}
int main() {
int arr[] = {1, 2, 3, 4, 5};
printArray(arr, 5);
return 0;
}
What is the output of the following code snippet?
#include <iostream>
using namespace std;
int binarySearch(int arr[], int left, int right, int key) {
if (left <= right) {
int mid = left + (right  left) / 2;
if (arr[mid] == key)
return mid;
if (arr[mid] > key)
return binarySearch(arr, left, mid  1, key);
return binarySearch(arr, mid + 1, right, key);
}
return 1;
}
int main() {
int arr[] = {2, 4, 6, 8, 10};
int key = 8;
int result = binarySearch(arr, 0, 4, key);
cout << result;
return 0;
}
What does the following code snippet do?
#include <iostream>
using namespace std;
int binarySearch(int arr[], int n, int key) {
int low = 0, high = n  1;
while (low <= high) {
int mid = low + (high  low) / 2;
if (arr[mid] == key)
return mid;
if (arr[mid] < key)
low = mid + 1;
else
high = mid  1;
}
return 1;
}
int main() {
int arr[] = {2, 4, 6, 8, 10};
int key = 6;
int result = binarySearch(arr, 5, key);
cout << result;
return 0;
}
What does the following code snippet do?
#include <iostream>
using namespace std;
int binarySearch(int arr[], int low, int high, int key) {
if (low <= high) {
int mid = low + (high  low) / 2;
if (arr[mid] == key)
return mid;
if (arr[mid] > key)
return binarySearch(arr, low, mid  1, key);
return binarySearch(arr, mid + 1, high, key);
}
return 1;
}
int main() {
int arr[] = {2, 4, 6, 8, 10};
int key = 8;
int result = binarySearch(arr, 0, 4, key);
cout << result;
return 0;
}
What does the following code snippet do?
#include <iostream>
using namespace std;
int binarySearch(int arr[], int n, int key) {
int low = 0, high = n  1;
while (low <= high) {
int mid = low + (high  low) / 2;
if (arr[mid] == key)
return mid;
if (arr[mid] > key)
high = mid  1;
else
low = mid + 1;
}
return 1;
}
int main() {
int arr[] = {2, 4, 6, 8, 10};
int key = 6;
int result = binarySearch(arr, 5, key);
cout << result;
return 0;
}
What does the following code snippet do?
#include <iostream>
using namespace std;
int binarySearch(int arr[], int low, int high, int key) {
if (low <= high) {
int mid = low + (high  low) / 2;
if (arr[mid] == key)
return mid;
if (arr[mid] < key)
low = mid + 1;
else
high = mid  1;
return binarySearch(arr, low, high, key);
}
return 1;
}
int main() {
int arr[] = {2, 4, 6, 8, 10};
int key = 8;
int result = binarySearch(arr, 0, 4, key);
cout << result;
return 0;
}
What does the following code snippet do?
#include <iostream>
using namespace std;
int binarySearch(int arr[], int left, int right, int key) {
if (left <= right) {
int mid = left + (right  left) / 2;
if (arr[mid] == key)
return mid;
if (arr[mid] > key)
return binarySearch(arr, left, mid  1, key);
return binarySearch(arr, mid + 1, right, key);
}
return 1;
}
int main() {
int arr[] = {2, 4, 6, 8, 10};
int key = 12;
int result = binarySearch(arr, 0, 4, key);
cout << result;
return 0;
}
70 videos44 docs15 tests

70 videos44 docs15 tests
