{"id":7265,"date":"2022-09-09T16:55:50","date_gmt":"2022-09-09T14:55:50","guid":{"rendered":"https:\/\/blue.pri.ee\/ttu\/?page_id=7265"},"modified":"2022-09-09T16:55:50","modified_gmt":"2022-09-09T14:55:50","slug":"algorithm-tasks","status":"publish","type":"page","link":"https:\/\/blue.pri.ee\/ttu\/programming-i\/algorithm-tasks\/","title":{"rendered":"Algorithm tasks"},"content":{"rendered":"<p>This page contains a collection of various algorithms which you should be able to independently create a solution for. You will find algorithm tasks with similar complexity in the test. Some of the algorithms on this page will be completed within various lab tasks and homework.<\/p>\n<p>Reminder!<\/p>\n<ol>\n<li>The algorithm shouldn&#8217;t not contain language-specific aspects. Algorithms should be programming language agnostic. Implementation language is up to the developer.<\/li>\n<li>You are not expected to be able to program all of the tasks on this page by the time of the test &#8211; e.g. files and strings will be covered later. However you should be able to devise the algorithm how to solve it.<\/li>\n<\/ol>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/blue.pri.ee\/ttu\/programming-i\/algorithm-tasks\/#Algorithm_1_Food_scale\" >Algorithm 1: Food scale<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/blue.pri.ee\/ttu\/programming-i\/algorithm-tasks\/#Algorithm_2_ATM\" >Algorithm 2: ATM<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/blue.pri.ee\/ttu\/programming-i\/algorithm-tasks\/#Variation_1_Small_banknotes\" >Variation 1: Small banknotes<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/blue.pri.ee\/ttu\/programming-i\/algorithm-tasks\/#Variation_2_Equal_distribution\" >Variation 2: Equal distribution<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/blue.pri.ee\/ttu\/programming-i\/algorithm-tasks\/#Algorithm_3_Reordering_negative_and_positive_numbers\" >Algorithm 3: Reordering negative and positive numbers<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/blue.pri.ee\/ttu\/programming-i\/algorithm-tasks\/#Algorithm_4_Sorting_facility\" >Algorithm 4: Sorting facility<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/blue.pri.ee\/ttu\/programming-i\/algorithm-tasks\/#Algorithm_5_Package_ratios\" >Algorithm 5: Package ratios<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/blue.pri.ee\/ttu\/programming-i\/algorithm-tasks\/#Algorithm_6_Finding_the_lowest_possible_number_base\" >Algorithm 6: Finding the lowest possible number base<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/blue.pri.ee\/ttu\/programming-i\/algorithm-tasks\/#Algorithm_7_Converting_decimal_numbers_to_the_desired_number_system\" >Algorithm 7: Converting decimal numbers to the desired number system<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/blue.pri.ee\/ttu\/programming-i\/algorithm-tasks\/#Algorithm_8_Converting_binary_numbers\" >Algorithm 8: Converting binary numbers<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/blue.pri.ee\/ttu\/programming-i\/algorithm-tasks\/#Algorithm_9_Date_validation\" >Algorithm 9: Date validation<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/blue.pri.ee\/ttu\/programming-i\/algorithm-tasks\/#Algorithm_10_Finding_results_from_a_matrix\" >Algorithm 10: Finding results from a matrix<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/blue.pri.ee\/ttu\/programming-i\/algorithm-tasks\/#Algorithm_11_Printing_a_matrix_column_by_column_transposed\" >Algorithm 11: Printing a matrix, column by column transposed<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/blue.pri.ee\/ttu\/programming-i\/algorithm-tasks\/#Algorithm_12_Rate_of_occurrence_of_characters_and_number_of_sentences\" >Algorithm 12: Rate of occurrence of characters and number of sentences<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/blue.pri.ee\/ttu\/programming-i\/algorithm-tasks\/#Algorithm_13_Character_replacement\" >Algorithm 13: Character replacement<\/a><\/li><\/ul><\/nav><\/div>\n<h3><span class=\"ez-toc-section\" id=\"Algorithm_1_Food_scale\"><\/span>Algorithm 1: Food scale<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ul>\n<li>Create an algorithm that mimics the behavior of the food scales in grocery stores<\/li>\n<li>Your inputs are the weight of the produce and the product code.<\/li>\n<li>You must find the product based on the code, it&#8217;s price per kilo and the total cost.<\/li>\n<li>Solution must handle various errors that may occur with inputs.<\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"Algorithm_2_ATM\"><\/span>Algorithm 2: ATM<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ul>\n<li>Your task is to mimic the behavior of an ATM.<\/li>\n<li>Client wishes to withdraw cash from an ATM and will enter the amount manually.<\/li>\n<li>The ATM currency is euro and it carries all euro banknotes in use in Estonia.<\/li>\n<li>User entered withdrawal amount must be verified.<\/li>\n<li>Give out the banknotes with the intention of giving the least possible amount of banknotes.<\/li>\n<li>E.g.: 537\u20ac -&gt; error; 195\u20ac -&gt; 1&#215;100\u20ac + 1&#215;50\u20ac + 2&#215;20\u20ac + 1&#215;5\u20ac<\/li>\n<\/ul>\n<h4><span class=\"ez-toc-section\" id=\"Variation_1_Small_banknotes\"><\/span>Variation 1: Small banknotes<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<ul>\n<li>User will select small banknotes from the menu.<\/li>\n<li>ATM has limits on giving out small notes. If the user entered amount exceeds the amount possibly by the smallest note, a larger note will be given instead.<\/li>\n<li>Limits\n<ul>\n<li>5\u20ac euro notes for 25\u20ac<\/li>\n<li>10\u20ac euro notes for 50\u20ac<\/li>\n<li>20\u20ac euro notes for 100\u20ac<\/li>\n<li>50\u20ac euro notes for 500\u20ac<\/li>\n<li>100\u20ac euro notes for 1000\u20ac<\/li>\n<li>The rest will be given as 200\u20ac banknotes.<\/li>\n<\/ul>\n<\/li>\n<li>Example:\n<ul>\n<li>25\u20ac -&gt; 5&#215;5\u20ac<\/li>\n<li>30\u20ac -&gt; 1&#215;10\u20ac + 4&#215;5\u20ac<\/li>\n<li>35\u20ac -&gt; 1&#215;10\u20ac + 5&#215;5\u20ac<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h4><span class=\"ez-toc-section\" id=\"Variation_2_Equal_distribution\"><\/span>Variation 2: Equal distribution<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<ul>\n<li>The banknote counting algorithm will try to create an equal distribution of notes. The difference between the most and least used should must be 1.<\/li>\n<li>Example:\n<ul>\n<li>40\u20ac -&gt; 1&#215;20\u20ac + 1&#215;10\u20ac + 2&#215;5\u20ac<\/li>\n<li>45\u20ac -&gt; 1&#215;20\u20ac + 2&#215;10\u20ac + 1&#215;5\u20ac<\/li>\n<li>1500\u20ac -&gt; 2&#215;500 \u20ac+ 1&#215;200\u20ac+ 2&#215;100\u20ac + 1&#215;50\u20ac + 1&#215;20\u20ac + 2&#215;10\u20ac + 2&#215;5\u20ac<\/li>\n<li>2000\u20ac -&gt; 2&#215;500 \u20ac+ 3&#215;200\u20ac+ 2&#215;100\u20ac + 2&#215;50\u20ac + 3&#215;20\u20ac + 3&#215;10\u20ac + 2&#215;5\u20ac<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"Algorithm_3_Reordering_negative_and_positive_numbers\"><\/span>Algorithm 3: Reordering negative and positive numbers<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ul>\n<li>You are given an array of N integers as input.<\/li>\n<li>Reorder the numbers in the array in such a way that negative numbers are in the beginning of the array, followed by the positive numbers.<\/li>\n<li>Do not change the order of appearance<\/li>\n<li>Example:<br \/>\nInput: 5, -7, -87, -221, 7, 97, 1, -5, 5<br \/>\nResult: -7, -87, -221, -5, 5, 7, 97, 1, 5<\/li>\n<\/ul>\n<p><strong>Variation 1<\/strong>: The same rules apply for the number 0 as was for the positive integers.<\/p>\n<p><strong>Variation 2:\u00a0<\/strong>All occurrences of the number 0 will be removed. The resulting array may be shorter.<\/p>\n<p><strong>Variation 3:\u00a0<\/strong>All occurrences of 0 will be pushed to the end of the array<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Algorithm_4_Sorting_facility\"><\/span>Algorithm 4: Sorting facility<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ul>\n<li>The company has 2 small warehouses (warehouse A and B) and a larger sorting facility that they operate in. The packages arrive in the smaller warehouses and are then sent over to the sorting facility.<\/li>\n<li>All packages are given as integers, which represent the weight in kilograms.<\/li>\n<li>All packages are put together when they arrive in the sorting facility. Once there, they are sorted in a way that when they exit, the heaviest packages leave first.<\/li>\n<li>Example:\n<ul>\n<li>Warehouse A: 7, 59, 1, 93, 15, 27, 48, 6<\/li>\n<li>Warehouse B: 9, 3, 1, 94<\/li>\n<li>Exit order from sorting facility: 94, 93, 59, 48, 27, 15, 9, 7, 6, 3, 1, 1<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"Algorithm_5_Package_ratios\"><\/span>Algorithm 5: Package ratios<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ul>\n<li>Read product weights and tracking numbers from a file<\/li>\n<li>Find and output the extreme values (the heaviest and lightest package), followed by the list of packages and their ratios to the extremums.\u00a0 The list must include tracking codes alongside ratios.<\/li>\n<li>Example:\n<ul>\n<li>Weights: 6, 7, 2, 10, 4<\/li>\n<li>Tracking codes: EE790A1, EE001A1, EE117CA, EE000A2, EE01010<\/li>\n<li>Extreme values: minimum 2 kg, maximum 10 kg<\/li>\n<li>Package EE790A1 ratios are 3.0 and 0.6<br \/>\nPackage EE001A1 ratios are 3.5 and 0.7<br \/>\nPackage EE117CA ratios are 1.0 and 0.2<br \/>\nEtc.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"Algorithm_6_Finding_the_lowest_possible_number_base\"><\/span>Algorithm 6: Finding the lowest possible number base<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ul>\n<li>User enters 4-character strings from the keyboard<\/li>\n<li>Find the lowest possible number base from the selection: base-2, base-16. The ones that don&#8217;t match any possible number bases from the list must also be displayed separately.<\/li>\n<li>Example: 0110, AZY1, 001F, 0101, 0Y24<\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"Algorithm_7_Converting_decimal_numbers_to_the_desired_number_system\"><\/span>Algorithm 7: Converting decimal numbers to the desired number system<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ul>\n<li>User enters decimal integers from the keyboard until they insert the number 0, which terminates the input.<\/li>\n<li>User will enter the desired new number base from the keyboard.<\/li>\n<li>All numbers will be converted to the new base and printed alongside the original input.<\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"Algorithm_8_Converting_binary_numbers\"><\/span>Algorithm 8: Converting binary numbers<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ul>\n<li>Binary numbers are read from the file. One number is 4 bytes long.<\/li>\n<li>All read numbers will be converted to hexadecimal.<\/li>\n<li>The results are printed into a new file. They are printed side-by-side with the binary numbers, one pair per line.<\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"Algorithm_9_Date_validation\"><\/span>Algorithm 9: Date validation<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ul>\n<li>8-digit integers are read from a file. Each of them represents a date.<\/li>\n<li>The dates are based on the Gregorian calendar.<\/li>\n<li>Validate and output which of the dates exist and which do not.<\/li>\n<li>Make sure to check for leap years!<\/li>\n<li>Example: 27041998, 29022003, 58042013, 04132013<\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"Algorithm_10_Finding_results_from_a_matrix\"><\/span>Algorithm 10: Finding results from a matrix<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ul>\n<li>Create a matrix\u00a0 A<sup>(m * n)<\/sup> , where n &gt; 5, m &gt; 5. Matrix will be composed of randomly generated integers -100 \u2264 a<sub>i<\/sub> \u2264 100.<\/li>\n<li>Find the following results\n<ul>\n<li>The sum of negative numbers from the last row<\/li>\n<li>The sum of positive elements in a column. Find one sum per column from all columns to the right of the third column.<\/li>\n<li>The product of negative elements in a row. Find one product per row from rows that are higher than the third row.<\/li>\n<\/ul>\n<\/li>\n<li>Print all of the results you found.<\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"Algorithm_11_Printing_a_matrix_column_by_column_transposed\"><\/span>Algorithm 11: Printing a matrix, column by column transposed<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ul>\n<li>User enters a matrix A<sup>(m * n)<\/sup><\/li>\n<li>The following conditions must be met &gt; 5, m &gt; 5<\/li>\n<li>The contents of the matrix A will be copied to the vector B, one column at a time.<\/li>\n<li>The matrix will be printed on the screen only through the vector B. One column at a time, transposed as a row.<\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"Algorithm_12_Rate_of_occurrence_of_characters_and_number_of_sentences\"><\/span>Algorithm 12: Rate of occurrence of characters and number of sentences<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ul>\n<li>The text (e.g. a book or a newspaper article) is read from a file.<\/li>\n<li>Find and print the rates of occurrence\n<ul>\n<li>Your algorithm should be case-insensitive (must ignore capitalization).<\/li>\n<\/ul>\n<\/li>\n<li>Find and print the number of sentences in the text. A sentence can end by a point, exclamation or a question mark.<\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"Algorithm_13_Character_replacement\"><\/span>Algorithm 13: Character replacement<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ul>\n<li>A novella is read from a file.<\/li>\n<li>Make the following replacements in the text:\n<ul>\n<li>a -&gt; u<\/li>\n<li>u -&gt; a<\/li>\n<\/ul>\n<\/li>\n<li>Print the number of replacements made on the screen.<\/li>\n<li>Update the novel in the file.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>This page contains a collection of various algorithms which you should be able to independently create a solution for. You will find algorithm tasks with similar complexity in the test. Some of the algorithms on this page will be completed within various lab tasks and homework. Reminder! The algorithm shouldn&#8217;t not contain language-specific aspects. Algorithms &hellip; <a href=\"https:\/\/blue.pri.ee\/ttu\/programming-i\/algorithm-tasks\/\" class=\"more-link\">Loe edasi <span class=\"screen-reader-text\">Algorithm tasks<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":1425,"menu_order":8,"comment_status":"closed","ping_status":"closed","template":"page-templates\/code-width.php","meta":{"footnotes":""},"class_list":["post-7265","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/pages\/7265","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/comments?post=7265"}],"version-history":[{"count":0,"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/pages\/7265\/revisions"}],"up":[{"embeddable":true,"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/pages\/1425"}],"wp:attachment":[{"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/media?parent=7265"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}