Searching

Practice Questions

Computer Science › Searching

Page 1 of 2
10 of 12
1

Which of the following implements a method named contains for searching an array sequentially, confirming whether or not the array contains a requested element?

2

Which of the following implements a method named contains for searching an array sequentially, confirming whether or not the array contains a requested element?

3

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);

4

What is the difference between inorder traversal of a binary search tree and a preorder traversal?

5

What is the difference between inorder traversal of a binary search tree and a preorder traversal?

6

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);

7

True or False.

Sequential search is more efficient than Binary Search.

8

True or False.

Sequential search is more efficient than Binary Search.

9

Which of the following is true for a binary search algorithm?

10

Which of the following is true for a binary search algorithm?

Page 1 of 2
Return to subject