My teacher has just teach me about complexity of algorithm and he has gave me some homework. I have solve almost all except for this ex:
Consider a robot arm that is fixed at one end. The arm contains two elbows at each of which it is possible to rotate the arm 90 degrees up and down in a vertical plane. How would you mathematically model the possible movements of the end of the arm? Describe an algorithm to move the end of the robot arm from one permissible position to another.
I have to make an algorithm from this requirement? Please give me some cue. ==

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by tungnk1993

The way I see the problem is shown through the picture, you can see the link or attachment

So, you can set two variables,
int firstElbow, secondElbow;

where value of 1 = up and 2 = right, 3 = down, 4 = left for example

So if firstElbow = 2 (right) and secondElbow = 1 ( up) the final position is (1,2) for example.

Attachments

Thank you for giving me the cue. I guess that is complexity is O(1) because it always has two elements regardless of input or out. Is it right?

Since all you need is to calculate the out position from the two elements and no for-loop are required, it's O(1)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.