>

>
1x
go to beginning previous frame pause play next frame go to end

Diberikan sebuah graf, kita bisa menggunakan algoritma O(V+E) DFS (Depth-First-Search) atau BFS (Breadth-First-Search) untuk menjelajahi graf tersebut dan melihat fitur-fitur ataupun properti-properti yang ada dalam graf tersebut. Setiap algoritma penjelajahan graf memiliki karakteristik, fitur, dan efek samping tersendiri yang akan kita lihat dalam visualisasi ini.

Visualisasi ini kaya dengan berbagai variasi DFS dan BFS (semua berjalan dalam O(V+E)) seperti:
    1. Algoritma pengurutan topologikal (Versi DFS dan BFS/algoritma Kahn),
    2. Algoritma pengecekan bipartit (Versi DFS dan BFS),
    3. Algoritma pencari simpul artikulasi & jembatan,
    4. Algoritma-algoritma pencari Strongly-Connected Component (SCC)
      (versi Kosaraju dan Tarjan), dan
    5. Algoritma pengecek 2-SAT.

    Remarks: By default, we show e-Lecture Mode for first time (or non logged-in) visitor.
    If you are an NUS student and a repeat visitor, please login.

    🕑

    Ketika algoritma penjelajahan graf yang terpilih sedang berjalan, animasinya akan ditampilkan di sini.


    Kami menggunakan warna simpul+sisi (skema warna akan dijelaskan segera) dan seringkali ada teks tambahan di bawah simpul (dalam warna merah) untuk menyorot perubahan yang terjadi.

    Seluruh algoritma-algoritma penjelajahan graf dapat dijalankan pada graf terarah (ini merupakan pengaturan default, di mana setiap sisi memiliki anak panah untuk menunjukkan arahnya), tetapi algoritma Pengecekan Graf Bipartit dan algoritma penemuan Simpul Potong & Jembatan memerlukan graf tak terarah (konversi dilakukan secara otomatis oleh visualisasi ini).


    Pro-tip 1: Since you are not logged-in, you may be a first time visitor (or not an NUS student) who are not aware of the following keyboard shortcuts to navigate this e-Lecture mode: [PageDown]/[PageUp] to go to the next/previous slide, respectively, (and if the drop-down box is highlighted, you can also use [→ or ↓/← or ↑] to do the same),and [Esc] to toggle between this e-Lecture mode and exploration mode.

    🕑

    There are two different sources for specifying an input graph:

    1. Edit Graph: You can draw a new graph or edit an example unweighted directed graph as the input graph (to draw bidirectional edge (u, v), you can draw two directed edges u → v and v → u).
    2. Example Graphs: You can select from the list of our selected example graphs to get you started.

    Pro-tip 2: We designed this visualization and this e-Lecture mode to look good on 1366x768 resolution or larger (typical modern laptop resolution in 2021). We recommend using Google Chrome to access VisuAlgo. Go to full screen mode (F11) to enjoy this setup. However, you can use zoom-in (Ctrl +) or zoom-out (Ctrl -) to calibrate this.

    🕑

    Jika anda tiba di Kuliah Maya ini tanpa pertama mengjelajahi/menguasai konsep Tumpukan Biner dan terutama Pohon Biner Terurut, kami menyarankan agar anda mengeksplorasi mereka dulu, karena menjelajahi sebuah struktur Pohon (Biner) jauh lebih mudah daripada menjelajahi sebuah graf umum.


    Quiz: Mini pre-requisite check. What are the Pre-/In-/Post-order traversal of the binary tree shown (root = vertex 0), left and right child are as drawn?

    Post = 4, 3, 2, 1, 0
    Pre = 0, 2, 4, 3, 1
    In = 4, 2, 3, 0, 1
    Pre = 0, 1, 2, 3, 4
    Post = 1, 3, 4, 2, 0
    In = 1, 0, 3, 2, 4

    Pro-tip 3: Other than using the typical media UI at the bottom of the page, you can also control the animation playback using keyboard shortcuts (in Exploration Mode): Spacebar to play/pause/replay the animation, / to step the animation backwards/forwards, respectively, and -/+ to decrease/increase the animation speed, respectively.

    🕑

    Kita biasanya mulai dari simpul yang paling penting dari sebuah pohon (biner): Simpul akar.


    Jika pohon yang diberikan tidak 'berakar' (lihat gambar contoh), kita bisa ambil satu simpul apa saja (contohnya, simpul 0 di gambar contoh) dan menunjuknya sebagai akar. Jika kita membayangkan semua sisi-sisi adalah tali-tali dengan panjang yang sama, maka setelah "secara virtual mengangkat akar yang ditunjuk keatas" dan membiarkan gravitasi menarik sisanya kebawah, kita akan mendapat pohon berakar yang terarah (kebawah) — lihat slide berikutnya.


    Catatan: Secara teknis, transformasi ini dilakukan dengan menjalankan DFS(0) yang akan kita eksplorasi segera.

    🕑

    Dalam sebuah pohon biner, kita hanya mempunyai paling banyak dua pilihan tetanga: Dari simpul sekarang, kita bisa pergi ke sub-pohon kiri dulu atau pergi ke sub-pohon kanan dulu. Kita juga mempunyai opsi untuk mengunjungi simpul sekarang sebelum atau sesudah mengunjungi satu (atau kedua) sub-pohon.


    Ini menghasilkan beberapa penjelajahan klasik: pre-order (kunjungi simpul sekarang, kunjungi sub-pohon kirinya, kunjungi sub-pohon kanannya), in-order (kiri, sekarang, kanan), dan post-order (kiri, kanan, sekarang).


    Diskusi: Apakah anda menyadari bahwa ada tiga lagi kombinasi penjelajahan pohon biner yang memungkinkan? Apa sajakah mereka?

    🕑

    The content of this interesting slide (the answer of the usually intriguing discussion point from the earlier slide) is hidden and only available for legitimate CS lecturer worldwide. This mechanism is used in the various flipped classrooms in NUS.


    If you are really a CS lecturer (or an IT teacher) (outside of NUS) and are interested to know the answers, please drop an email to stevenhalim at gmail dot com (show your University staff profile/relevant proof to Steven) for Steven to manually activate this CS lecturer-only feature for you.


    FAQ: This feature will NOT be given to anyone else who is not a CS lecturer.

    🕑

    Didalam pohon biner, atau didalam struktur pohon pada umumnya, tidak ada siklus (tidak-trivial) yang berurusan dengan 3 atau lebih simpul yang berbeda yang perlu kita khawatirkan (kita tidak menganggap siklus trivial yang berurusan dengan sisi-sisi dua-arah yang bisa diurus dengan mudah — lihat tiga slide selanjutnya).

    🕑

    Dalam graf umum, kita tidak memiliki gagasan tentang simpul akar. Melainkan, kita perlu memilih satu simpul yang dikhususkan untuk menjadi titik mula dari penjelajahan, yaitu simpul sumber s.


    Kita juga mempunyai 0, 1, ..., k tetangga dari sebuah simpul daripada hanya ≤ 2.


    Kita mungin (atau sebenarnya sangat mungkin) memiliki siklus(-siklus) dalam graf umum kita daripada pohon yang tidak-bersiklus,
    baik itu adalah siklus yang trivial seperti u → v → u atau yang tidak-trivial seperti a → b → c → a.


    Tetapi jangan takut, penjelajahan graf adalah masalah mudah dengan dua algoritma klasik: DFS dan BFS.

    🕑

    Salah satu algoritma penjelajahan graf yang paling dasar adalah O(V+E) Depth-First Search (DFS).


    DFS membutuhkan satu parameter masukan: Vertex sumber s.


    DFS adalah salah satu algoritma graf yang paling mendasar, jadi tolong gunakan waktu untuk mengerti semua langkah-langkah kunci dari algoritma ini.

    🕑

    mazeAnalogi terdekat dengan perilaku DFS adalah untuk mengimaginasikan sebuah maze dengan hanya satu pintu masuk dan satu pitu keluar. Anda berada pada pintu masuk dan mau mengeksplorasi maze untuk mencapai pintu keluar. Tentu saja anda tidak bisa membelah diri anda menjadi lebih dari satu.


    Tanya pertanyaan-pertanyaan reflektif ini sebelum melanjutkan: Apa yang akan anda lakukan jika ada opsi-opsi bercabang didepan anda? Bagaiamana untuk menghindari berjalan dalam siklus? Bagaimana cara menandai jalur anda sendiri? Petunjuk: Anda membutuhkan sebuah kapur, batu-batu (atau penanda lainnya) dan sebuah tali (yang panjang).

    🕑

    Seperti namanya, DFS dimulai dari sebuah simpul sumber s yang dibedakan dan menggunakan rekursi (sebuah tumpukan implisit) untuk mengatur urutan pengunjungan sedalam mungkin sebelum mundur (backtracking).


    Jika DFS ada di simpul u dan DFS memiliki X tetangga, DFS akan memilih tetangga pertama V1 (biasanya simpul dengan nomor simpul terkecil), secara rekursif mengeksplorasi semua simpul-simpul yang terjangkau dari simpul V1, dan pada akhirnya mundur (backtrack) ke simpul u. DFS akan lalu melakukan hal yang sama ke tetanga-tetangga lainnya sampai DFS selesai menjelajahi tetangga terakhir VX dan semua simpul-simpul yang terjangkau dari sana.


    Penjelasan yang penuh teks ini akan lebih jelas dengan animasi DFS nantinya.

    🕑

    Jika grafnya bersiklus, strategi 'coba-semua' sebelumnya bisa membuat DFS berjalan dalam siklus.


    Jadi bentuk dasar dari DFS menggunakan sebuah larik status[u] dengan ukuran V simpul untuk menentukan diantara dua kondisi biner: Apakah simpul u telah dikunjungi atau belum dikunjungi. Hanya jika simpul u masih belum dikunjungi, maka DFS bisa mengunjungi simpul u.


    Ketika DFS kehabisan opsi, maka DFS mundur kembali (backtrack) ke simpul sebelumnya (p[u], lihat slide berikut) saat rekrusinya kembali (unwinds).

    🕑

    DFS uses another array p[u] of size V vertices to remember the parent/predecessor/previous of each vertex u along the DFS traversal path.


    The predecessor of the source vertex, i.e., p[s] is set to -1 to say that the source vertex has no predecessor (as the lowest vertex number is vertex 0).


    The sequence of vertices from a vertex u that is reachable from the source vertex s back to s forms the DFS spanning tree. We color these tree edges with red color.

    🕑

    Untuk saat ini, abaikan status[u] = explored ekstra di pseudocode yang sedang ditampilkan dan keberadaan sisi-sisi biru dan abu-abu dalam visualisasi (akan dijelaskan segera).


    Tanpa basa-basi lagi, mari eksekusi DFS(0) pada graf contoh default untuk Kuliah Maya ini (CP3 Figure 4.1). Recap DFS Example


    Versi dasar dari DFS yang dipresentasikan sejauh ini sudah cukup untuk kebanyakan kasus-kasus sederhana.

    🕑

    Kompleksitas waktu dari DFS adalah O(V+E) karena:

    1. Setiap simpul hanya dikunjungi sekali karena DFS hanya akan secara rekursif menjelajahi sebuah simpul u jika status[u] = unvisited — O(V)
    2. Setiap kali sebuah simpul dikunjungi, semua k tetangganya akan dieksplorasi dan oleh karena itu setelah semua simpul-simpul dikunjungi, kita telah memeriksa semua E sisi-sisi — (O(E) karena jumlah total tetangga-tetangga dari setiap simpul sama dengan E).
    🕑

    Kompleksitas waktu O(V+E) dari DFS hanya bisa dicapai jika kita dapat mengunjungi semua k simpul-simpul tetangga dari sebuah simpul dalam waktu O(k).


    Quiz: Which underlying graph data structure support that operation?

    Adjacency Matrix
    Adjacency List
    Edge List


    Diskusi: Kenapa?

    🕑

    The content of this interesting slide (the answer of the usually intriguing discussion point from the earlier slide) is hidden and only available for legitimate CS lecturer worldwide. This mechanism is used in the various flipped classrooms in NUS.


    If you are really a CS lecturer (or an IT teacher) (outside of NUS) and are interested to know the answers, please drop an email to stevenhalim at gmail dot com (show your University staff profile/relevant proof to Steven) for Steven to manually activate this CS lecturer-only feature for you.


    FAQ: This feature will NOT be given to anyone else who is not a CS lecturer.

    🕑

    Algoritma penjelajahan graf dasar yang lain adalah O(V+E) Breadth-First Search (BFS).


    Sama seperti DFS, BFS juga membutuhkan satu parameter masukan: Simpul sumber s.


    DFS dan BFS memiliki kekuatan-kekuatan dan kelemahan-kelemahan masing-masing. Penting untuk mempelajari keduanya dan mengaplikasikan algoritma penjelajahan graf yang tepat pada situasi yang tepat.

    🕑

    rippleBayangkan sebuah kumpulan air tenang dan anda melempar sebuah batu kedalamnya. Lokasi pertama dimana batu tersebut mengenai permukaan air adalah posisi dari simpul sumber dan efek riak sepanjang permukaan air seperti pola penjelajahan BFS.

    🕑

    BFS sangat mirip dengan DFS yang sudah didiskusikan sebelumnya, tetapi dengan beberapa perbedaan.


    BFS dimulai dari sebuah simpul sumber s tetapi BFS menggunakan sebuah antrean untuk mengatur urutan visitasi selebar mungkin sebelum masuk lebih dalam.


    BFS juga menggunakan sebuah larik Boolean dengan ukuran V simpul-simpul untuk membedakan antara dua kondisi: simpul-simpul yang sudah dikunjungi dan yang belum dikunjungi (kita tidak akan menggunakan BFS untuk mendeteksi sisi(-sisi) belakang (back) seperti DFS).


    Dalam visualisasi ini, kita juga menunjukkan bahwa dimulai dengan simpul sumber s yang sama dalam sebuah graf tidak-berbobot, pohon perentang (spanning tree) BFS dari grafnya sama dengan pohon perentang SSSPnya.

    🕑

    Tanpa basa-basi lagi, mari eksekusi BFS(5) pada graf contoh default untuk Kuliah Maya ini (CP3 Figure 4.3). Recap BFS Example.


    Sadari bahwa penjelajahan Kesamping-dulu (Breadth-first) karena penggunaan struktur data FIFO: Antrean?

    🕑

    Kompleksitas waktu dari BFS adalah O(V+E) karena:

    1. Setiap simpul hanya dikunjungi sekali karena setiap simpul cuma bisa masuk ke dalam antrean sekali — O(V)
    2. Setiap kali sebuah simpul di dequeue dari antrean, semua k tetangganya akan dieksplorasi dan oleh karena itu setelah semua simpul-simpul dikunjungi, kita telah memeriksa semua E sisi-sisi — (O(E) karena jumlah total tetangga-tetangga dari setiap vertex sama dengan E).

    Sama seperti DFS, kompleksitas waktu O(V+E) ini hanya mungkin jika kita menggunakan struktur data graf Daftar Adjacency (Adjacency List) — alasan yang sama dengan analisa DFS.

    🕑

    So far, we can use DFS/BFS to solve a few graph traversal problem variants:

    1. Reachability test,
    2. Actually printing the traversal path,
    3. Identifying/Counting/Labeling Connected Components (CCs) of undirected graphs,
    4. Detecting if a graph is cyclic,
    5. Topological Sort (only on DAGs),

    For most data structures and algorithms courses, the applications of DFS/BFS are up to these few basic ones only, although DFS/BFS can do much more...

    🕑

    If you are asked to test whether a vertex s and a (different) vertex t in a graph are reachable, i.e., connected directly (via a direct edge) or indirectly (via a simple, non cyclic, path), you can call the O(V+E) DFS(s) (or BFS(s)) and check if status[t] = visited.


    Example 1: s = 0 and t = 4, run DFS(0) and notice that status[4] = visited.
    Example 2: s = 0 and t = 7, run DFS(0) and notice that status[7] = unvisited.

    🕑

    Remember that we set p[v] = u every time we manage to extend DFS/BFS traversal from vertex u to vertex v — a tree edge in the DFS/BFS spanning tree. Thus, we can use following simple recursive function to print out the path stored in array p. Possible follow-up discussion: Can you write this in iterative form? (trivial)

    method backtrack(u)
    if (u == -1) stop
    backtrack(p[u]);
    output vertex u

    To print out the path from a source vertex s to a target vertex t in a graph, you can call O(V+E) DFS(s) (or BFS(s)) and then O(V) backtrack(t). Example: s = 0 and t = 4, you can call DFS(0) and then backtrack(4). Elaborate

    🕑

    We can enumerate all vertices that are reachable from a vertex s in an undirected graph (as the example graph shown above) by simply calling O(V+E) DFS(s) (or BFS(s)) and enumerate all vertex v that has status[v] = visited.


    Example: s = 0, run DFS(0) and notice that status[{0,1,2,3,4}] = visited so they are all reachable vertices from vertex 0, i.e., they form one Connected Component (CC).

    🕑

    We can use the following pseudo-code to count the number of CCs:

    CC = 0
    for all u in V, set status[u] = unvisited
    for all u in V
    if (status[u] == unvisited)
    ++CC // we can use CC counter number as the CC label
    DFS(u) // or BFS(u), that will flag its members as visited
    output CC // the answer is 3 for the example graph above, i.e.
    // CC 0 = {0,1,2,3,4}, CC 1 = {5}, CC 2 = {6,7,8}

    You can modify the DFS(u)/BFS(u) code a bit if you want to use it to label each CC with the identifier of that CC.

    🕑

    Quiz: What is the time complexity of Counting the Number of CCs algorithm?

    It is still O(V+E)
    Trick question, the answer is none of the above, it is O(_____)
    Calling O(V+E) DFS/BFS V times, so O(V*(V+E)) = O(V^2 + VE)


    Diskusi: Kenapa?

    🕑

    The content of this interesting slide (the answer of the usually intriguing discussion point from the earlier slide) is hidden and only available for legitimate CS lecturer worldwide. This mechanism is used in the various flipped classrooms in NUS.


    If you are really a CS lecturer (or an IT teacher) (outside of NUS) and are interested to know the answers, please drop an email to stevenhalim at gmail dot com (show your University staff profile/relevant proof to Steven) for Steven to manually activate this CS lecturer-only feature for you.


    FAQ: This feature will NOT be given to anyone else who is not a CS lecturer.

    🕑

    Kita sebenarnya bisa meng-augmentasi DFS dasar lebih jauh untuk memberikan wawasan lebih tentang graf yang sedang dibahas.


    Dalam visualisasi ini, kami menggunakan warna biru untuk menyorot sisi(-sisi) kembali (back edge) dari pohon perentang DFS. Keberadaan satu saja sisi kembali menunjukkan bahwa (komponen) graf yang sedang dieksplorasi adalah bersiklus ketika ketidakadaannya menunjukkan bahwa setidaknya komponen yang terhubung dengan vertex sumber dari graf yang sedang dijelajahi adalah tidak-bersiklus.

    🕑

    Sisi belakang (Back edge) bisa dideteksi dengan memodifikasi larik status[u] untuk menyimpan tiga keadaan berbeda:

    1. belum dikunjungi: sama seperti sebelumnya, DFS belum mencapai simpul u sebelumnya,
    2. dieksplorasi: DFS telah mengunjungi simpul u, tetapi setidaknya satu tetangga dari simpul u belum dikunjungi (DFS akan pergi kedalam-dulu ke tetangga itu terlebih dahulu),
    3. sudah dikunjungi: sekarang definisi yang lebih kuat: semua tetangga dari simpul u juga sudah dikunjungi dan DFS baru mau mundur (backtrack) dari simpul u ke simpul p[u].

    Jika DFS sekarang berada di simpul x dan mengeksplorasi sisi x → y dan menjumpai status[y] = dieksplorasi, kita bisa mendeklarasikan x → y sebagai sisi belakang (back edge) (sebuah siklus ditemukan karena kita sebelumnya ada di simpul y (maka status[y] = dieksplorasi), pergi ke dalam ke tetangga dari y dan selanjutnya, tetapi sekarang kita ada di simpul x yang terjangkau dari y tetapi simpul x kembali menunjuk ke simpul y).

    🕑

    The edges in the graph that are not tree edge(s) nor back edge(s) are colored grey. They are called forward or cross edge(s) and currently have limited use (not elaborated).


    Now try DFS(0) on the example graph above with this new understanding, especially about the 3 possible status of a vertex (unvisited/normal black circle, explored/blue circle, visited/orange circle) and back edge. Edge 2 → 1 will be discovered as a back edge as it is part of cycle 1 → 3 → 2 → 1 (as vertex 2 is `explored' to vertex 1 which is currently `explored') (similarly with Edge 6 → 4 as part of cycle 4 → 5 → 7 → 6 → 4).


    Note that if edges 2 → 1 and 6 → 4 are reversed to 1 → 2 and 4 → 6, then the graph is correctly classified as acyclic as edge 3 → 2 and 4 → 6 go from `explored' to `fully visited'. If we only use binary states: `unvisited' vs `visited', we cannot distinguish these two cases.

    🕑

    There is another DFS (and also BFS) application that can be treated as 'simple': Performing Topological Sort(ing) of a Directed Acyclic Graph (DAG) — see example above.


    Topological sort of a DAG is a linear ordering of the DAG's vertices in which each vertex comes before all vertices to which it has outbound edges.


    Every DAG (can be checked with DFS earlier) has at least one but possibly more topological sorts/ordering.


    One of the main purpose of (at least one) topological sort of a DAG is for Dynamic Programming (DP) technique. For example, this topological sorting process is used internally in DP solution for SSSP on DAG.

    🕑

    Kita dapat menggunakan antara O(V+E) DFS atau BFS untuk melakukan Pengurutan Topologis dari sebuah Graf Terarah Tidak-bersiklus (Directed Acyclic Graph, DAG).


    Versi DFS membutuhkan hanya satu baris tambahan dibandingkan dengan DFS normal dan pada dasarnya adalah penjelajahan post-order dari graf tersebut. Coba Toposort (DFS) pada DAG contoh.


    Versi BFS berdasarkan ide simpul-simpul tanpa sisi masuk (incoming edge) dan juga disebut sebagai algoritma Kahn. Coba Toposort (BFS/Kahn's) pada DAG contoh.

    🕑

    Pada saat ini, anda telah melihat DFS/BFS dan apa yang DFS/BFS bisa selesaikan (dengan hanya perubahan-perubahan kecil). Ada beberapa aplikasi-aplikasi tingkat lanjut yang membutuhkan lebih banyak perubahan-perubahan dan kami akan membiarkan murid-murid tingkat lanjut untuk mengeksplorasi mereka sendiri:

    1. Pengecekan Graf Bipartit (varian DFS dan BFS),
    2. Menemukan Articulation Points (Cut Vertices) dan Bridges dari sebuah Graf Tidak-terarah (DFS saja),
    3. Menemukan Strongly Connected Components (SCCs) dari sebuah Graf Terarah (algoritma Tarjan dan Kosaraju), dan
    4. Algoritma Pengecekan 2-SAT(isfiability).

    Iklan: Detil-detilnya sudah ditulis di buku Competitive Programming.

    🕑

    Kita bisa menggunakan O(V+E) DFS atau BFS (keduanya bekerja dengan mirip) untuk mengecek apakah sebuah graf yang diberikan adalah graf bipartit dengan memberi warna secara selang-seling (oranye dan biru dalam visualisasi ini) pada simpul-simpul yang berhubungan dan melaporkan 'non-bipartit' apabila kita terpaksa memberi warna yang sama pada dua simpul yang berhubungan atau 'bipartit' bila kita berhasil memberi melakukan proses 'pewarnaan dengan 2 warna saja'. Coba DFS_Checker atau BFS_Checker pada Graf Bipartit contoh.


    Graf Bipartit memiliki aplikasi-aplikasi yang berguna di (masalah Pencocok Graf (Bipartit).


    Perlu dicatat bahwa Graf-Graf Bipartit biasanya hanya didefinisikan untuk graf tak terarah dan visualisasi di halaman ini akan mengubah graf terarah masukan menjadi graf tak terarah secara otomatis sebelum melanjutkan. Langkah ini bersifat permanen dan tidak dapat dibatalkan, sehingga anda harus menggambar ulang graf terarah masukkan anda untuk hal-hal lainnya.

    🕑

    Kita dapat memodifikasi (tetapi sayangnya, tidak dengan mudah) algoritma DFS O(V+E) menjadi algoritma untuk mencari simpul-simpul artikulasi & jembatan dari sebuah graf tak terarah.


    Sebuah Simpul Potong (Cut Vertex), atau Titik Artikulasi (Articulation Point), adalah simpul dari sebuah graf tak terarah yang apabila simpul tersebut dihapuskan dari graf yang ada akan mengakibatkan graf tersebut menjadi tak terhubung. Demikian pula, sebuah jembatan (bridge) adalah sebuah sisi dari graf tak terarah yang kalau dihapus akan mengakibatkan graf tersebut menjadi tak terhubung.

    Perlu dicatat bahwa algoritma pencari Simpul Potong & Jembatan ini hanya bekerja untuk graf-graf tak berarah dan visualisasi di halaman ini akan mengubah graf terarah masukan menjadi graf tak terarah secara otomatis sebelum melanjutkan. Langkah ini bersifat permanen dan tidak dapat dibatalkan, sehingga anda harus menggambar ulang graf 
    terarah masukkan anda untuk hal-hal lainnya. Anda bisa mencoba Find Cut Vertices & Bridges pada graf contoh diatas.

    🕑

    Kita dapat memodifikasi (tetapi sayangnya, tidak dengan mudah) algoritma O(V+EDFS menjadi algoritma untuk mencari Komponen-komponen yang Terhubung Kuat (Strongly Connected Components, SCCs) dari sebuah graf terarah G.


    Sebuah SCC dari graf terarah G didefinisikan sebagai sub-graf S dari G dimana untuk tiap dua simpul u dan v dalam S, simpul u dapat mengunjungi simpul v secara langsung atau melalui sebuah jalur, dan vertex v juga bisa mengunjungi simpul u secara langsung atau melalui sebuah jalur.


    Ada dua algoritma yang diketahui bisa menemukan SCCs dari sebuah Graf Terarah: Kosaraju dan Tarjan. Keduanya tersedia di visualisasi ini. Coba Kosaraju's Algorithm dan/atau Tarjan's Algorithm pada graf terarah contoh diatas.

    🕑

    Kami juga memiliki algoritma pengecekan 2-SAT. Diberikan sebuah instance dari masalah 2-Satisfiability (2-SAT) dalam bentuk konjungsi klausa-klausa: (klausa1) ^ (klausa2) ^ ... ^ (klausan) dan setiap klausa ditulis dalam bentuk disjungtif (maksimal 2 variabel vara v varb), tentukan apakah kita bisa memberikan nilai True (Benar)/False (Salah) ke variabel-variabel tersebut sehingga instance 2-SAT tersebut dapat menjadi true (benar), atau dengan kata lain dapat dipenuhi (satisfiable).


    Ternyata, setiap klausa (a v b) dapat diubah menjadi empat simpul a, bukan a, b, dan bukan b dengan dua sisi (not a → b) dan (not b → a). Maka kita memiliki graf berarah. Jika ada setidaknya satu variabel dan negasinya dalam sebuah SCC (Strongly Connected Component) dari graf tersebut, kita tahu bahwa tidaklah mungkin untuk memenuhi instance 2-SAT ini.


    Setelah pemodelan graf tersebut, kita dapat menjalankan algoritma pencarian SCC (Algoritma Kosaraju atau Tarjan) untuk menentukan apakah instance 2-SAT tersebut dapat dipenuhi.

    🕑

    Quiz: Which Graph Traversal Algorithm is Better?

    Always BFS
    It Depends on the Situation
    Both are Equally Good
    Always DFS


    Diskusi: Kenapa?

    🕑

    The content of this interesting slide (the answer of the usually intriguing discussion point from the earlier slide) is hidden and only available for legitimate CS lecturer worldwide. This mechanism is used in the various flipped classrooms in NUS.


    If you are really a CS lecturer (or an IT teacher) (outside of NUS) and are interested to know the answers, please drop an email to stevenhalim at gmail dot com (show your University staff profile/relevant proof to Steven) for Steven to manually activate this CS lecturer-only feature for you.


    FAQ: This feature will NOT be given to anyone else who is not a CS lecturer.

    🕑

    Ada banyak hal yang masih bisa kita lakukan dengan hanya DFS dan/atau BFS...

    🕑

    Ada pertanyaan-pertanyaan menarik tentang dua algoritma penjelajahan graf: DFS+BFS dan varian-varian dari masalah-masalah penjelajahan graf, silahkan latihan pada modul Penjelajahan Graf (tidak perlu login).


    Tetapi, untuk pengguna yang teregistrasi, anda sebaiknya login dan pergi ke Halaman Latihan Utama untuk secara resmi menyelesaikan modul ini dan prestasi tersebut akan disimpan di akun pengguna anda.

    🕑

    We also have a few programming problems that somewhat requires the usage of DFS and/or BFS: Kattis - reachableroads and Kattis - breakingbad.


    Try to solve them and then try the many more interesting twists/variants of this simple graph traversal problem and/or algorithm.


    You are allowed to use/modify our implementation code for DFS/BFS Algorithms:
    dfs_cc.cpp/bfs.cpp
    dfs_cc.java/bfs.java
    dfs_cc.py/bfs.py
    dfs_cc.ml/bfs.ml

    🕑

    The content of this interesting slide (the answer of the usually intriguing discussion point from the earlier slide) is hidden and only available for legitimate CS lecturer worldwide. This mechanism is used in the various flipped classrooms in NUS.


    If you are really a CS lecturer (or an IT teacher) (outside of NUS) and are interested to know the answers, please drop an email to stevenhalim at gmail dot com (show your University staff profile/relevant proof to Steven) for Steven to manually activate this CS lecturer-only feature for you.


    FAQ: This feature will NOT be given to anyone else who is not a CS lecturer.


    You have reached the last slide. Return to 'Exploration Mode' to start exploring!

    Note that if you notice any bug in this visualization or if you want to request for a new visualization feature, do not hesitate to drop an email to the project leader: Dr Steven Halim via his email address: stevenhalim at gmail dot com.

    🕑

    Visualisation Scale

    Toggle V. Number for 0.5x

    Edit Graph

    Graf-Graf Contoh

    Depth-First Search

    Breadth-First Search

    Pengurutan Topologikal

    Cek Graf Bipartit

    Simpul Artikulasi dan Jembatan

    Algoritma-algoritma SCC

    Pengecek 2-SAT

    >

    1.0x (Default)

    0.5x (Minimal Details)

    CP3 4.1

    CP3 4.3

    CP3 4.4 DAG

    CP3 4.9

    CP3 4.17 DAG

    CP3 4.18 DAG, Bipartite

    CP3 4.19 Bipartite

    Large Graph

    Large, Cycles

    s =

    Lakukan

    s =

    Lakukan

    Versi DFS

    versi BFS (Algoritma Kahn)

    Versi DFS

    Versi BFS

    Algoritma Kosaraju

    Algoritma Tarjan

    Jumlah klausa. =
    Jumlah variabel. =

    LAKUKAN

    Tentang Tim Syarat Guna Kebijakan Privasi

    Tentang

    Initially conceived in 2011 by Associate Professor Steven Halim, VisuAlgo aimed to facilitate a deeper understanding of data structures and algorithms for his students by providing a self-paced, interactive learning platform.

    Featuring numerous advanced algorithms discussed in Dr. Steven Halim's book, 'Competitive Programming' — co-authored with Dr. Felix Halim and Dr. Suhendry Effendy — VisuAlgo remains the exclusive platform for visualizing and animating several of these complex algorithms even after a decade.

    While primarily designed for National University of Singapore (NUS) students enrolled in various data structure and algorithm courses (e.g., CS1010/equivalent, CS2040/equivalent (including IT5003), CS3230, CS3233, and CS4234), VisuAlgo also serves as a valuable resource for inquisitive minds worldwide, promoting online learning.

    Initially, VisuAlgo was not designed for small touch screens like smartphones, as intricate algorithm visualizations required substantial pixel space and click-and-drag interactions. For an optimal user experience, a minimum screen resolution of 1366x768 is recommended. However, since April 2022, a mobile (lite) version of VisuAlgo has been made available, making it possible to use a subset of VisuAlgo features on smartphone screens.

    VisuAlgo remains a work in progress, with the ongoing development of more complex visualizations. At present, the platform features 24 visualization modules.

    Equipped with a built-in question generator and answer verifier, VisuAlgo's "online quiz system" enables students to test their knowledge of basic data structures and algorithms. Questions are randomly generated based on specific rules, and students' answers are automatically graded upon submission to our grading server. As more CS instructors adopt this online quiz system worldwide, it could effectively eliminate manual basic data structure and algorithm questions from standard Computer Science exams in many universities. By assigning a small (but non-zero) weight to passing the online quiz, CS instructors can significantly enhance their students' mastery of these basic concepts, as they have access to an almost unlimited number of practice questions that can be instantly verified before taking the online quiz. Each VisuAlgo visualization module now includes its own online quiz component.

    VisuAlgo has been translated into three primary languages: English, Chinese, and Indonesian. Additionally, we have authored public notes about VisuAlgo in various languages, including Indonesian, Korean, Vietnamese, and Thai:

    id, kr, vn, th.

    Tim

    Pemimpin & Penasihat Proyek (Jul 2011-sekarang)
    Associate Professor Steven Halim, School of Computing (SoC), National University of Singapore (NUS)
    Dr Felix Halim, Senior Software Engineer, Google (Mountain View)

    Murid-Murid S1 Peniliti 1
    CDTL TEG 1: Jul 2011-Apr 2012: Koh Zi Chun, Victor Loh Bo Huai

    Murid-Murid Proyek Tahun Terakhir/UROP 1
    Jul 2012-Dec 2013: Phan Thi Quynh Trang, Peter Phandi, Albert Millardo Tjindradinata, Nguyen Hoang Duy
    Jun 2013-Apr 2014 Rose Marie Tan Zhao Yun, Ivan Reinaldo

    Murid-Murid S1 Peniliti 2
    CDTL TEG 2: May 2014-Jul 2014: Jonathan Irvin Gunawan, Nathan Azaria, Ian Leow Tze Wei, Nguyen Viet Dung, Nguyen Khac Tung, Steven Kester Yuwono, Cao Shengze, Mohan Jishnu

    Murid-Murid Proyek Tahun Terakhir/UROP 2
    Jun 2014-Apr 2015: Erin Teo Yi Ling, Wang Zi
    Jun 2016-Dec 2017: Truong Ngoc Khanh, John Kevin Tjahjadi, Gabriella Michelle, Muhammad Rais Fathin Mudzakir
    Aug 2021-Apr 2023: Liu Guangyuan, Manas Vegi, Sha Long, Vuong Hoang Long, Ting Xiao, Lim Dewen Aloysius

    Murid-Murid S1 Peniliti 3
    Optiver: Aug 2023-Oct 2023: Bui Hong Duc, Oleh Naver, Tay Ngan Lin

    Murid-Murid Proyek Tahun Terakhir/UROP 3
    Aug 2023-Apr 2024: Xiong Jingya, Radian Krisno, Ng Wee Han

    List of translators who have contributed ≥ 100 translations can be found at statistics page.

    Ucapan Terima Kasih
    NUS CDTL gave Teaching Enhancement Grant to kickstart this project.

    For Academic Year 2023/24, a generous donation from Optiver will be used to further develop VisuAlgo.

    Syarat Guna

    VisuAlgo is generously offered at no cost to the global Computer Science community. If you appreciate VisuAlgo, we kindly request that you spread the word about its existence to fellow Computer Science students and instructors. You can share VisuAlgo through social media platforms (e.g., Facebook, YouTube, Instagram, TikTok, Twitter, etc), course webpages, blog reviews, emails, and more.

    Data Structures and Algorithms (DSA) students and instructors are welcome to use this website directly for their classes. If you capture screenshots or videos from this site, feel free to use them elsewhere, provided that you cite the URL of this website (https://visualgo.net) and/or the list of publications below as references. However, please refrain from downloading VisuAlgo's client-side files and hosting them on your website, as this constitutes plagiarism. At this time, we do not permit others to fork this project or create VisuAlgo variants. Personal use of an offline copy of the client-side VisuAlgo is acceptable.

    Please note that VisuAlgo's online quiz component has a substantial server-side element, and it is not easy to save server-side scripts and databases locally. Currently, the general public can access the online quiz system only through the 'training mode.' The 'test mode' offers a more controlled environment for using randomly generated questions and automatic verification in real examinations at NUS.

    List of Publications

    This work has been presented at the CLI Workshop at the ICPC World Finals 2012 (Poland, Warsaw) and at the IOI Conference at IOI 2012 (Sirmione-Montichiari, Italy). You can click this link to read our 2012 paper about this system (it was not yet called VisuAlgo back in 2012) and this link for the short update in 2015 (to link VisuAlgo name with the previous project).

    Bug Reports or Request for New Features

    VisuAlgo is not a finished project. Associate Professor Steven Halim is still actively improving VisuAlgo. If you are using VisuAlgo and spot a bug in any of our visualization page/online quiz tool or if you want to request for new features, please contact Associate Professor Steven Halim. His contact is the concatenation of his name and add gmail dot com.

    Kebijakan Privasi

    Version 1.2 (Updated Fri, 18 Aug 2023).

    Since Fri, 18 Aug 2023, we no longer use Google Analytics. Thus, all cookies that we use now are solely for the operations of this website. The annoying cookie-consent popup is now turned off even for first-time visitors.

    Since Fri, 07 Jun 2023, thanks to a generous donation by Optiver, anyone in the world can self-create a VisuAlgo account to store a few customization settings (e.g., layout mode, default language, playback speed, etc).

    Additionally, for NUS students, by using a VisuAlgo account (a tuple of NUS official email address, student name as in the class roster, and a password that is encrypted on the server side — no other personal data is stored), you are giving a consent for your course lecturer to keep track of your e-lecture slides reading and online quiz training progresses that is needed to run the course smoothly. Your VisuAlgo account will also be needed for taking NUS official VisuAlgo Online Quizzes and thus passing your account credentials to another person to do the Online Quiz on your behalf constitutes an academic offense. Your user account will be purged after the conclusion of the course unless you choose to keep your account (OPT-IN). Access to the full VisuAlgo database (with encrypted passwords) is limited to Prof Halim himself.

    For other CS lecturers worldwide who have written to Steven, a VisuAlgo account (your (non-NUS) email address, you can use any display name, and encrypted password) is needed to distinguish your online credential versus the rest of the world. Your account will have CS lecturer specific features, namely the ability to see the hidden slides that contain (interesting) answers to the questions presented in the preceding slides before the hidden slides. You can also access Hard setting of the VisuAlgo Online Quizzes. You can freely use the material to enhance your data structures and algorithm classes. Note that there can be other CS lecturer specific features in the future.

    For anyone with VisuAlgo account, you can remove your own account by yourself should you wish to no longer be associated with VisuAlgo tool.