Question: 1. Suppose we define a static method totalEvenLocation that returns the total of even-index items of an integer List as below: public static int totalEvenLocation(

1. Suppose we define a static method totalEvenLocation that returns the total of even-index items of an integer List as below: public static int totalEvenLocation( List lst ) { int sum = 0; for( int i = 0; i < lst.size() ; i+=2 ) sum += lst.get(i); return sum; }

What is the Big-O running time of the method if lst is an LinkedList of size N?

select one:

a) O(1) b) O(logN) c) O(N) d) O(NLogN) e) O(N2)

2. Suppose we define a static method totalEvenLocation that returns the total of even-index items of an integer List as below: public static int totalEvenLocation( List lst ) { int sum = 0; for( int i = 0; i < lst.size() ; i+=2 ) sum += lst.get(i); return sum; }

What is the Big-O running time of the method if lst is an ArrayList of size N?

select one:

a) O(1) b) O(logN) c) O(N) d) O(NLogN) e) O(N2)

3. Given the following definition of ListNode constructor (similar to the one we have in our doubly-linked list example). public ListNode (T v, ListNode n) { this.value = v; this.next = n; }

Which statement inserts an item x after position "current"?

select one:

a) current = new ListNode(x, current); b) current = new ListNode(x, current.next); c) current.next = new ListNode(x, current); d) current.next = new ListNode(x, current.next); e) none of the above

4. Suppose we define a method removeHalf that removes the first half of a List (or slightly less than one-half of the list if odd length) as below: public static void removeHalf( List lst ) { int size = lst.size( ); for( int i = 0; i < _________/2 ; i++ ) lst.remove( 0 ); } What can be used to fill the blank?

select one:

a) only size b) only lst.size() c) either size or lst.size() would work d) neither size nor lst.size()

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 Databases Questions!