{"id":33986,"date":"2024-11-01T09:22:45","date_gmt":"2024-11-01T09:22:45","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=33986"},"modified":"2024-11-01T10:54:25","modified_gmt":"2024-11-01T10:54:25","slug":"c-coding-test-course-exploring-the-maze","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/33986\/","title":{"rendered":"C# Coding Test Course, Exploring the Maze"},"content":{"rendered":"<p><body><\/p>\n<p>Hello! In this lecture, we will address the maze exploration problem as an example of a C# algorithm coding test. The maze exploration problem is very useful for understanding graph theory and the DFS (Depth-First Search) and BFS (Breadth-First Search) algorithms. In this course, we will define the problem, explain the input format, output format, and the solution algorithm step by step.<\/p>\n<h2>1. Problem Definition<\/h2>\n<p>The problem is to count the number of ways to reach the destination from the starting point in a given 2D array that forms a maze. The maze follows these rules:<\/p>\n<ul>\n<li>0 represents a navigable path.<\/li>\n<li>1 represents an impassable wall.<\/li>\n<\/ul>\n<p>For example, if the following maze is given:<\/p>\n<pre>\n0 1 0 0\n0 1 0 1\n0 0 0 0\n1 1 0 1\n<\/pre>\n<p>Our goal is to count all possible paths from (0,0) to (3,2) in this maze.<\/p>\n<h2>2. Input Format<\/h2>\n<p>The first line contains the height <code>n<\/code> and width <code>m<\/code> of the maze, separated by a space. From the second line, the maze is provided with 0 and 1 for <code>n<\/code> lines.<\/p>\n<h2>3. Output Format<\/h2>\n<p>Outputs the number of paths that can be taken to reach the destination from the starting point.<\/p>\n<h2>4. Approach<\/h2>\n<p>We will use BFS to solve this problem. BFS is a breadth-first search, suitable for finding the shortest path or paths meeting specific conditions in a given graph. The steps to solve the problem are as follows:<\/p>\n<ol>\n<li>Put the starting point of the maze into a queue and record its visit status in an array.<\/li>\n<li>Remove the current position from the queue and check possible positions to move up, down, left, and right.<\/li>\n<li>If the position to move to is a place that hasn&#8217;t been visited, add it to the queue and record its visit status.<\/li>\n<li>If the destination is reached, increment the path count.<\/li>\n<li>Repeat until all paths are explored.<\/li>\n<\/ol>\n<h2>5. C# Code Implementation<\/h2>\n<p>Now let&#8217;s implement this algorithm in C#. Below is the C# code for maze exploration.<\/p>\n<div class=\"example-code\">\n<pre>\nusing System;\nusing System.Collections.Generic;\n\nclass Program\n{\n    static int n, m;\n    static int[,] maze;\n    static bool[,] visited;\n    static int[] deltaRow = { -1, 1, 0, 0 };\n    static int[] deltaCol = { 0, 0, -1, 1 };\n    static int pathCount = 0;\n\n    static void Main()\n    {\n        \/\/ Input handling\n        string[] inputs = Console.ReadLine().Split(' ');\n        n = int.Parse(inputs[0]);\n        m = int.Parse(inputs[1]);\n        maze = new int[n, m];\n        visited = new bool[n, m];\n\n        for (int i = 0; i < n; i++)\n        {\n            string row = Console.ReadLine();\n            for (int j = 0; j < m; j++)\n            {\n                maze[i, j] = row[j] - '0'; \/\/ Convert '0' and '1' to integers\n            }\n        }\n\n        \/\/ Start BFS exploration\n        BFS(0, 0);\n        Console.WriteLine(\"Number of reachable paths: \" + pathCount);\n    }\n\n    static void BFS(int startRow, int startCol)\n    {\n        Queue<(int, int)> queue = new Queue<(int, int)>();\n        queue.Enqueue((startRow, startCol));\n        visited[startRow, startCol] = true;\n\n        while (queue.Count > 0)\n        {\n            var (currentRow, currentCol) = queue.Dequeue();\n\n            \/\/ Check for destination\n            if (currentRow == n - 1 && currentCol == m - 1)\n            {\n                pathCount++;\n                continue; \/\/ Continue exploring other paths\n            }\n\n            \/\/ Explore up, down, left, and right\n            for (int i = 0; i < 4; i++)\n            {\n                int newRow = currentRow + deltaRow[i];\n                int newCol = currentCol + deltaCol[i];\n\n                \/\/ Check range and movement feasibility\n                if (newRow >= 0 && newRow < n &#038;&#038; newCol >= 0 && newCol < m &#038;&#038; \n                    maze[newRow, newCol] == 0 &#038;&#038; !visited[newRow, newCol])\n                {\n                    visited[newRow, newCol] = true;\n                    queue.Enqueue((newRow, newCol));\n                }\n            }\n        }\n    }\n}\n<\/pre>\n<\/div>\n<p>The above code uses BFS to explore the maze and increments the path count every time it reaches the destination. This code explores all possible paths starting from the starting point (0, 0) to the destination (n-1, m-1).<\/p>\n<h2>6. Code Explanation<\/h2>\n<p>I will explain the main parts of the code in detail.<\/p>\n<h3>6.1. Input Handling<\/h3>\n<p>In the input part, we first read the size of the maze and initialize the 2D array <code>maze<\/code> accordingly. Each row is read and stored separated by 0s and 1s.<\/p>\n<h3>6.2. BFS Function<\/h3>\n<p>The <code>BFS<\/code> function checks if it can move in 4 directions from the current position using a queue. Here, we use the <code>deltaRow<\/code> and <code>deltaCol<\/code> arrays to calculate the indices when moving up, down, left, or right.<\/p>\n<h3>6.3. Path Counting<\/h3>\n<p>If we reach the destination, we increment <code>pathCount<\/code> and manage the exploration of other paths. BFS is a useful method for exploring all possible paths.<\/p>\n<h2>7. Performance Analysis<\/h2>\n<p>The time complexity of this algorithm is O(N * M). This is because each cell is checked once. However, in the worst case, it may require additional time due to the need to explore all paths.<\/p>\n<h2>8. Taking a Step Further After Problem Solving<\/h2>\n<p>Now that you understand the basic concept of maze exploration, consider taking the next step to calculate the shortest path in the maze using Dijkstra's algorithm or the A* algorithm. Learn how each algorithm works and challenge yourself to solve optimization problems using them.<\/p>\n<h2>9. Conclusion<\/h2>\n<p>In this lecture, we learned how to solve the maze exploration problem using C#. We examined how the BFS algorithm works and what processes were followed to solve the problem. I hope this lecture helps improve your algorithm skills, and continue to prepare for more coding tests.<\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello! In this lecture, we will address the maze exploration problem as an example of a C# algorithm coding test. The maze exploration problem is very useful for understanding graph theory and the DFS (Depth-First Search) and BFS (Breadth-First Search) algorithms. In this course, we will define the problem, explain the input format, output format, &hellip; <a href=\"https:\/\/atmokpo.com\/w\/33986\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;C# Coding Test Course, Exploring the Maze&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[90],"tags":[],"class_list":["post-33986","post","type-post","status-publish","format-standard","hentry","category-c-coding-test-tutorials"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>C# Coding Test Course, Exploring the Maze - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/atmokpo.com\/w\/33986\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"C# Coding Test Course, Exploring the Maze - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Hello! In this lecture, we will address the maze exploration problem as an example of a C# algorithm coding test. The maze exploration problem is very useful for understanding graph theory and the DFS (Depth-First Search) and BFS (Breadth-First Search) algorithms. In this course, we will define the problem, explain the input format, output format, &hellip; \ub354 \ubcf4\uae30 &quot;C# Coding Test Course, Exploring the Maze&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/33986\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:22:45+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T10:54:25+00:00\" \/>\n<meta name=\"author\" content=\"root\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:site\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:label1\" content=\"\uae00\uc4f4\uc774\" \/>\n\t<meta name=\"twitter:data1\" content=\"root\" \/>\n\t<meta name=\"twitter:label2\" content=\"\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04\" \/>\n\t<meta name=\"twitter:data2\" content=\"4\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/33986\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/33986\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"C# Coding Test Course, Exploring the Maze\",\"datePublished\":\"2024-11-01T09:22:45+00:00\",\"dateModified\":\"2024-11-01T10:54:25+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/33986\/\"},\"wordCount\":590,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"C# Coding Test Tutorials\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/33986\/\",\"url\":\"https:\/\/atmokpo.com\/w\/33986\/\",\"name\":\"C# Coding Test Course, Exploring the Maze - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:22:45+00:00\",\"dateModified\":\"2024-11-01T10:54:25+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/33986\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/33986\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/33986\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C# Coding Test Course, Exploring the Maze\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/atmokpo.com\/w\/#website\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/atmokpo.com\/w\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ko-KR\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"contentUrl\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"width\":400,\"height\":400,\"caption\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\"},\"image\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/bebubo4\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\",\"name\":\"root\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"caption\":\"root\"},\"sameAs\":[\"http:\/\/atmokpo.com\/w\"],\"url\":\"https:\/\/atmokpo.com\/w\/author\/root\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"C# Coding Test Course, Exploring the Maze - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/atmokpo.com\/w\/33986\/","og_locale":"ko_KR","og_type":"article","og_title":"C# Coding Test Course, Exploring the Maze - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Hello! In this lecture, we will address the maze exploration problem as an example of a C# algorithm coding test. The maze exploration problem is very useful for understanding graph theory and the DFS (Depth-First Search) and BFS (Breadth-First Search) algorithms. In this course, we will define the problem, explain the input format, output format, &hellip; \ub354 \ubcf4\uae30 \"C# Coding Test Course, Exploring the Maze\"","og_url":"https:\/\/atmokpo.com\/w\/33986\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:22:45+00:00","article_modified_time":"2024-11-01T10:54:25+00:00","author":"root","twitter_card":"summary_large_image","twitter_creator":"@bebubo4","twitter_site":"@bebubo4","twitter_misc":{"\uae00\uc4f4\uc774":"root","\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04":"4\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/33986\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/33986\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"C# Coding Test Course, Exploring the Maze","datePublished":"2024-11-01T09:22:45+00:00","dateModified":"2024-11-01T10:54:25+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/33986\/"},"wordCount":590,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["C# Coding Test Tutorials"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/33986\/","url":"https:\/\/atmokpo.com\/w\/33986\/","name":"C# Coding Test Course, Exploring the Maze - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:22:45+00:00","dateModified":"2024-11-01T10:54:25+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/33986\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/33986\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/33986\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"C# Coding Test Course, Exploring the Maze"}]},{"@type":"WebSite","@id":"https:\/\/atmokpo.com\/w\/#website","url":"https:\/\/atmokpo.com\/w\/","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","description":"","publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/atmokpo.com\/w\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ko-KR"},{"@type":"Organization","@id":"https:\/\/atmokpo.com\/w\/#organization","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","url":"https:\/\/atmokpo.com\/w\/","logo":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/","url":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","contentUrl":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","width":400,"height":400,"caption":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8"},"image":{"@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/bebubo4"]},{"@type":"Person","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7","name":"root","image":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","caption":"root"},"sameAs":["http:\/\/atmokpo.com\/w"],"url":"https:\/\/atmokpo.com\/w\/author\/root\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/33986","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/comments?post=33986"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/33986\/revisions"}],"predecessor-version":[{"id":33987,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/33986\/revisions\/33987"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=33986"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=33986"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=33986"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}