{"id":34636,"date":"2024-11-01T09:30:21","date_gmt":"2024-11-01T09:30:21","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=34636"},"modified":"2024-11-01T11:40:24","modified_gmt":"2024-11-01T11:40:24","slug":"javascript-coding-test-course-kevin-bacons-six-degrees-of-separation","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/34636\/","title":{"rendered":"JavaScript Coding Test Course, Kevin Bacon&#8217;s Six Degrees of Separation"},"content":{"rendered":"<div class=\"post\">\n<p>Hello! In this post, we will explore &#8220;The Six Degrees of Kevin Bacon,&#8221; one of the topics in the JavaScript coding test, and I will detail the process of solving the problem. In this lecture, we will learn how to design and implement algorithms, as well as how to efficiently use JavaScript syntax and functions.<\/p>\n<h2>1. What is the Six Degrees of Kevin Bacon?<\/h2>\n<p>The Six Degrees of Kevin Bacon is a theory that describes the relationships among movie actors. According to this theory, the relationship between two people can be achieved through a maximum of six connections. In other words, if actor A is connected to actor B, and B has another connection to C, it is believed that there is a relationship between A and C within six degrees.<\/p>\n<h2>2. Problem Description<\/h2>\n<p>This problem is based on graph theory. Given a list of actors and their relationships, the task is to find the links between a specific actor and another actor and calculate how many degrees of connection exist between them.<\/p>\n<h3>Problem Definition<\/h3>\n<pre>\n    Represent the given list of actors and their relationships as a graph,\n    and write a function that calculates and returns the number of steps \n    between the two given actors.\n    \n    <strong>Constraints:<\/strong>\n    - Each actor is represented as a string, and two actors are directly connected\n      if they appeared in the same movie together.\n    - The edges of the graph are undirected, allowing us to use BFS \n      (Breadth-First Search) to find the shortest path.\n    \n    Example input:\n    actors = [\n        ['A', 'B'],\n        ['B', 'C'],\n        ['C', 'D'],\n        ['D', 'E'],\n        ['A', 'E']\n    ]\n    startActor = 'A'\n    targetActor = 'D'\n    \n    Example output:\n    3 (A -> B -> C -> D)\n    <\/pre>\n<h2>3. Solution Method<\/h2>\n<p>To solve this problem, we will proceed with the following steps.<\/p>\n<h3>3.1. Selecting Data Structure<\/h3>\n<p>First, we need a data structure to store the relationships among all actors. We will represent this relationship using a <code>Map<\/code> or <code>Object<\/code> as a graph. Each actor will be a key, and the corresponding value will be an array of actors they have appeared with.<\/p>\n<h3>3.2. Constructing the Graph<\/h3>\n<p>Using the given list of actors, we will add the relationships between actors to the selected data structure.<\/p>\n<h3>3.3. Finding the Shortest Path<\/h3>\n<p>We&#8217;ll use the BFS algorithm to find the shortest path between the starting actor and the target actor. BFS is a useful algorithm for solving shortest distance problems, as it explores nodes level by level and guarantees the shortest path.<\/p>\n<h2>4. JavaScript Implementation<\/h2>\n<p>Now, based on what has been described above, let&#8217;s implement it in JavaScript code.<\/p>\n<pre>\n    function findShortestPath(actors, startActor, targetActor) {\n        \/\/ Create the graph\n        const graph = {};\n        \n        for (const [actorA, actorB] of actors) {\n            if (!graph[actorA]) graph[actorA] = [];\n            if (!graph[actorB]) graph[actorB] = [];\n            graph[actorA].push(actorB);\n            graph[actorB].push(actorA);\n        }\n        \n        \/\/ BFS algorithm\n        const queue = [[startActor, 0]];\n        const visited = new Set();\n        visited.add(startActor);\n        \n        while (queue.length > 0) {\n            const [currentActor, steps] = queue.shift();\n            \n            \/\/ If the target actor is reached\n            if (currentActor === targetActor) {\n                return steps;\n            }\n            \n            for (const neighbor of graph[currentActor]) {\n                if (!visited.has(neighbor)) {\n                    visited.add(neighbor);\n                    queue.push([neighbor, steps + 1]);\n                }\n            }\n        }\n        \n        \/\/ No connection\n        return -1;\n    }\n    \n    \/\/ Example execution\n    const actors = [['A', 'B'], ['B', 'C'], ['C', 'D'], ['D', 'E'], ['A', 'E']];\n    const startActor = 'A';\n    const targetActor = 'D';\n    \n    console.log(findShortestPath(actors, startActor, targetActor)); \/\/ Output: 3\n    <\/pre>\n<h2>5. Code Analysis<\/h2>\n<p>Through the above code, we have constructed a graph based on the relationships between the given actors and implemented a method to find the shortest path using BFS. Let&#8217;s analyze this part in more detail.<\/p>\n<h3>5.1. Graph Implementation<\/h3>\n<p>The graph is structured as an object, where the key is the actor&#8217;s name and the value is an array of connected actors. We update the bidirectional connections directly by adding the associated actors.<\/p>\n<h3>5.2. Functioning of BFS<\/h3>\n<p>BFS is implemented using a queue. We add the starting actor to the queue and include visited actors in a Set to avoid duplicate visits. We continuously explore until the queue is empty, returning the number of steps taken when the target actor is found.<\/p>\n<h3>5.3. Time Complexity<\/h3>\n<p>The time complexity of this algorithm is O(V + E), where V represents the number of actors and E represents the number of edges. This ensures efficient performance, allowing for quick results even with large data sets.<\/p>\n<h2>6. Conclusion<\/h2>\n<p>In this post, we examined the process of solving an algorithm problem using &#8220;The Six Degrees of Kevin Bacon.&#8221; We covered the entire process from algorithm design to data structure selection, implementation, and analysis. Such problems are frequently featured in actual coding tests, so it is important to practice and master them.<\/p>\n<p>In the future, I will continue to post about various algorithms and problem-solving methods. Always remember to practice coding, and feel free to leave any questions in the comments!<\/p>\n<h2>7. Additional Reference Materials<\/h2>\n<ul>\n<li><a href=\"https:\/\/en.wikipedia.org\/wiki\/Six_degrees_of_kevin_bacon\">Six Degrees of Kevin Bacon (Wikipedia)<\/a><\/li>\n<li><a href=\"https:\/\/en.wikipedia.org\/wiki\/Breadth-first_search\">Breadth-First Search (Wikipedia)<\/a><\/li>\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\">JavaScript Documentation (MDN)<\/a><\/li>\n<\/ul>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Hello! In this post, we will explore &#8220;The Six Degrees of Kevin Bacon,&#8221; one of the topics in the JavaScript coding test, and I will detail the process of solving the problem. In this lecture, we will learn how to design and implement algorithms, as well as how to efficiently use JavaScript syntax and functions. &hellip; <a href=\"https:\/\/atmokpo.com\/w\/34636\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;JavaScript Coding Test Course, Kevin Bacon&#8217;s Six Degrees of Separation&#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-34636","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, Kevin Bacon&#039;s Six Degrees of Separation - \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\/34636\/\" \/>\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, Kevin Bacon&#039;s Six Degrees of Separation - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Hello! In this post, we will explore &#8220;The Six Degrees of Kevin Bacon,&#8221; one of the topics in the JavaScript coding test, and I will detail the process of solving the problem. In this lecture, we will learn how to design and implement algorithms, as well as how to efficiently use JavaScript syntax and functions. &hellip; \ub354 \ubcf4\uae30 &quot;JavaScript Coding Test Course, Kevin Bacon&#8217;s Six Degrees of Separation&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/34636\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:30:21+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:40:24+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\/34636\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/34636\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"JavaScript Coding Test Course, Kevin Bacon&#8217;s Six Degrees of Separation\",\"datePublished\":\"2024-11-01T09:30:21+00:00\",\"dateModified\":\"2024-11-01T11:40:24+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/34636\/\"},\"wordCount\":586,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Javascript Coding Test\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/34636\/\",\"url\":\"https:\/\/atmokpo.com\/w\/34636\/\",\"name\":\"JavaScript Coding Test Course, Kevin Bacon's Six Degrees of Separation - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:30:21+00:00\",\"dateModified\":\"2024-11-01T11:40:24+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/34636\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/34636\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/34636\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JavaScript Coding Test Course, Kevin Bacon&#8217;s Six Degrees of Separation\"}]},{\"@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, Kevin Bacon's Six Degrees of Separation - \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\/34636\/","og_locale":"ko_KR","og_type":"article","og_title":"JavaScript Coding Test Course, Kevin Bacon's Six Degrees of Separation - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Hello! In this post, we will explore &#8220;The Six Degrees of Kevin Bacon,&#8221; one of the topics in the JavaScript coding test, and I will detail the process of solving the problem. In this lecture, we will learn how to design and implement algorithms, as well as how to efficiently use JavaScript syntax and functions. &hellip; \ub354 \ubcf4\uae30 \"JavaScript Coding Test Course, Kevin Bacon&#8217;s Six Degrees of Separation\"","og_url":"https:\/\/atmokpo.com\/w\/34636\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:30:21+00:00","article_modified_time":"2024-11-01T11:40:24+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\/34636\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/34636\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"JavaScript Coding Test Course, Kevin Bacon&#8217;s Six Degrees of Separation","datePublished":"2024-11-01T09:30:21+00:00","dateModified":"2024-11-01T11:40:24+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/34636\/"},"wordCount":586,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Javascript Coding Test"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/34636\/","url":"https:\/\/atmokpo.com\/w\/34636\/","name":"JavaScript Coding Test Course, Kevin Bacon's Six Degrees of Separation - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:30:21+00:00","dateModified":"2024-11-01T11:40:24+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/34636\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/34636\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/34636\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"JavaScript Coding Test Course, Kevin Bacon&#8217;s Six Degrees of Separation"}]},{"@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\/34636","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=34636"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/34636\/revisions"}],"predecessor-version":[{"id":34637,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/34636\/revisions\/34637"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=34636"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=34636"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=34636"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}