Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 > void intersection(List L1, List L2, List Intersect) {

ListIterator iterL1 = L1.listIterator(); ListIterator iterL2 = L2.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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spatial Database Systems Design Implementation And Project Management

Authors: Albert K.W. Yeung, G. Brent Hall

1st Edition

1402053932, 978-1402053931

More Books

Students also viewed these Databases questions