1 / 72

Design and Analysis of Algorithm Decrease and Conquer Algorithm

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

malina
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.

E N D

Presentation Transcript


  1. Design and Analysis of AlgorithmDecrease and Conquer Algorithm Aryo Pinandito, ST, M.MT – PTIIK UniversitasBrawijaya

  2. Decrease and Conquer • Mengurangipermasalahanmenjadilebihkecilpadapermasalahan yang sama • Selesaikanpermasalahan yang lebihkeciltersebut • Kembangkanpermasalahan yang lebihkecilitusehinggamenyelesaikanpermasalahansebenarnya • Dapatdilakukandengandenganmetode top down atau bottom up

  3. Variasi decrease and conquer • Mengurangidengansebuah constant (Decrease by a constant) • Ukurandarimasalahdikurangidenganfaktorkonstanta yang sama – biasanyadikurangisebanyakduapadasetiapiterasi • Polapenguranganukuranmasalahbervariasi/berbedaantaraiterasisatudengan yang lainnya

  4. 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.

  5. 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

  6. Sorting in Decrease and Conquer Insertion Sort, Selection Sort

  7. Insertion Sort

  8. Insertion Sort dengan Divide and Conquer ProsedurMergedapatdigantidenganprosedurpenyisipansebuahelemen padatabel yang sudahterurut (lihatalgoritmaInsertion Sortversiiteratif).

  9. Divide, Conquer, and Solve

  10. Merge

  11. Kompleksitas Insertion Sort

  12. Selection Sort

  13. Pseudocode Selection Sort

  14. Contoh Selection Sort

  15. Kompleksitas Selection Sort

  16. Searching Depth-First Search (DFS) Breadth-First Search (BFS) Binary Search Tree (BST)

  17. Depth-First Search (DFS) • Mengunjungi vertex-vertex padagrafikdenganselalubergerakdari vertex yang terakhirdikunjungike vertex yang belumdikunjungi, lakukan backtrack apabilatidakada vertex tetangga yang belumdikunjungi. • Rekursifataumenggunakan stack • Vertex di-push ke stack ketikadicapaiuntukpertamakalinya • Sebuah vertex di-pop off ataudilepasdari stack ketika vertex tersebutmerupakan vertex akhir (ketikatidakada vertex tetangga yang belumdikunjungi) • "Redraws" ataugambarulanggrafikdalambentuksepertipohon (dengan edges pohondan back edges untukgrafiktakberarah/undirected graph)

  18. Pseudo code DFS

  19. 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

  20. 1 • DFS : 1, 2, 4, 8, 5, 6, 3, 7 2 3 4 5 6 7 8

  21. 1 • DFS : 1, 2, 3, 6, 8, 4, 5, 7 2 3 4 5 6 7 8

  22. 1 • DFS : 1, 2, 5, 8, 9, 6, 3, 7, 4 2 3 4 5 6 7 8 9

  23. Notes on DFS • Time complexity of DFS is O(|V|). Why? • each edge (u, v) is explored exactly once, • All steps are constant time.

  24. 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)

  25. 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

  26. Pseudo code BFS

  27. Notes on BFS • Asumsi: setiapsimpuldapatmembangkitkan b buahsimpulbaru. • Misalkansolusiditemukanpadaaraske-d • Jumlahmaksimumseluruhsimpul: 1+b+b2 +b3 +...+bd =(bd+1 –1)/(b–1) T(n) = O(bd) • Kompleksitasruangalgoritma BFS = samadengankompleksitaswaktunya, karenasemuasimpuldaundaripohonharusdisimpan di dalammemoriselama proses pencarian.

  28. Breadth First Search (grafik berarah) 2 4 8 s 5 7 3 6 9

  29. Breadth First Search 1 2 2 4 8 Shortest pathfrom s 0 s 5 7 3 6 9 Undiscovered Queue: s Discovered Top of queue Finished

  30. Breadth First Search 1 2 4 8 0 s 5 7 3 3 6 9 1 Undiscovered Queue: s 2 Discovered Top of queue Finished

  31. Breadth First Search 1 2 4 8 0 5 s 5 7 1 3 6 9 1 Undiscovered Queue: s 2 3 Discovered Top of queue Finished

  32. Breadth First Search 1 2 4 8 0 s 5 7 1 3 6 9 1 Undiscovered Queue: 2 3 5 Discovered Top of queue Finished

  33. Breadth First Search 1 2 2 4 4 8 0 s 5 7 1 3 6 9 1 Undiscovered Queue: 2 3 5 Discovered Top of queue Finished

  34. Breadth First Search 1 2 2 4 8 5 already discovered:don't enqueue 0 s 5 7 1 3 6 9 1 Undiscovered Queue: 2 3 5 4 Discovered Top of queue Finished

  35. Breadth First Search 1 2 2 4 8 0 s 5 7 1 3 6 9 1 Undiscovered Queue: 2 3 5 4 Discovered Top of queue Finished

  36. Breadth First Search 1 2 2 4 8 0 s 5 7 1 3 6 9 1 Undiscovered Queue: 3 5 4 Discovered Top of queue Finished

  37. Breadth First Search 1 2 2 4 8 0 s 5 7 1 3 6 6 9 1 2 Undiscovered Queue: 3 5 4 Discovered Top of queue Finished

  38. Breadth First Search 1 2 2 4 8 0 s 5 7 1 3 6 9 1 2 Undiscovered Queue: 3 5 4 6 Discovered Top of queue Finished

  39. Breadth First Search 1 2 2 4 8 0 s 5 7 1 3 6 9 1 2 Undiscovered Queue: 5 4 6 Discovered Top of queue Finished

  40. Breadth First Search 1 2 2 4 8 0 s 5 7 1 3 6 9 1 2 Undiscovered Queue: 5 4 6 Discovered Top of queue Finished

  41. Breadth First Search 1 2 2 4 8 0 s 5 7 1 3 6 9 1 2 Undiscovered Queue: 4 6 Discovered Top of queue Finished

  42. Breadth First Search 1 2 3 2 4 8 8 0 s 5 7 1 3 6 9 1 2 Undiscovered Queue: 4 6 Discovered Top of queue Finished

  43. Breadth First Search 1 2 3 2 4 8 0 s 5 7 1 3 6 9 1 2 Undiscovered Queue: 4 6 8 Discovered Top of queue Finished

  44. Breadth First Search 1 2 3 2 4 8 0 7 s 5 7 1 3 3 6 9 1 2 Undiscovered Queue: 6 8 Discovered Top of queue Finished

  45. Breadth First Search 1 2 3 2 4 8 0 s 5 7 1 3 3 6 9 9 3 1 2 Undiscovered Queue: 6 8 7 Discovered Top of queue Finished

  46. Breadth First Search 1 2 3 2 4 8 0 s 5 7 1 3 3 6 9 3 1 2 Undiscovered Queue: 6 8 7 9 Discovered Top of queue Finished

  47. Breadth First Search 1 2 3 2 4 8 0 s 5 7 1 3 3 6 9 3 1 2 Undiscovered Queue: 8 7 9 Discovered Top of queue Finished

  48. Breadth First Search 1 2 3 2 4 8 0 s 5 7 1 3 3 6 9 3 1 2 Undiscovered Queue: 7 9 Discovered Top of queue Finished

  49. Breadth First Search 1 2 3 2 4 8 0 s 5 7 1 3 3 6 9 3 1 2 Undiscovered Queue: 7 9 Discovered Top of queue Finished

  50. Breadth First Search 1 2 3 2 4 8 0 s 5 7 1 3 3 6 9 3 1 2 Undiscovered Queue: 7 9 Discovered Top of queue Finished

More Related