What is the Big-O running time of the following code fragment?public static int
ID: 3616514 • Letter: W
Question
What is the Big-O running time of the following code fragment?public static int Count( List<Integer> lst1, List<Integer> lst2){Iterator<Integer> itr1 = lst1.iterator();int count=0;while ( itr1.hasNext() ){Integer x = itr1.next();Iterator<Integer> itr2 = lst2.iterator();while ( itr2.hasNext() )if ( x.equals( itr2.next()) )count++;}return count;}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
public static int Count( List<Integer> lst1, List<Integer> lst2)
{
Iterator<Integer> itr1 = lst1.iterator();
int count=0;
while ( itr1.hasNext() )
{
Integer x = itr1.next();
Iterator<Integer> itr2 = lst2.iterator();
while ( itr2.hasNext() )
if ( x.equals( itr2.next()) )
count++;
}
return count;
}
so it will go i time, where m is the size of linklist of itr1, and n is the size of linklist itr2
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.