I read this statement in “Hitchhiker’s guide to algorithms”. But, I’m not able to visualize it as in a LIS problem all we have is a sequence of numbers. How can I modulate it as a graph problem?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Imagine the problem of a 2D grid. You’re on the bottom left square and you need to get to the top right square. Can you imagine an acyclic DAG out of this scheme?
Now imagine some of the squares are forbidden. Making squares forbidden may lead to a ‘lock’ (you might find yourself trapped), and now chosing which paths to follow is actually important.
In terms of graph, you can think of forbidding squares as removing vertices, and your goal is go from the root to one specific node (the sink).
Now let’s go back to the LIS. When solving the LIS, what you actually need to do is decide which numbers you’ll pick, and which you won’t. The restriction is that whenever you pick one number, you can’t pick any number which is smaller than this one (you pick the numbers in order).
Now we can mix both things. Imagine that you’ll build a graph out of your sequence of numbers:
Every path on this graph is a valid increasing subsequence. The problem of finding the LIS is now the problem of finding the longest path on this graph.