Sequential

Practice Questions

Computer Science › Sequential

Questions
3
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

True or False.

Sequential search is more efficient than Binary Search.

3

public static int foo(int\[\] arr, int x) {

for(int i = 0; i < arr.length; i++) {

if(arr\[i\] == x) {

return i;

}

}

return -1;

}

Given the method defined above, how many times is the word "Indubitably!" output by the code below?

int\[\] vals = {1,4,51,3,14,91,130,14};

for(int i = 0; i < 20; i++) {

if(foo(vals,i%4) < 0) {

System.out.println("Indubitably!");

}

}

Return to subject