Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

What is the Big-O running time of the following code fragment?public static int

ID: 3616513 • Letter: W

Question

 What is the Big-O running time of the following code fragment?public static int calc( List<Integer> lst, int N ){int count = 0;for ( int i=0; i<N; i++){if (lst.get(i) > 0)sum += lst.get(i);elsesum += lst.get(i) * lst.get(i);}return sum;}a.  If an ArrayList is passed.  Explain your answer.b.  If a LinkedList is passed.  Explain your answer.What is the Big-O running time of the following code fragment?public static void add( List<Integer> lst1, List<Integer> lst2){for ( Integer x : lst1 )lst2.add(0, x);}a.  If an ArrayList is passed for lst1 and lst2.  Explain your answer.b.  If a LinkedList is passed for lst1 and lst2.  Explain your answer.

Explanation / Answer

//Hope this will help you. It case of Array, it will be O(n), as get functiontake O(1). In case of linkList it will take O(n2), as get functiontake O(n)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote