{"id":34248,"date":"2024-11-01T09:26:00","date_gmt":"2024-11-01T09:26:00","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=34248"},"modified":"2024-11-01T10:58:00","modified_gmt":"2024-11-01T10:58:00","slug":"c-coding-test-course-understanding-time-complexity-notation-2","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/34248\/","title":{"rendered":"C++ Coding Test Course, Understanding Time Complexity Notation"},"content":{"rendered":"<p><body><\/p>\n<h2>1. Introduction: The Importance of Algorithms<\/h2>\n<p>\n        In modern software development, algorithms are an essential component. Especially in coding tests, they serve as a crucial criterion for evaluating candidates&#8217; problem-solving abilities. Therefore, enhancing algorithmic knowledge and problem-solving skills is very important. In this article, we will practice C++ coding through actual coding test problems and learn about time complexity notation in detail.\n    <\/p>\n<h2>2. Problem: Sum of Two Numbers<\/h2>\n<p>\n        The problem is as follows: Given an integer array <code>nums<\/code> and an integer <code>target<\/code>, implement a function <code>twoSum<\/code> that returns the indices of the two numbers such that they add up to <code>target<\/code>. Note that there is exactly one solution for each input, and you may not use the same element twice.\n    <\/p>\n<p>\n<strong>Function Signature:<\/strong><br \/>\n<code>vector<int> twoSum(vector<int>&amp; nums, int target);<\/code>\n<\/p>\n<h3>Example<\/h3>\n<ul>\n<li>Input: <code>nums = [2, 7, 11, 15], target = 9<\/code><\/li>\n<li>Output: <code>[0, 1]<\/code><\/li>\n<\/ul>\n<h3>Approach to Solving the Problem<\/h3>\n<p>\n        This problem involves finding two numbers in an array that add up to a specific sum, and there are various approaches to tackle it. The simplest method is to use nested loops, while a more efficient approach is to use a hash map. We will compare the time complexities of each method and look for the optimal solution.\n    <\/p>\n<h4>2.1. Brute Force Approach<\/h4>\n<p>\n        The simplest approach is to compare all possible pairs of two numbers in the array <code>nums<\/code> to check if their sum equals <code>target<\/code>.<br \/>\n        The time complexity of this method is <code>O(n^2)<\/code> because it requires <code>n*(n-1)\/2<\/code> operations to explore all pairs through two nested loops, where <code>n<\/code> is the length of the array.\n    <\/p>\n<pre><code>vector<int> twoSum(vector<int>&amp; nums, int target) {\n        for (int i = 0; i &lt; nums.size(); i++) {\n            for (int j = i + 1; j &lt; nums.size(); j++) {\n                if (nums[i] + nums[j] == target) {\n                    return {i, j};\n                }\n            }\n        }\n        return {}; \/\/ No solution\n    }<\/code><\/pre>\n<h4>2.2. Approach Using Hash Map<\/h4>\n<p>\n        To solve this problem more efficiently, we can use a hash map. By maintaining a record of how many times each number appears, we can quickly find the needed value for the current number while iterating.<br \/>\n        The time complexity of this method is <code>O(n)<\/code> because it requires a single pass through the array while updating the hash map, and finding the needed value takes constant time <code>O(1)<\/code>.\n    <\/p>\n<pre><code>vector<int> twoSum(vector<int>&amp; nums, int target) {\n        unordered_map<int, int> numMap;\n        for (int i = 0; i &lt; nums.size(); i++) {\n            int complement = target - nums[i];\n            if (numMap.find(complement) != numMap.end()) {\n                return {numMap[complement], i};\n            }\n            numMap[nums[i]] = i;\n        }\n        return {}; \/\/ No solution\n    }<\/code><\/pre>\n<h3>3. Understanding Time Complexity<\/h3>\n<p>\n        Time complexity is a crucial factor when evaluating the efficiency of algorithms. There are several methods for analyzing time complexity, but commonly used notations include <code>O(n)<\/code>, <code>O(log n)<\/code>, and <code>O(n^2)<\/code>. These indicate how many operations an algorithm performs based on the input size <code>n<\/code>.\n    <\/p>\n<ul>\n<li><strong>O(1)<\/strong>: Constant time complexity &#8211; An algorithm that takes a fixed time regardless of input size.<\/li>\n<li><strong>O(n)<\/strong>: Linear time complexity &#8211; The running time of the function increases proportionally with input size.<\/li>\n<li><strong>O(log n)<\/strong>: Logarithmic time complexity &#8211; An efficient algorithm that increases relatively slowly as the input size increases.<\/li>\n<li><strong>O(n^2)<\/strong>: Quadratic time complexity &#8211; The time taken grows quadratically as the input size increases.<\/li>\n<\/ul>\n<h3>4. Analysis Results<\/h3>\n<p>\n        For this problem, we chose an efficient algorithm using a hash map. Thanks to this approach, we managed to reduce the time complexity to <code>O(n)<\/code>, allowing for more efficient processing as the amount of data increases. When selecting algorithms, it is essential to consider time complexity to choose the best one.\n    <\/p>\n<h2>5. Conclusion<\/h2>\n<p>\n        Solving algorithmic problems is a crucial aspect of coding tests, and understanding various approaches to tackling these problems is important. We can leverage data structures like hash maps to solve problems more efficiently.<br \/>\n        Furthermore, understanding time complexity is essential when comparing the performance of algorithms. This knowledge will help you take the first step toward becoming a better developer.\n    <\/p>\n<h2>6. Additional Resources<\/h2>\n<p>\n        C++ is a language well-suited for implementing various data structures and algorithms. You can gain a deeper understanding through the following resources:\n    <\/p>\n<ul>\n<li><a href=\"https:\/\/cplusplus.com\/doc\/tutorial\/\">C++ Tutorial<\/a><\/li>\n<li><a href=\"https:\/\/www.geeksforgeeks.org\/\">GeeksforGeeks<\/a><\/li>\n<li><a href=\"https:\/\/leetcode.com\/\">LeetCode<\/a><\/li>\n<\/ul>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. Introduction: The Importance of Algorithms In modern software development, algorithms are an essential component. Especially in coding tests, they serve as a crucial criterion for evaluating candidates&#8217; problem-solving abilities. Therefore, enhancing algorithmic knowledge and problem-solving skills is very important. In this article, we will practice C++ coding through actual coding test problems and learn &hellip; <a href=\"https:\/\/atmokpo.com\/w\/34248\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;C++ Coding Test Course, Understanding Time Complexity Notation&#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-34248","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, Understanding Time Complexity Notation - \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\/34248\/\" \/>\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, Understanding Time Complexity Notation - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"1. Introduction: The Importance of Algorithms In modern software development, algorithms are an essential component. Especially in coding tests, they serve as a crucial criterion for evaluating candidates&#8217; problem-solving abilities. Therefore, enhancing algorithmic knowledge and problem-solving skills is very important. In this article, we will practice C++ coding through actual coding test problems and learn &hellip; \ub354 \ubcf4\uae30 &quot;C++ Coding Test Course, Understanding Time Complexity Notation&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/34248\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:26:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T10:58:00+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\/34248\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/34248\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"C++ Coding Test Course, Understanding Time Complexity Notation\",\"datePublished\":\"2024-11-01T09:26:00+00:00\",\"dateModified\":\"2024-11-01T10:58:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/34248\/\"},\"wordCount\":558,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"C++ Coding Test Tutorials\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/34248\/\",\"url\":\"https:\/\/atmokpo.com\/w\/34248\/\",\"name\":\"C++ Coding Test Course, Understanding Time Complexity Notation - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:26:00+00:00\",\"dateModified\":\"2024-11-01T10:58:00+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/34248\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/34248\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/34248\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C++ Coding Test Course, Understanding Time Complexity Notation\"}]},{\"@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, Understanding Time Complexity Notation - \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\/34248\/","og_locale":"ko_KR","og_type":"article","og_title":"C++ Coding Test Course, Understanding Time Complexity Notation - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"1. Introduction: The Importance of Algorithms In modern software development, algorithms are an essential component. Especially in coding tests, they serve as a crucial criterion for evaluating candidates&#8217; problem-solving abilities. Therefore, enhancing algorithmic knowledge and problem-solving skills is very important. In this article, we will practice C++ coding through actual coding test problems and learn &hellip; \ub354 \ubcf4\uae30 \"C++ Coding Test Course, Understanding Time Complexity Notation\"","og_url":"https:\/\/atmokpo.com\/w\/34248\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:26:00+00:00","article_modified_time":"2024-11-01T10:58:00+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\/34248\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/34248\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"C++ Coding Test Course, Understanding Time Complexity Notation","datePublished":"2024-11-01T09:26:00+00:00","dateModified":"2024-11-01T10:58:00+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/34248\/"},"wordCount":558,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["C++ Coding Test Tutorials"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/34248\/","url":"https:\/\/atmokpo.com\/w\/34248\/","name":"C++ Coding Test Course, Understanding Time Complexity Notation - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:26:00+00:00","dateModified":"2024-11-01T10:58:00+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/34248\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/34248\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/34248\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"C++ Coding Test Course, Understanding Time Complexity Notation"}]},{"@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\/34248","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=34248"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/34248\/revisions"}],"predecessor-version":[{"id":34249,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/34248\/revisions\/34249"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=34248"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=34248"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=34248"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}