Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Dominator Tree

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
Avatar for knshnb knshnb
August 02, 2020

Dominator Tree

Avatar for knshnb

knshnb

August 02, 2020

More Decks by knshnb

Other Decks in Programming

Transcript

  1. ͸͡Ίʹ ✴ Dominator Treeͱ͸ʁ ‣ Flowgraphʹରͯ͠Ұҙʹఆ·Δ໦ߏ଄ ‣ ϓϩάϥϜͷσʔλϑϩʔΛղੳ͢Δจ຺Ͱग़ͯ͘Δ ‣ Lengauer

    & Tarjan͕ޮ཰తͳΞϧΰϦζϜΛൃݟ ✴ ࢀߟ ‣ ΦϦδφϧ࿦จ: “A Fast Algorithm for Finding Dominators in a Flowgraph” ‣ sigma͞Μͷϒϩά: http://sigma425.hatenablog.com/ entry/2015/12/25/224053 2
  2. ໨࣍ ✴ ൃද಺༰ ‣ Dominator Tree͕ఆٛͰ͖Δ͜ͱΛஸೡʹ ‣ ͷΞϧΰϦζϜઆ໌ ‣ Lengauer-TarjanͷΞϧΰϦζϜΛ͔Δʔʔʔ֓͘ཁઆ໌

    ✴ Lengauer-TarjanͷΞϧΰϦζϜΛৄ͘͠஌Γ͍ͨํ͸sigma ͞Μͷϒϩά͕͓͢͢ΊͰ͢ ✴ ݩ࿦จ΋͔ͳΓಡΈ΍͍͢ʢূ໌શ෦௥ͬͯͳ͍͚Ͳ…ʣ O(nm) 3
  3. ఆٛ1 ✴ Flowgraph: ࢝఺͔Βશͯͷ௖఺ʹ౸ୡՄೳͳ༗޲άϥϑ ‣ ҎԼɺ࢝఺Λ ͱͨ͠FlowgraphΛߟ͑Δ ✴ ௖఺ ͕௖఺

    Λdominate͢Δ: ͔Β ΁ͷ೚ҙͷύε͕ Λ ௨Δʢ ͸ Λdominate͠ɺ ͸ Λdominate͠ͳ͍΋ͷͱ͢ Δʣ ‣ Λdominate͢Δ௖఺ू߹Λ ͷdominatorͱݺͿ r d v r v d r d d d v v 5
  4. Ex.1: ޓ͍ʹdominate͠ͳ͍ ✴ ʮ ͕ Λdominateʯ͔ͭʮ ͕ Λdominateʯ͸͋Γ͑ͳ͍ ‣ ূ໌:

    ͔Βద౰ʹdfsͯ͠ɺ ͔ ʹ͸͡Ίͯ౸ୡͨ͠ͱ͖ ͷύεΛߟ͑Δɻͦͷύε্ʹ΋͏ยํͷ௖఺͸ଘࡏ͠ͳ ͍ɺ͢ͳΘͪͲͪΒ͔͸΋͏ยํΛdominate͠ͳ͍ɻ a b b a r a b 7
  5. Ex.2: dominateͷਪҠ཯ ✴ ͕ Λdominate, ͕ Λdominate ͕ Λdominate ‣

    ূ໌: ೚ҙͷ ύε্ʹ ͕ଘࡏɻͦͷ ্ʹ͸ඞͣ ͕ଘࡏ͢ΔɻΑͬͯ ͸ Λdominate͢Δɻ a b b c ⇒ a c r − c b r − b a a c 9
  6. Ex.3: dominator಺ͷશॱং ✴ ϧʔϓͷͳ͍શͯͷ ύεʹ͓͍ͯɺ ͷdominatorͷݱ ΕΔॱং͸ಉ͡Ͱ͋Δ ‣ ূ໌: Λ

    ͷdominatorͱͯ͠ɺϧʔϓͷͳ͍ύε(1) ͱ(2) ͕ଘࡏ͢ΔͱԾఆ͢Δɻ (1)ΑΓ ͔Β Λ௨Βͣʹ ʹ౸ୡͰ͖Δ͕ɺ͜Εͱ(2)ΑΓ ͕dominatorͰ͋Δ͜ͱʹໃ६ɻ ✴ ͜ΕʹΑͬͯdominatorͳ͍ͷશॱং͕ఆٛͰ͖Δ r − v v a, b v r − a − b − v r − b − a − v b a v a 11
  7. ఆٛ2 ✴ ͷimmediate dominator: ͷdominatorͰ͋ͬͯɺEx.3ͷશ ॱংͰ࠷΋ޙΖͷ΋ͷʢ ʹ͍ۙ΋ͷʣ ‣ ఆٛΑΓɺ Ҏ֎ʹ͍ͭͯҰҙʹଘࡏ͢Δ

    • ͱද͢ ‣ ಉ஋ͳఆٛ: ͷdominatorͰ͋ͬͯͦͷଞͷdominatorશ ͯʹdominate͞ΕΔ΋ͷ v v v r idom(v) v 12
  8. ۪௚ͳΞϧΰϦζϜ ✴ ͕ Λdominate Λফͨ͠άϥϑͰ ͔Β ʹ౸ୡෆೳ ✴ ͷΞϧΰϦζϜ 1.

    ֤௖఺Λফͨ͠άϥϑͰ ͔ΒdfsͳͲͰ౸ୡ൑ఆ͢Δ͜ ͱͰɺ ௨Γͷdominateؔ܎͕Θ͔Δ 2. ֤௖఺ʹ͍ͭͯɺ1Λ༻͍ͯimmediate dominatorΛٻΊ Δɻ͜Ε͸dominator಺Ͱͦͷଞͷdominatorશͯʹ dominate͞Ε͍ͯΔ΋ͷͰ͋Δ d v ⇔ d r v O(nm) r n2 17
  9. Lengauer-TarjanͷΞϧΰϦζϜ ✴ semidominatorͱ͍͏֓೦Λఆٛͯ͠ɺͦΕʹؔ͢Δ͍͢͝ ੑ࣭Λ࢖͍·͢ ✴ ΞϧΰϦζϜ֓ཁ 1. Λࠜͱ͢Δdfs໦Λ࡞ͬͯ๚Εͨॱʹ൪߸Λ;Δ 2. semidominatorΛٻΊΔʢdfsٯॱʣ

    3. semidominator͔Βimmediate dominatorΛٻΊΔͷʹ ඞཁͳ௖఺ΛٻΊΔʢdfsٯॱʣ 4. Immediate dominatorΛٻΊΔʢdfsॱʣ ✴ ܭࢉྔ͸ ɺ΋ͬͱؤுΔͱ r O(m log(n)) O(mα(m, n)) 18
  10. ࣮૷্ͷ஫ҙ ✴ root͔Β֤௖఺·Ͱͷύε্ͷminΛ؅ཧͰ͖ΔUnionFindΛ ࢖͍·͢ ‣ ৄ͘͠͸http://sigma425.hatenablog.com/entry/ 2015/12/07/185047 ✴ ΋ͱ΋ͱͷ௖఺൪߸͔dfsॱͷ൪߸͔͕ͪ͝Όͪ͝ΌʹͳΓ ͕ͪ

    ‣ ݸਓతʹ͸શ෦൪߸ৼΓ௚ͪ͠Ό͏΄͏͕ϥΫͰͨ͠ ✴ ࣮૷: https://knshnb.github.io/competitive_library/library/src/ Graph/DominatorTree.hpp.html ✴ ݁ߏେมͰͨ͠… 19
  11. ऴΘΓʹ ✴ “The fast algorithm is … but almost as

    easy to program as the other two algorithms, …” ‣Lengauer͞ΜTarjan͞Μਖ਼ؾ ͔ʁʁʁ 20