Efficient Algorithm for Longest Increasing Subsequence Problem

dynamic programming 4 longest increasing n.w
1 / 11
Embed
Share

Explore dynamic programming algorithms for the Longest Increasing Subsequence (LIS) problem, understand the concept of maintaining the smallest integers ending a subsequence of each length, and learn how to efficiently compute and maintain this list for every prefix. Discover a more efficient solution that determines the smallest integer ending a longest increasing subsequence, enhancing your understanding of dynamic programming concepts.

  • Dynamic Programming
  • Longest Increasing Subsequence
  • Algorithm Efficiency
  • Prefix Computation

Uploaded on | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. Dynamic Programming (4) Longest Increasing Subsequence (LCS)

  2. DP alg. for LIS The idea is to compute for each 1 ? ?: L[i] = The length of the longest increasing subsequence ending with ?? P[i] = The index of the element that precedes ??in the longest sequence that ends at ?? The length of the LIS is max 1 ? ??[?] ? ? = max ? ? ??< ?? + 1 ?<? ? 1 2 3 4 5 6 7 8 9 ? 2 4 10 9 7 5 6 8 8 L P

  3. DP alg. for LIS The idea is to compute for each 1 ? ?: L[i] = The length of the longest increasing subsequence ending with ?? P[i] = The index of the element that precedes ?? in the longest sequence that ends at ?? The length of the LIS is max 1 ? ??[?] ? ? = max ? ? ??< ?? + 1 ?<? ? 1 2 3 4 5 6 7 8 9 ? 2 4 10 9 7 5 6 8 6 L 1 2 3 3 3 3 4 5 4 P 1 2 2 2 2 6 7 6

  4. Running time ? ? ?2

  5. A more efficient algorithm ? Back to our previous solution, where we wanted to know the smallest integer that ends a longest increasing subsequence I[j] = the smallest integer that ends an increasing subsequence of length j

  6. Smallest integers ending subsequence of each length Back to our previous solution, where we wanted to know the smallest integer that ends a longest increasing subsequence I[j] = the smallest integer that ends an increasing subsequence of length j ? 1 2 3 4 5 6 7 8 9 ? 2 4 3 5 1 7 6 9 8 I

  7. Lets try to compute this list for every prefix Back to our previous solution, where we wanted to know the smallest integer that ends a longest increasing subsequence I[j] = the smallest integer that ends an increasing subsequence of length j ? 1 2 3 4 5 6 7 8 9 ? 2 4 3 5 1 7 6 9 8 I [2] [2,4] [2,3] [2,3,5] [1,3,5] [1,3,5,7] [1,3,5,6] [1,3,5,6,9] [1,3,5,6,8]

  8. How do we maintain the list I I ? Back to our previous solution, where we wanted to know the smallest integer that ends a longest increasing subsequence I[j] = the smallest integer that ends an increasing subsequence of length j ? 1 2 3 4 5 6 7 8 9 ? 2 4 3 5 1 7 6 9 8 I [2] [2,4] [2,3] [2,3,5] [1,3,5] [1,3,5,7] [1,3,5,6] [1,3,5,6,9] [1,3,5,6,8] The list I is sorted When traversing ?? find ? such that ? ? 1 < ?? ?[?] Update ? ? = ??

  9. Smallest integers ending subsequence of each length Back to our previous solution, where we wanted to know the smallest integer that ends a longest increasing subsequence I[j] = the smallest integer that ends an increasing subsequence of length j ? 1 2 3 4 5 6 7 8 9 ? 2 4 10 9 7 5 6 8 3 I [2] [2,4] [2,4,10] [2,4,9] [2,4,7] [2,4,5] [2,4,5,6] [2,4,5,6,8] [2,3,5,6,8] The list I is sorted When traversing ?? find ? such that ? ? 1 < ?? ?[?] Update ? ? = ??

  10. Efficient Implementation Maintain I such that you can find ? by a binary search ? ? log ? time

  11. How do we find the list itself ? Try to find the algorithm by yourself

Related


More Related Content