Question
Analyze the time complexity of this program in big-O notation, assuming the size of L1 is n and the size of L2 is n too
Analyze the time complexity of this program in big-O notation, assuming the size of L1 is n and the size of L2 is n too
public static
ListIterator
AnyType itemL1=null, itemL2=null;
// get first item in each list if ( iterL1.hasNext() && iterL2.hasNext() ) { itemL1 = iterL1.next(); itemL2 = iterL2.next(); }
while ( itemL1 != null && itemL2 != null ) { int compareResult = itemL1.compareTo(itemL2);
if ( compareResult == 0 ) { Intersect.add(itemL1); itemL1 = iterL1.hasNext()?iterL1.next():null; itemL2 = iterL2.hasNext()?iterL2.next():null; } else if ( compareResult < 0 ) { itemL1 = iterL1.hasNext()?iterL1.next():null; } else { itemL2 = iterL2.hasNext()?iterL2.next():null; } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started