Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a function remove_duplicates(L) that consumes a list L of natural numbers and uses a modification of our binary searching algorithm to replace all elements

image text in transcribedimage text in transcribed
Write a function remove_duplicates(L) that consumes a list L of natural numbers and uses a modification of our binary searching algorithm to replace all elements that appear more than once with -1, Vour code must run in 0(n10gn) time. Sample: L = [6,1,2,3,3,4,5,6,89823] remove_duplicates(L) => None and L is mutated to [-1,1,2, -1,-1,4,5, -1,89823] Do not import any modules other than math and check. You are always allowed to define your own helper/wrapper functions, as long as they meet the assignment restrictions. Do not use Python constructs from later modules (e'g' dictionaries, commands continue or break, zip, functions with default parameters, anything with set or enumerator, ord, chr, try and except), Do not mutate passed parameters for required functions unless otherwise told to. Use only the functions and methods as follows: - abs, len, max, min, sum, range and sorted 0 Any method or constant in the math module Anybasicarithmetic orcomparison operations(+, -, *, /, H, 94, **, ; >=) Any basic logical operators (not, and, or) These typecasting operators: int(), str()_, floato, bool(), list(), and type() 11: state m ents String or list slicing and indexing as well as string or list operations using the operators above Any string or list methods (see additional notes below) and the in operator input and print as well as the formatting parameter end and method format. Note that all prompts must match exactly in order to obtain marks, so ensure that you do not alter these prompts. Recursion is allowed but inputs will often be larger than recursion can handle so be cautious! Abstract List Functions map and filter and the keyword lambda Single variable loops, specifically for and while loops

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

Students also viewed these Programming questions