Question: 1, Write a function: def removeFrom ( self , d ) that finds the first occurrence of d in the linked list (the one represented
1, Write a function: def removeFrom ( self , d ) that finds the first occurrence of d in the linked list (the one represented by self) and removes all the elements of the list from that position onwards, and returns True. If d is not in the list, the function should leave the list as is and return False. For example, if ls is the list [1,6,13,6,8,27,3] then ls.removeFrom(6) should change ls to [1] and return True. If ls is [1,13,8,27] then ls.removeFrom(6) should leave ls as is and return False. For full marks, your function should go through the elements of the list at most once (each time it is called).
2. Consider the following Python function, written for the ArrayList class. It returns the number of elements in the array list (i.e. the one represented by self) that are duplicates. The function uses the implementation of mergeSort that we saw in the lectures. def countDups ( self ) : A = self . inArray [: self . count ] mergeSort ( A ) dups = 0 for i in range (1 , len ( A ) ) : if A [ i ] == A [i -1]: dups += 1 return dups Explain, in terms of big-, what is the worst-case time complexity of countDups. Express the time complexity as a function of the size of the array list.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
