{"id":33516,"date":"2024-11-01T09:17:21","date_gmt":"2024-11-01T09:17:21","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=33516"},"modified":"2024-11-01T11:38:13","modified_gmt":"2024-11-01T11:38:13","slug":"java-coding-test-course-card-sorting","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/33516\/","title":{"rendered":"Java Coding Test Course, Card Sorting"},"content":{"rendered":"<p><body><\/p>\n<h2>Problem Description<\/h2>\n<p>\n        You are a card organization expert. Each card has a number from 1 to N written on it.<br \/>\n        However, the cards are shuffled. Your goal is to sort the given cards in ascending order.<br \/>\n        You can select one card at a time. The selected cards should be sorted in ascending order based on their numbers. <strong>You must sort the cards with the minimum number of comparisons.<\/strong>\n<\/p>\n<h3>Input<\/h3>\n<p>\n        The first line contains the number of cards N (1 \u2264 N \u2264 10^6).<br \/>\n        The second line contains N integers A1, A2, &#8230;, AN (1 \u2264 Ai \u2264 10^9).<br \/>\n        This array represents the numbers on the cards.\n    <\/p>\n<h3>Output<\/h3>\n<p>\n        Output the numbers on each card sorted in ascending order, each on a new line.\n    <\/p>\n<h2>Problem-Solving Strategy<\/h2>\n<p>\n        To solve the card sorting problem, various sorting algorithms can be utilized.<br \/>\n        In particular, it is good to implement efficient sorting algorithms such as <strong>Quick Sort<\/strong> or <strong>Merge Sort<\/strong>.<br \/>\n        In this discussion, we will use <strong>Merge Sort<\/strong> to solve the problem.\n    <\/p>\n<h3>Merge Sort<\/h3>\n<p>\n        Merge Sort is a type of Divide and Conquer algorithm that sorts through the following steps:\n    <\/p>\n<ol>\n<li>Split the array in half.<\/li>\n<li>Recursively sort each half.<\/li>\n<li>Merge the sorted two arrays to obtain the final sorted array.<\/li>\n<\/ol>\n<h3>Java Code<\/h3>\n<pre>\n        <code>\npublic class CardSorting {\n    public static void main(String[] args) {\n        int[] cards = {3, 2, 5, 4, 1}; \/\/ Example input\n        mergeSort(cards, 0, cards.length - 1);\n        System.out.println(\"Sorted cards:\");\n        for (int card : cards) {\n            System.out.print(card + \" \");\n        }\n    }\n\n    public static void mergeSort(int[] array, int left, int right) {\n        if (left < right) {\n            int mid = (left + right) \/ 2;\n\n            mergeSort(array, left, mid);\n            mergeSort(array, mid + 1, right);\n\n            merge(array, left, mid, right);\n        }\n    }\n\n    public static void merge(int[] array, int left, int mid, int right) {\n        int n1 = mid - left + 1;\n        int n2 = right - mid;\n\n        int[] L = new int[n1];\n        int[] R = new int[n2];\n\n        for (int i = 0; i < n1; i++) {\n            L[i] = array[left + i];\n        }\n        for (int j = 0; j < n2; j++) {\n            R[j] = array[mid + 1 + j];\n        }\n\n        int i = 0, j = 0;\n        int k = left;\n        while (i < n1 &#038;&#038; j < n2) {\n            if (L[i] <= R[j]) {\n                array[k] = L[i];\n                i++;\n            } else {\n                array[k] = R[j];\n                j++;\n            }\n            k++;\n        }\n\n        while (i < n1) {\n            array[k] = L[i];\n            i++;\n            k++;\n        }\n\n        while (j < n2) {\n            array[k] = R[j];\n            j++;\n            k++;\n        }\n    }\n}\n        <\/code>\n    <\/pre>\n<h2>Complexity Analysis<\/h2>\n<p>\n        The time complexity of Merge Sort is<br \/>\n        <strong>O(N log N)<\/strong>. This is because merging two sorted arrays takes O(N), and continually splitting the array takes log N.<br \/>\n        Therefore, it can efficiently sort large card datasets.\n    <\/p>\n<h2>Conclusion<\/h2>\n<p>\n        In this article, we explored solving the card sorting problem using Merge Sort.<br \/>\n        The implementation of Merge Sort in Java enhances understanding of the importance of various data structures and algorithms.<br \/>\n        Keep addressing such problems to continuously improve your Java programming skills.\n    <\/p>\n<h2>Further Reading<\/h2>\n<ul>\n<li><a href=\"https:\/\/en.wikipedia.org\/wiki\/Merge_sort\">Merge Sort - Wikipedia<\/a><\/li>\n<li><a href=\"https:\/\/www.geeksforgeeks.org\/merge-sort\/\">GeeksforGeeks - Merge Sort<\/a><\/li>\n<\/ul>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Problem Description You are a card organization expert. Each card has a number from 1 to N written on it. However, the cards are shuffled. Your goal is to sort the given cards in ascending order. You can select one card at a time. The selected cards should be sorted in ascending order based on &hellip; <a href=\"https:\/\/atmokpo.com\/w\/33516\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;Java Coding Test Course, Card Sorting&#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":[139],"tags":[],"class_list":["post-33516","post","type-post","status-publish","format-standard","hentry","category-java-coding-test"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Java Coding Test Course, Card Sorting - \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\/33516\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java Coding Test Course, Card Sorting - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Problem Description You are a card organization expert. Each card has a number from 1 to N written on it. However, the cards are shuffled. Your goal is to sort the given cards in ascending order. You can select one card at a time. The selected cards should be sorted in ascending order based on &hellip; \ub354 \ubcf4\uae30 &quot;Java Coding Test Course, Card Sorting&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/33516\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:17:21+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:38:13+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=\"2\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/33516\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/33516\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"Java Coding Test Course, Card Sorting\",\"datePublished\":\"2024-11-01T09:17:21+00:00\",\"dateModified\":\"2024-11-01T11:38:13+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/33516\/\"},\"wordCount\":293,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Java Coding Test\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/33516\/\",\"url\":\"https:\/\/atmokpo.com\/w\/33516\/\",\"name\":\"Java Coding Test Course, Card Sorting - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:17:21+00:00\",\"dateModified\":\"2024-11-01T11:38:13+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/33516\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/33516\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/33516\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Coding Test Course, Card Sorting\"}]},{\"@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":"Java Coding Test Course, Card Sorting - \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\/33516\/","og_locale":"ko_KR","og_type":"article","og_title":"Java Coding Test Course, Card Sorting - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Problem Description You are a card organization expert. Each card has a number from 1 to N written on it. However, the cards are shuffled. Your goal is to sort the given cards in ascending order. You can select one card at a time. The selected cards should be sorted in ascending order based on &hellip; \ub354 \ubcf4\uae30 \"Java Coding Test Course, Card Sorting\"","og_url":"https:\/\/atmokpo.com\/w\/33516\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:17:21+00:00","article_modified_time":"2024-11-01T11:38:13+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":"2\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/33516\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/33516\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"Java Coding Test Course, Card Sorting","datePublished":"2024-11-01T09:17:21+00:00","dateModified":"2024-11-01T11:38:13+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/33516\/"},"wordCount":293,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Java Coding Test"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/33516\/","url":"https:\/\/atmokpo.com\/w\/33516\/","name":"Java Coding Test Course, Card Sorting - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:17:21+00:00","dateModified":"2024-11-01T11:38:13+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/33516\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/33516\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/33516\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"Java Coding Test Course, Card Sorting"}]},{"@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\/33516","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=33516"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/33516\/revisions"}],"predecessor-version":[{"id":33517,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/33516\/revisions\/33517"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=33516"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=33516"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=33516"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}