subject

See method fasterLinSearch() below. This method implements the linear search algorithm to search list for key. However, unlike the usual linear search algorithm, fasterLinSearch() attempts to find key more quickly by performing two comparisons of a list element to key during each pass of the loop. In particular, it compares the elements at indices n and list. size() - 1 - n to key each time through the loop. If key is equal to one of these two list elements, then the corresponding list index is returned. The question is: what is(are) the key operation(s) in this algorithm? public int fasterLinSearch ArrayList Integer list, Integer key)
{ for (int n = 0; n <= list. size() / 2; ++n) {
if (list. get(n).equals(key)) {
return n;
} else if (list. get(list. size() 1 - n).equals(key)) {
return list. size() - 1 - n;
}
}
return -1;
}
return list. size() - 1 - n;
list. get (list. size() 1 n).equals (key) n
++n n
list. get (n) U
n <= list. size() / 2
list. get(n).equals (key)
list. get (list. size() - 1 - n)
return -1;
return n; n
public int fasterlinSearch (ArrayList list, Integer key)

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 18:00
Assume that you have an array of integers named a. which of these code segments print the same results? int i = 1; while(i < a.length) { system.out.println(a[i]); i++; } int i; for (i = 0; i < a.length; i++) { system.out.println(a[i]); } for (int i : a) { system.out.println(i); } i and ii only ii and iii only i and iii only all three print the same results. all three print different results.
Answers: 3
question
Computers and Technology, 23.06.2019 22:50
What is an rss reader used for? for creating a user account on a social new site
Answers: 2
question
Computers and Technology, 24.06.2019 07:00
You are most likely to automatically encode information about
Answers: 1
question
Computers and Technology, 24.06.2019 10:00
(, urgent need): how do i change my username
Answers: 1
You know the right answer?
See method fasterLinSearch() below. This method implements the linear search algorithm to search lis...
Questions
question
Mathematics, 22.11.2021 19:30
question
Mathematics, 22.11.2021 19:30
question
Mathematics, 22.11.2021 19:30
question
Mathematics, 22.11.2021 19:40
Questions on the website: 13722365