Describe an algorithm that sorts 5 unequal rocks with lever

Describe an algorithm that sorts 5 unequal rocks with lever scales using only 7 (or 8) tests

Solution

Explanation:

Let\'s assume that 5 rocks are numbered as 1,2,3,4 and 5, respectively and we are sorting them in increasing order.

Step1: Let\'s 1 and 2 are compared using a lever. Let (2>1).

Step 2: Now, 3 and 4 are compared using a lever. Let (4>3)

Step 3: Now, 5 will be compared with sorted pair of rocks (3,4).

Step-4: Similarly, now sorted pair (1,2) will be compared with (3,4,5).

So, in worst case, total number of levers can be used to sort unequal rocks will be 8.

Describe an algorithm that sorts 5 unequal rocks with lever scales using only 7 (or 8) testsSolutionExplanation: Let\'s assume that 5 rocks are numbered as 1,2,

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site