Skip to content

Instantly share code, notes, and snippets.

@shiva27
Created December 24, 2011 09:11
Show Gist options
  • Save shiva27/1516958 to your computer and use it in GitHub Desktop.
Save shiva27/1516958 to your computer and use it in GitHub Desktop.
Circus Sorting Problem
A circus is designing a tower routine consisting of people standing atop one another’s shoulders. For
practical and aesthetic reasons, each person must be both shorter and lighter than the person below him or
her. Given the heights and weights of each person in the circus, write a method to compute the largest
possible number of people in such a tower.
EXAMPLE:
Input (ht, wt): (65, 100) (70, 150) (56, 90) (75, 190) (60, 95) (68, 110)
Output: The longest tower is length 6 and includes from top to bottom: (56, 90) (60,95) (65,100) (68,110)
(70,150) (75,190)
Proposed Algorithm:
The proposed algorithm is as follows
1. Create a Directed graph from the given list of persons
2. Each vertex will represent a Person and there will be an edge between two vertices iff source
vertex(person) can stand on destination vertex(person)
3. Once a graph is created, now find the longest path in the graph. This should give the solution for the
problem.
To implement a graph, we can make use of adjacency matrix
Check the link: http://en.wikipedia.org/wiki/Adjacency_matrix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment