Computer Science › Searching
Which of the following implements a method named contains
for searching an array sequentially, confirming whether or not the array contains a requested element?
Which of the following implements a method named contains
for searching an array sequentially, confirming whether or not the array contains a requested element?
public static int foo(int\[\] arr, int x) {
int a = 0;
int b = arr.length - 1;
while(b >= a) {
int c = (a + b) / 2;
int v = arr\[c\];
if(v == x) {
return c;
} else if(v < x) {
a = c + 1;
} else {
b = c - 1;
}
}
return -1;
}
What is the value of y in the code below:
int\[\] vals = {1,3,4,5,6,31,41,51};
int x = 41;
int y = foo(vals,41);
What is the difference between inorder traversal of a binary search tree and a preorder traversal?
What is the difference between inorder traversal of a binary search tree and a preorder traversal?
public static int foo(int\[\] arr, int x) {
int a = 0;
int b = arr.length - 1;
while(b >= a) {
int c = (a + b) / 2;
int v = arr\[c\];
if(v == x) {
return c;
} else if(v < x) {
a = c + 1;
} else {
b = c - 1;
}
}
return -1;
}
What is the value of y in the code below:
int\[\] vals = {1,3,4,5,6,31,41,51};
int x = 41;
int y = foo(vals,41);
True or False.
Sequential search is more efficient than Binary Search.
True or False.
Sequential search is more efficient than Binary Search.
Which of the following is true for a binary search algorithm?
Which of the following is true for a binary search algorithm?