Consider the following Algorithm is to compare two lists.
compare list ( list 1, list 2)
{
for num in list 1
{
if num not in list 2
return 0 ;
else
remove the first occurrence of num from list 2
}
if list 2 is empty
return 1;
}
Let n be the length of list 1 and m be the length of list 2. What is the worst – case running time of given algorithm?
- O(n2)
- O(m2)
- O( m log n)
- O(nm)