Question: Index of Element in Array ( Permutation ) The following algorithm finds the index of an element in an array of integers, or None if
Index of Element in Array Permutation
The following algorithm finds the index of an element in an array of integers, or None if it is not found. def findelementindexa x:
# Get length of array
n lena
# Iterate over all elements
for i in rangen:
# Get value of element
val ai
# Check element found
if val x:
# Return current index as found
return i
# Return not found
return None
If the array is a permutation of the numbers from to n and the element to find is within that range, the following is requested:
a Find the expression for the expected value of the growth order in terms of the size n of the array.
b The expression of the growth order according to the asymptotic notation O
c How would you reconcile the two previous answers?
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
