{"id":34352,"date":"2024-11-01T09:27:12","date_gmt":"2024-11-01T09:27:12","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=34352"},"modified":"2024-11-01T10:57:35","modified_gmt":"2024-11-01T10:57:35","slug":"c-coding-test-course-try-2","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/34352\/","title":{"rendered":"C++ Coding Test Course, Try"},"content":{"rendered":"<div class=\"post\">\n<h2>1. Introduction<\/h2>\n<p>\n        In today&#8217;s lecture, we will take an in-depth look at the Trie data structure using the C++ programming language,<br \/>\n        and solve algorithm problems utilizing this structure. A Trie is an optimized data structure for storing and<br \/>\n        searching strings, useful for solving various problems such as dictionary lookups, auto-completion, and prefix searches.\n    <\/p>\n<h2>2. Introduction to Trie Data Structure<\/h2>\n<p>\n        A Trie stores characters of strings at each node, and the paths between nodes represent the prefixes of specific strings.<br \/>\n        This data structure allows for efficient string searching, with a basic time complexity of O(m),<br \/>\n        where m is the length of the string to be searched.\n    <\/p>\n<h3>2.1 Components of a Trie<\/h3>\n<p>\n        The basic components of a Trie are as follows:\n    <\/p>\n<ul>\n<li>\n<strong>Node:<\/strong> Each node contains a character and child nodes.\n        <\/li>\n<li>\n<strong>Insert:<\/strong> Adds a new string to the Trie.\n        <\/li>\n<li>\n<strong>Search:<\/strong> Searches for a specific string in the Trie.\n        <\/li>\n<li>\n<strong>Delete:<\/strong> Deletes a specific string from the Trie.\n        <\/li>\n<\/ul>\n<h3>2.2 Advantages and Disadvantages of a Trie<\/h3>\n<p>\n        The advantage of a Trie is that it makes prefix searches easy. However, a disadvantage is that it can use a lot<br \/>\n        of memory and can be complex to implement.\n    <\/p>\n<h2>3. Problem Definition<\/h2>\n<p>\n        The following is an algorithm problem.<br \/>\n        Please write a program that outputs all words with a specific prefix from the given list of strings.\n    <\/p>\n<h3>Problem Description<\/h3>\n<p>\n<strong>Input:<\/strong><br \/>\n        &#8211; Word list words: [&#8220;apple&#8221;, &#8220;app&#8221;, &#8220;application&#8221;, &#8220;bat&#8221;, &#8220;ban&#8221;, &#8220;band&#8221;]<br \/>\n        &#8211; Specific prefix prefix: &#8220;ap&#8221;<\/p>\n<p>        <strong>Output:<\/strong><br \/>\n        &#8211; Strings with the prefix &#8220;ap&#8221;: [&#8220;apple&#8221;, &#8220;app&#8221;, &#8220;application&#8221;]\n    <\/p>\n<h2>4. Problem Solving Process<\/h2>\n<h3>4.1 Defining the Trie Class<\/h3>\n<p>\n        First, we need to define a Trie node and implement the Trie class. Below is a basic implementation in C++.\n    <\/p>\n<pre>\n<code class=\"cpp\">\n#include <iostream>\n#include <vector>\n#include <string>\n#include <unordered_map>\n\nusing namespace std;\n\nclass TrieNode {\npublic:\n    unordered_map<char, trienode*=\"\"> children;\n    bool isEndOfWord;\n\n    TrieNode() : isEndOfWord(false) {}\n};\n\nclass Trie {\nprivate:\n    TrieNode* root;\n\npublic:\n    Trie() {\n        root = new TrieNode();\n    }\n\n    void insert(const string&amp; word) {\n        TrieNode* node = root;\n        for (char c : word) {\n            if (!node-&gt;children[c]) {\n                node-&gt;children[c] = new TrieNode();\n            }\n            node = node-&gt;children[c];\n        }\n        node-&gt;isEndOfWord = true;\n    }\n\n    void searchByPrefix(const string&amp; prefix, vector<string>&amp; result, string current, TrieNode* node) {\n        if (node-&gt;isEndOfWord) {\n            result.push_back(current);\n        }\n\n        for (const auto&amp; pair : node-&gt;children) {\n            searchByPrefix(prefix, result, current + pair.first, pair.second);\n        }\n    }\n\n    vector<string> getWordsWithPrefix(const string&amp; prefix) {\n        TrieNode* node = root;\n        vector<string> result;\n\n        for (char c : prefix) {\n            if (!node-&gt;children[c]) {\n                return result; \/\/ No words with the given prefix\n            }\n            node = node-&gt;children[c];\n        }\n\n        searchByPrefix(prefix, result, prefix, node);\n        return result;\n    }\n};\n<\/string><\/string><\/string><\/char,><\/unordered_map><\/string><\/vector><\/iostream><\/code>\n    <\/pre>\n<h3>4.2 Implementing the Main Function<\/h3>\n<p>\n        Now, let&#8217;s implement the main function to insert words into the Trie and search for words with the prefix.\n    <\/p>\n<pre>\n<code class=\"cpp\">\nint main() {\n    Trie trie;\n    vector<string> words = {\"apple\", \"app\", \"application\", \"bat\", \"ban\", \"band\"};\n\n    \/\/ Insert words into the trie\n    for (const string&amp; word : words) {\n        trie.insert(word);\n    }\n\n    \/\/ Prefix to search\n    string prefix = \"ap\";\n    vector<string> result = trie.getWordsWithPrefix(prefix);\n\n    \/\/ Print the result\n    cout &lt;&lt; \"Words with prefix '\" &lt;&lt; prefix &lt;&lt; \"': \";\n    for (const string&amp; word : result) {\n        cout &lt;&lt; word &lt;&lt; \" \";\n    }\n    cout &lt;&lt; endl;\n\n    return 0;\n}\n<\/string><\/string><\/code>\n    <\/pre>\n<h2>5. Code Execution Results<\/h2>\n<p>\n        When the above code is executed, the following results will be printed.<br \/>\n        All words corresponding to the given prefix &#8220;ap&#8221; will be output as a list.\n    <\/p>\n<pre>\n<code>\nWords with prefix 'ap': apple app application\n<\/code>\n    <\/pre>\n<h2>6. Conclusion<\/h2>\n<p>\n        In this lecture, we implemented the Trie data structure using C++ and solved the problem of searching for<br \/>\n        words with a specific prefix. Tries are very useful data structures for solving string-related algorithm problems,<br \/>\n        and can be used in various application areas. In future lectures,<br \/>\n        I hope to learn about various data structures and techniques that can serve as references for solving various<br \/>\n        algorithm problems. Thank you.\n    <\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>1. Introduction In today&#8217;s lecture, we will take an in-depth look at the Trie data structure using the C++ programming language, and solve algorithm problems utilizing this structure. A Trie is an optimized data structure for storing and searching strings, useful for solving various problems such as dictionary lookups, auto-completion, and prefix searches. 2. Introduction &hellip; <a href=\"https:\/\/atmokpo.com\/w\/34352\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;C++ Coding Test Course, Try&#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":[111],"tags":[],"class_list":["post-34352","post","type-post","status-publish","format-standard","hentry","category-c-coding-test-tutorials-2"],"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, Try - \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\/34352\/\" \/>\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, Try - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"1. Introduction In today&#8217;s lecture, we will take an in-depth look at the Trie data structure using the C++ programming language, and solve algorithm problems utilizing this structure. A Trie is an optimized data structure for storing and searching strings, useful for solving various problems such as dictionary lookups, auto-completion, and prefix searches. 2. Introduction &hellip; \ub354 \ubcf4\uae30 &quot;C++ Coding Test Course, Try&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/34352\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:27:12+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T10:57:35+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=\"3\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/34352\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/34352\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"C++ Coding Test Course, Try\",\"datePublished\":\"2024-11-01T09:27:12+00:00\",\"dateModified\":\"2024-11-01T10:57:35+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/34352\/\"},\"wordCount\":395,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"C++ Coding Test Tutorials\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/34352\/\",\"url\":\"https:\/\/atmokpo.com\/w\/34352\/\",\"name\":\"C++ Coding Test Course, Try - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:27:12+00:00\",\"dateModified\":\"2024-11-01T10:57:35+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/34352\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/34352\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/34352\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C++ Coding Test Course, Try\"}]},{\"@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, Try - \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\/34352\/","og_locale":"ko_KR","og_type":"article","og_title":"C++ Coding Test Course, Try - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"1. Introduction In today&#8217;s lecture, we will take an in-depth look at the Trie data structure using the C++ programming language, and solve algorithm problems utilizing this structure. A Trie is an optimized data structure for storing and searching strings, useful for solving various problems such as dictionary lookups, auto-completion, and prefix searches. 2. Introduction &hellip; \ub354 \ubcf4\uae30 \"C++ Coding Test Course, Try\"","og_url":"https:\/\/atmokpo.com\/w\/34352\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:27:12+00:00","article_modified_time":"2024-11-01T10:57:35+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":"3\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/34352\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/34352\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"C++ Coding Test Course, Try","datePublished":"2024-11-01T09:27:12+00:00","dateModified":"2024-11-01T10:57:35+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/34352\/"},"wordCount":395,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["C++ Coding Test Tutorials"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/34352\/","url":"https:\/\/atmokpo.com\/w\/34352\/","name":"C++ Coding Test Course, Try - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:27:12+00:00","dateModified":"2024-11-01T10:57:35+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/34352\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/34352\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/34352\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"C++ Coding Test Course, Try"}]},{"@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\/34352","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=34352"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/34352\/revisions"}],"predecessor-version":[{"id":34353,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/34352\/revisions\/34353"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=34352"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=34352"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=34352"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}