Given a list of n distinct integers and a sequence of n boxe

Given a list of n distinct integers and a sequence of n boxes with preset inequality signs inserted between them, design an algorithm that places the numbers into boxes to satisfy those inequalities. For example, the numbers 2, 5, 1, 4, and 0 can be placed in the boxes as shown below:

0 < 5 > 1 < 2 < 4

Solution

In this problem, each and every position defines a separate partial order set i.e element1 < element2 or element1 > element2.

Once we construct total order set from this partial order set, we could solve this problem easily. Sort the positions with respect to total order and assign numbers based on the position in the total order.

Pseudo code:

Given a list of n distinct integers and a sequence of n boxes with preset inequality signs inserted between them, design an algorithm that places the numbers in

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site