Question
In this problem, you are given the list of numbers and the parameter _m_ and you want to return the **indices** of the _m_ smallest
In this problem, you are given the list of numbers and the parameter _m_ and you want to return the **indices** of the _m_ smallest numbers **without changing the original list**.
E.g. If the list is \[7, 4, 1, 3, 6, 8, 2, 5\] and _m_ is 3 then the indices of the _m_ smallest values are 2, 3, and 6.
In the cells below, complete the function definition and run it on the given test cases.
def mSmallestIndices(L, m):
"""
Pre: L is a list of integers, m <= length(L)
Post: A list of the indices of the m smallest elements of L has been returned.
"""
# Initialize the result list
ms = [] # At the end of the function, ms will be a list of the indices of the m smallest values in L.
... # Replace this whole line with the lines of your function
return ms
Questions
What should be the output of the following function call? -> mSmallestIndices(B, 4)
What should happen if you try it with a value of _m_ greater than the size of the list? (Try it)
Determine the worst-case time complexity of your function for a list of size _n_, based on the characteristic operation you identified. (Use as many celles as necessary.)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started