Design and Analysis of Algorithm Decrease and Conquer Algorithm. Aryo Pinandito, ST, M.MT – PTIIK Universitas Brawijaya. Decrease and Conquer. Mengurangi permasalahan menjadi lebih kecil pada permasalahan yang sama Selesaikan permasalahan yang lebih kecil tersebut
01 / 72Design and Analysis of Algorithm Decrease and Conquer Algorithm
1 / 17
Download Presentation
Design and Analysis of Algorithm Decrease and Conquer Algorithm
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.
Decrease and Conquer • Mengurangipermasalahanmenjadilebihkecilpadapermasalahan yang sama • Selesaikanpermasalahan yang lebihkeciltersebut • Kembangkanpermasalahan yang lebihkecilitusehinggamenyelesaikanpermasalahansebenarnya • Dapatdilakukandengandenganmetode top down atau bottom up
Variasi decrease and conquer • Mengurangidengansebuah constant (Decrease by a constant) • Ukurandarimasalahdikurangidenganfaktorkonstanta yang sama – biasanyadikurangisebanyakduapadasetiapiterasi • Polapenguranganukuranmasalahbervariasi/berbedaantaraiterasisatudengan yang lainnya
Decrease and Conquer • Decrease by a constant (usually by 1): • insertion sort • graph traversal algorithms (DFS and BFS) • topological sorting • algorithms for generating permutations, subsets • Decrease by a constant factor (usually by half) • binary search and bisection method • exponentiation by squaring • multiplication à la russe • Variable-size decrease • Euclid's algorithm • Selection by partition • Nim-like games • Biasanyamenggunakanalgoritmarekursif.
PermasalahanEksponensial • Permasalahan: Hitungxn • Brute Force: • Divide and conquer: • Decrease by one: • Decrease by constant factor: n-1 multiplications T(n) = 2 * T(n/2) + 1 = n-1 T(n) = T(n-1) + 1 = n-1 T(n) = T(n/a) + a-1 = (a-1) loga n = log2 n when a = 2
Insertion Sort dengan Divide and Conquer ProsedurMergedapatdigantidenganprosedurpenyisipansebuahelemen padatabel yang sudahterurut (lihatalgoritmaInsertion Sortversiiteratif).
a b c d e f g h Red edges are tree edges and black edges are back edges. Example: DFS traversal of undirected graph DFS traversal stack: DFS tree: a ab abf abfe abf ab abg abgc abgcd abgcdh abgcd … 1 2 6 7 a b c d e f g h 4 3 5 8
Notes on DFS • Time complexity of DFS is O(|V|). Why? • each edge (u, v) is explored exactly once, • All steps are constant time.
Breadth-first search (BFS) • Mengunjungi vertex-vertex grafikdenganberpindahkesemua vertex tetanggadari vertex yang terakhirdikunjungi • BFS menggunakan queue • Miripdengan level ke level daripohonmerentang • "Redraws"ataugambarulanggrafikdalambentuksepertipohon (dengan edges pohondan back edges untukgrafiktakberarah/undirected graph)
a b c d e f g h Red edges are tree edges and black edges are cross edges. Example of BFS traversal of undirected graph BFS traversal queue: BFS tree: a bef efg fg g ch hd d 1 2 6 8 a b c d e f g h 3 4 5 7