Question: Using Matlab to solve following question: (1) Write the function has duplicate() which takes as input a vector v and outputs true if there is

Using Matlab to solve following question: (1) Write the function has duplicate()Using Matlab to solve following question:

(1) Write the function has duplicate() which takes as input a vector v and outputs true if there is a repeated element in v and false if there is no repeated elements. Below is the algorithm which you should implement.

default output is 0

for elt1 in v:

for elt2 later in v than elt1:

if elt1==elt2, make output 1, break, end

end

end

Checking if elt1==elt2 counts as one step. Setting the output value also counts as one step.

(a) How many steps does it take for the input of v=[1, 3, 3, 7, 9]? List each step in order.

(b) Whats the most number of steps it could take for a length 5 input?

(c) Whats the most number of steps it could take for a length n input?

(1) Write the function has.duplicate) which takes as input a vector v and outputs true if there is a repeated element in v and false if there is no repeated elements. Below is the algorithm which you should implement default output is 0 for elt1 in v: for elt2 later in v than elt1: if elt 1-=elt2, make output l, break, end end end Checking if elt1==eIt2 counts as one step. Setting the output value also counts as one step. (a) How many steps does it take for the input of v [1, 3, 3, 7, 9]? List each step in order. b) What's the most number of steps it could take for a length 5 input? c) What's the most number of steps it could take for a length n input

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!