Question: Getting Data from a List. Given the following method Integer foo ( List a ) { Integer sum = new Integer ( 0 ) ;

Getting Data from a List. Given the following method
Integer foo( List a ){
Integer sum=new Integer(0);
for(int x =0; x < a.size(); x++){
sum += a.get( x )* a.get( a.size()- x -1);
}
return sum;
}
a. What prints out for a call to System.out.println(foo(list)) if the list contains {1,2,3,4}?
b. What is the Big-O if we call foo(list) where the list is a LinkedList with N elements
in it? Explain.
c. What is the Big-O if we call foo(list) where the list is an ArrayList with N elements
in it? Explain.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!