{"id":34602,"date":"2024-11-01T09:29:56","date_gmt":"2024-11-01T09:29:56","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=34602"},"modified":"2024-11-01T11:40:32","modified_gmt":"2024-11-01T11:40:32","slug":"javascript-coding-test-course-exploring-a-maze","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/34602\/","title":{"rendered":"JavaScript Coding Test Course, Exploring a Maze"},"content":{"rendered":"<p><body><\/p>\n<p>Hello! In this course, we will provide an in-depth explanation of an algorithm problem using JavaScript, specifically &#8220;Maze Exploration.&#8221; This is one of the frequently appearing problem types in coding tests, where the goal is to find a path from the starting point to the destination in a given maze. This problem can be solved using graph search algorithms such as BFS (Breadth-First Search) or DFS (Depth-First Search).<\/p>\n<h2>Problem Description<\/h2>\n<p><strong>Problem:<\/strong> Check if there is a path from the starting point (start) to the destination (end) in a given 2D array representing a maze. The path in the maze can follow &#8216;0&#8217; (a traversable space), while &#8216;1&#8217; (an obstacle) cannot be passed.<\/p>\n<p>For example, let&#8217;s assume the maze is as follows:<\/p>\n<pre>\n[\n    [0, 1, 0, 0, 0],\n    [0, 1, 0, 1, 0],\n    [0, 0, 0, 1, 0],\n    [0, 1, 0, 0, 0],\n    [0, 0, 0, 1, 0]\n]\n<\/pre>\n<p>The starting point is (0, 0) and the destination is (4, 4). In other words, we need to determine whether there exists a path from (0, 0) to (4, 4) while exploring the maze.<\/p>\n<h2>Input and Output<\/h2>\n<ul>\n<li><strong>Input:<\/strong> 2D array (maze), starting point (start), destination (end)<\/li>\n<li><strong>Output:<\/strong> Whether a path exists (true\/false)<\/li>\n<\/ul>\n<h2>Approach to Problem Solving<\/h2>\n<p>To solve this problem, we can use BFS (Breadth-First Search) or DFS (Depth-First Search) algorithms. BFS is suitable for finding the shortest path, but since we only need to check for the existence of a path in this problem, we can also solve it using DFS.<\/p>\n<h2>Algorithm Explanation<\/h2>\n<p>1. **Basic Setup**: The following process is needed to explore the maze.<\/p>\n<ol>\n<li>Add all nodes to be explored to the stack (for DFS).<\/li>\n<li>Mark explored nodes as visited to prevent duplicate exploration.<\/li>\n<li>Move in all possible directions (up, down, left, right) from the current position.<\/li>\n<li>If the target position is reached, return true.<\/li>\n<li>If all paths have been explored and the target is not reached, return false.<\/li>\n<\/ol>\n<h2>JavaScript Implementation<\/h2>\n<p>Now, let&#8217;s implement the above algorithm in JavaScript. Below is the specific code for the DFS algorithm for maze exploration:<\/p>\n<pre><code>\nfunction isPathExist(maze, start, end) {\n    const rows = maze.length;\n    const cols = maze[0].length;\n\n    \/\/ Movement direction array (up, down, left, right)\n    const directions = [\n        [-1, 0], \/\/ up\n        [1, 0],  \/\/ down\n        [0, -1], \/\/ left\n        [0, 1]   \/\/ right\n    ];\n\n    \/\/ Initialize stack and visited array\n    const stack = [start];\n    const visited = Array.from({ length: rows }, () => Array(cols).fill(false));\n    visited[start[0]][start[1]] = true;\n\n    \/\/ DFS exploration\n    while (stack.length > 0) {\n        const [x, y] = stack.pop();\n\n        \/\/ If the destination is reached\n        if (x === end[0] && y === end[1]) {\n            return true;\n        }\n\n        \/\/ Move in each direction\n        for (const [dx, dy] of directions) {\n            const newX = x + dx;\n            const newY = y + dy;\n\n            \/\/ Check range and visit status\n            if (newX >= 0 && newX < rows &#038;&#038; newY >= 0 && newY < cols &#038;&#038;\n                maze[newX][newY] === 0 &#038;&#038; !visited[newX][newY]) {\n                visited[newX][newY] = true;\n                stack.push([newX, newY]);\n            }\n        }\n    }\n\n    \/\/ If unreachable\n    return false;\n}\n\n\/\/ Test\nconst maze = [\n    [0, 1, 0, 0, 0],\n    [0, 1, 0, 1, 0],\n    [0, 0, 0, 1, 0],\n    [0, 1, 0, 0, 0],\n    [0, 0, 0, 1, 0]\n];\nconsole.log(isPathExist(maze, [0, 0], [4, 4])); \/\/ true\n<\/code><\/pre>\n<h2>Code Explanation<\/h2>\n<p>The above code implements the process of finding a path from the starting point to the destination in a given maze using DFS (Depth-First Search). The main steps are as follows:<\/p>\n<ol>\n<li><strong>Initial Setup:<\/strong> First, initialize the number of rows and columns in the maze and set the movement directions in an array. The directions we can move are up, down, left, and right.<\/li>\n<li><strong>Initialize Stack and Visited Array:<\/strong> Use a stack to explore paths for DFS, marking visited positions as 'true'.<\/li>\n<li><strong>DFS Iteration:<\/strong> Pop a position from the stack to get the current position and check if it is the destination. If the destination is reached, return true.<\/li>\n<li><strong>Check Move Possibility:<\/strong> Check all directions to confirm if the new position is within range, has no obstacles, and hasn\u2019t been visited before adding it to the stack.<\/li>\n<\/ol>\n<h2>Performance Analysis<\/h2>\n<p>The time complexity of this algorithm is O(V+E), where V is the number of vertices (i.e., all positions in the maze) and E is the number of edges (i.e., the number of possible movements from each position). In the worst case, we need to explore all positions, which is why this complexity is necessary. The space complexity is O(V) as space is required for the visited array.<\/p>\n<h2>Conclusion<\/h2>\n<p>In this lecture, we discussed how to solve the maze exploration problem using JavaScript. We learned basic code and techniques to check the existence of a path through the maze using the DFS algorithm. These types of problems frequently appear in coding tests, so practice various modified problems to build your confidence.<\/p>\n<p>In the next lecture, we will cover more complex maze exploration problems or other types of algorithm problems, so please look forward to it!<\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello! In this course, we will provide an in-depth explanation of an algorithm problem using JavaScript, specifically &#8220;Maze Exploration.&#8221; This is one of the frequently appearing problem types in coding tests, where the goal is to find a path from the starting point to the destination in a given maze. This problem can be solved &hellip; <a href=\"https:\/\/atmokpo.com\/w\/34602\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;JavaScript Coding Test Course, Exploring a 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":[141],"tags":[],"class_list":["post-34602","post","type-post","status-publish","format-standard","hentry","category-javascript-coding-test"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>JavaScript Coding Test Course, Exploring a 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\/34602\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JavaScript Coding Test Course, Exploring a Maze - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Hello! In this course, we will provide an in-depth explanation of an algorithm problem using JavaScript, specifically &#8220;Maze Exploration.&#8221; This is one of the frequently appearing problem types in coding tests, where the goal is to find a path from the starting point to the destination in a given maze. This problem can be solved &hellip; \ub354 \ubcf4\uae30 &quot;JavaScript Coding Test Course, Exploring a Maze&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/34602\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:29:56+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:40:32+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\/34602\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/34602\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"JavaScript Coding Test Course, Exploring a Maze\",\"datePublished\":\"2024-11-01T09:29:56+00:00\",\"dateModified\":\"2024-11-01T11:40:32+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/34602\/\"},\"wordCount\":603,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Javascript Coding Test\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/34602\/\",\"url\":\"https:\/\/atmokpo.com\/w\/34602\/\",\"name\":\"JavaScript Coding Test Course, Exploring a Maze - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:29:56+00:00\",\"dateModified\":\"2024-11-01T11:40:32+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/34602\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/34602\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/34602\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JavaScript Coding Test Course, Exploring a 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":"JavaScript Coding Test Course, Exploring a 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\/34602\/","og_locale":"ko_KR","og_type":"article","og_title":"JavaScript Coding Test Course, Exploring a Maze - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Hello! In this course, we will provide an in-depth explanation of an algorithm problem using JavaScript, specifically &#8220;Maze Exploration.&#8221; This is one of the frequently appearing problem types in coding tests, where the goal is to find a path from the starting point to the destination in a given maze. This problem can be solved &hellip; \ub354 \ubcf4\uae30 \"JavaScript Coding Test Course, Exploring a Maze\"","og_url":"https:\/\/atmokpo.com\/w\/34602\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:29:56+00:00","article_modified_time":"2024-11-01T11:40:32+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\/34602\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/34602\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"JavaScript Coding Test Course, Exploring a Maze","datePublished":"2024-11-01T09:29:56+00:00","dateModified":"2024-11-01T11:40:32+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/34602\/"},"wordCount":603,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Javascript Coding Test"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/34602\/","url":"https:\/\/atmokpo.com\/w\/34602\/","name":"JavaScript Coding Test Course, Exploring a Maze - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:29:56+00:00","dateModified":"2024-11-01T11:40:32+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/34602\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/34602\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/34602\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"JavaScript Coding Test Course, Exploring a 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\/34602","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=34602"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/34602\/revisions"}],"predecessor-version":[{"id":34603,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/34602\/revisions\/34603"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=34602"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=34602"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=34602"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}