1 / 8

What to Analyze

What to Analyze. Analyze the algorithm rather than the program Running time worst-case average case. example. Maximum subsequence sum problem Given A 1 ,A 2 ,…,A n find the maximum value of Ex : -2 , 11 , -4 , 13 , -5 , -2 有四種 Algorithm.

Télécharger la présentation

What to Analyze

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. What to Analyze • Analyze the algorithm rather than the program • Running time worst-case average case

  2. example Maximum subsequence sum problem Given A1,A2,…,An find the maximum value of Ex:-2 , 11 , -4 , 13 , -5 , -2 有四種Algorithm

  3. A1: -2 11 -4 13 -5 -2 假設n個Ai

  4. A2: -2 11 -4 13 -5 -2 i -2 9 5 18 13 11 11 7 20 15 13 -4 9 4 2 13 8 6 -5 -7 -2 ∴O(N2)

  5. A3: divide and conquer -2 11 -4 13 -5 -2 11 13 7+13=20

  6. A4: -2 11 -4 13 -5 -2 Sum-2放棄 max 0 11  7  20  15  13 Note:最佳解開頭不為負 step1:由左至右,sum=0 累加若為負,則捨去        若大於max,則設定 O(N)

  7. On-line algorithm:only require constant space and runs in linear time.

  8. T(1,8)=_____ T(5,8)=_____ T(1,4)=_____ T(7,8)=_____ T(5,6)=_____ T(3,4)=_____ T(1,2)=_____ • 1. The Maximum Subsequence Sum Problem • Given integers a1=4, a2=-5, a3=-3, a4=3, a5=7, a6=-1, a7=2, a8=6, find the maximum subsequence sum • by divide and conquer • Let T(i, j) denote the maximum subsequence sum from ai to aj. Fill the following: • (b)By on-line algorithm

More Related