Computational complexity of expanding a vector

For a n-by-1 vector A, and a m-by-1 index (integer) vector b, where max(b)<=n and min(b)>=1, can anyone tell me, what is the computational complexity (big-O notation) to expand the vector A using command A(b)?
Thanks

 Accepted Answer

Jan
Jan on 3 Aug 2017
Edited: Jan on 7 Aug 2017
This is O(m): If b has the double size, you need the double work.
You do not need any sorting. The size of the output is determined by the size of b, such that there is no need to find the maximum element. This is a linear job.
[EDITED: O(1) -> O(m): "linear" was correct, but not "1"]

3 Comments

Thank you for your replying, do you mean the complexicty is O(m)? Because I don't think the complexity will be a constant for any size of b
Yes, O(m) would be correct. m occurrences of O(1)
Yes, of course, O(m).

Sign in to comment.

More Answers (0)

Products

Asked:

on 3 Aug 2017

Commented:

Jan
on 7 Aug 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!