Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Contemporary Issues In Database Design And Information Systems Development

Authors: Keng Siau

1st Edition

1599042894, 978-1599042893

More Books

Students also viewed these Databases questions