{"id":19829,"date":"2023-01-18T06:38:39","date_gmt":"2023-01-18T06:38:39","guid":{"rendered":"https:\/\/www.booksofall.com\/?post_type=product&#038;p=19829"},"modified":"2023-02-07T08:42:13","modified_gmt":"2023-02-07T08:42:13","slug":"algorithms-notes-for-professionals","status":"publish","type":"product","link":"https:\/\/www.booksofall.com\/pt\/algorithms-notes-for-professionals\/","title":{"rendered":"Algorithms &#8211; Notes for Professionals"},"content":{"rendered":"<div id=\"reading-mode-page-div-7\" class=\"reading-mode-page-div\">\n<h2><b>Chapter 1: Getting started with algorithms<\/b><\/h2>\n<p><b style=\"font-size: 1rem;\">Section 1.1: A sample algorithmic problem\u00a0<\/b><\/p>\n<p><span style=\"font-size: 1rem;\">An algorithmic problem is specified by describing the complete set of instances it must work on and of its output after running on one of these instances. This distinction, between a problem and an instance of a problem, is fundamental. The algorithmic problem known as sorting is defined as follows: [Skiena:2008:ADM:1410219]<\/span><\/p>\n<ul>\n<li>Problem: Sorting<\/li>\n<li>Input: A sequence of\u00a0<i>n<\/i>\u00a0keys, a_1, a_2, &#8230;, a_n.<\/li>\n<li>Output: The reordering of the input sequence such that a&#8217;_1 &lt;= a&#8217;_2 &lt;= &#8230; &lt;= a&#8217;_{n-1} &lt;= a&#8217;_n<\/li>\n<\/ul>\n<p>An\u00a0<i>instance<\/i>\u00a0of sorting might be an array of strings, such as { Haskell, Emacs } or a sequence of numbers such as { 154, 245, 1337 }.<\/p>\n<p><b>Section 1.2: Getting Started with Simple <a href=\"https:\/\/www.geeksforgeeks.org\/fizz-buzz-implementation\/\">Fizz Buzz Algorithm<\/a> in Swift\u00a0<\/b><\/p>\n<p>For those of you that are new to programming in Swift and those of you coming from different programming bases, such as Python or Java, this article should be quite helpful. In this post, we will discuss a simple solution for implementing swift algorithms.<\/p>\n<p><b>Fizz Buzz<\/b><\/p>\n<p>You may have seen Fizz Buzz written as Fizz Buzz, FizzBuzz, or Fizz-Buzz; they&#8217;re all referring to the same thing. That &#8220;thing&#8221; is the main topic of discussion today. First, what is FizzBuzz?<\/p>\n<p>This is a common question that comes up in job interviews.<\/p>\n<p>Imagine a series of a number from 1 to 10.<\/p>\n<p>1 2 3 4 5 6 7 8 9 10<\/p>\n<p>Fizz and Buzz refer to any number that&#8217;s a multiple of 3 and 5 respectively. In other words, if a number is divisible by 3, it is substituted with fizz; if a number is divisible by 5, it is substituted with buzz. If a number is simultaneously a multiple of 3 AND 5, the number is replaced with &#8220;fizz buzz.&#8221; In essence, it emulates the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Fizz_buzz\">famous children game &#8220;fizz buzz&#8221;<\/a>.<\/p>\n<p>To work on this problem, open up Xcode to create a new playground and initialize an array like below:<\/p>\n<p><i>\/\/ for example<br \/>\n<\/i>let number = [1,2,3,4,5]<br \/>\n<i>\/\/ here 3 is fizz and 5 is buzz<\/i><\/p>\n<p>To find all the fizz and buzz, we must iterate through the array and check which numbers are fizz and which are buzz. To do this, create a <a href=\"https:\/\/www.learncpp.com\/cpp-tutorial\/for-statements\/\">for loop<\/a> to iterate through the array we have initialised:<\/p>\n<p><b>for<\/b>\u00a0num in number {<br \/>\n<i>\/\/ Body and calculation goes here<br \/>\n<\/i>}<\/p>\n<p>After this, we can simply use the &#8220;if else&#8221; condition and module operator in swift ie &#8211; % to locate the fizz and buzz<\/p>\n<\/div>\n<p><b>for<\/b>\u00a0num in number {<br \/>\n<b>if<\/b>\u00a0num % 3 == 0 {<br \/>\nprint(&#8220;<b>\\(<\/b>num) fizz&#8221;)<br \/>\n}\u00a0<b>else<\/b>\u00a0{<br \/>\nprint(num)<br \/>\n}<br \/>\n}<\/p>\n<p>Great! You can go to the debug console in <a href=\"https:\/\/designcode.io\/swiftui-handbook-xcode-playground\">Xcode playground<\/a> to see the output. You will find that the &#8220;fizzes&#8221; have been sorted out in your array.<\/p>\n<p>For the Buzz part, we will use the same technique. Let&#8217;s give it a try before scrolling through the article \u2014 you can check your results against this article once you&#8217;ve finished doing this.<\/p>\n<p><b>for<\/b>\u00a0num in number {<br \/>\n<b>if<\/b>\u00a0num % 3 == 0 {<br \/>\nprint(&#8220;<b>\\(<\/b>num) fizz&#8221;)<br \/>\n}\u00a0<b>else<\/b>\u00a0<b>if<\/b>\u00a0num % 5 == 0 {<br \/>\nprint(&#8220;<b>\\(<\/b>num) buzz&#8221;)<br \/>\n}\u00a0<b>else<\/b>\u00a0{<br \/>\nprint(num)<br \/>\n}<br \/>\n}<\/p>\n<p>Check the output!<\/p>\n<p>It&#8217;s rather straight forward \u2014 you divided the number by 3, fizz and divided the number by 5, buzz. Now, increase the numbers in the array<\/p>\n<p>let number = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]<\/p>\n<p>We increased the range of numbers from 1-10 to 1-15 in order to demonstrate the concept of a &#8220;fizz buzz.&#8221; Since 15 is a multiple of both 3 and 5, the number should be replaced with &#8220;fizz buzz.&#8221; Try for yourself and check the answer!<\/p>\n<p>Here is the solution:<\/p>\n<p><b>for<\/b>\u00a0num in number {<br \/>\n<b>if<\/b>\u00a0num % 3 == 0 &amp;&amp; num % 5 == 0 {<br \/>\nprint(&#8220;<b>\\(<\/b>num) fizz buzz&#8221;)<br \/>\n}\u00a0<b>else<\/b>\u00a0<b>if<\/b>\u00a0num % 3 == 0 {<br \/>\nprint(&#8220;<b>\\(<\/b>num) fizz&#8221;)<br \/>\n}\u00a0<b>else<\/b>\u00a0<b>if<\/b>\u00a0num % 5 == 0 {<br \/>\nprint(&#8220;<b>\\(<\/b>num) buzz&#8221;)<br \/>\n}\u00a0<b>else<\/b>\u00a0{ print(num)<br \/>\n}<br \/>\n}<\/p>\n<p>Wait&#8230;it&#8217;s not over though! The whole purpose of the algorithm is to customize the runtime correctly. Imagine if the range increases from 1-15 to 1-100. The compiler will check each number to determine whether it is divisible by 3 or 5. It would then run through the numbers again to check if the numbers are divisible by 3 and 5. The code would essentially have to run through each number in the array twice \u2014 it would have to runs the numbers by 3 first and then run it by 5. To speed up the process, we can simply tell our code to divide the numbers by 15 directly.<\/p>\n<p>Here is the final code:<\/p>\n<p><b>for<\/b> num in number {<br \/>\n<b style=\"font-size: 1rem;\">if<\/b><span style=\"font-size: 1rem;\">\u00a0num % 15 == 0 {<br \/>\nprint(&#8220;<\/span><b style=\"font-size: 1rem;\">\\(<\/b><span style=\"font-size: 1rem;\">num) fizz buzz&#8221;)<br \/>\n}\u00a0<\/span><b style=\"font-size: 1rem;\">else<\/b><span style=\"font-size: 1rem;\">\u00a0<\/span><b style=\"font-size: 1rem;\">if<\/b><span style=\"font-size: 1rem;\">\u00a0num % 3 == 0 {<br \/>\nprint(&#8220;<\/span><b style=\"font-size: 1rem;\">\\(<\/b><span style=\"font-size: 1rem;\">num) fizz&#8221;)<br \/>\n}\u00a0<\/span><b style=\"font-size: 1rem;\">else<\/b><span style=\"font-size: 1rem;\">\u00a0<\/span><b style=\"font-size: 1rem;\">if<\/b><span style=\"font-size: 1rem;\">\u00a0num % 5 == 0 {<br \/>\nprint(&#8220;<\/span><b style=\"font-size: 1rem;\">\\(<\/b><span style=\"font-size: 1rem;\">num) buzz&#8221;)<br \/>\n}\u00a0<\/span><b style=\"font-size: 1rem;\">else<\/b><span style=\"font-size: 1rem;\">\u00a0{ print(num)<br \/>\n}<br \/>\n}<\/span><\/p>\n<div id=\"reading-mode-page-div-9\" class=\"reading-mode-page-div\">\n<p>As Simple as that, you can use any language of your choice and get started<\/p>\n<p>Enjoy Coding<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p><iframe style=\"width: 100%; height: 750px; border: none;\" src=\"https:\/\/online.visual-paradigm.com\/share\/book\/algorithms-notes-for-professionals-book-185u7lzlua?p=1\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"><\/iframe><\/p>\n","protected":false},"featured_media":19832,"template":"","meta":{"_yoast_wpseo_title":"","_yoast_wpseo_metadesc":"Algorithms are a large field that includes different approaches and ideas. Learn more about algorithms with lots of examples and explanations in this book!"},"product_brand":[],"product_cat":[263],"product_tag":[314],"class_list":{"0":"post-19829","1":"product","2":"type-product","3":"status-publish","4":"has-post-thumbnail","6":"product_cat-algorithms-data-structures","7":"product_tag-new-books","9":"first","10":"instock","11":"shipping-taxable","12":"product-type-simple"},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Algorithms - Notes for Professionals - BooksOfAll Portuguese<\/title>\n<meta name=\"description\" content=\"Algorithms are a large field that includes different approaches and ideas. Learn more about algorithms with lots of examples and explanations in this book!\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.booksofall.com\/pt\/algorithms-notes-for-professionals\/\" \/>\n<meta property=\"og:locale\" content=\"pt_PT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Algorithms - Notes for Professionals - BooksOfAll Portuguese\" \/>\n<meta property=\"og:description\" content=\"Algorithms are a large field that includes different approaches and ideas. Learn more about algorithms with lots of examples and explanations in this book!\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.booksofall.com\/pt\/algorithms-notes-for-professionals\/\" \/>\n<meta property=\"og:site_name\" content=\"BooksOfAll Portuguese\" \/>\n<meta property=\"article:modified_time\" content=\"2023-02-07T08:42:13+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.booksofall.com\/pt\/wp-content\/uploads\/sites\/8\/2023\/01\/004.jpg\" \/><meta property=\"og:image\" content=\"https:\/\/www.booksofall.com\/pt\/wp-content\/uploads\/sites\/8\/2023\/01\/004.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"595\" \/>\n\t<meta property=\"og:image:height\" content=\"842\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:image\" content=\"https:\/\/www.booksofall.com\/pt\/wp-content\/uploads\/sites\/8\/2023\/01\/004.jpg\" \/>\n<meta name=\"twitter:label1\" content=\"Tempo estimado de leitura\" \/>\n\t<meta name=\"twitter:data1\" content=\"4 minutos\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.booksofall.com\/pt\/algorithms-notes-for-professionals\/\",\"url\":\"https:\/\/www.booksofall.com\/pt\/algorithms-notes-for-professionals\/\",\"name\":\"Algorithms - Notes for Professionals - BooksOfAll Portuguese\",\"isPartOf\":{\"@id\":\"https:\/\/www.booksofall.com\/pt\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.booksofall.com\/pt\/algorithms-notes-for-professionals\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.booksofall.com\/pt\/algorithms-notes-for-professionals\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.booksofall.com\/pt\/wp-content\/uploads\/sites\/8\/2023\/01\/004.jpg\",\"datePublished\":\"2023-01-18T06:38:39+00:00\",\"dateModified\":\"2023-02-07T08:42:13+00:00\",\"description\":\"Algorithms are a large field that includes different approaches and ideas. Learn more about algorithms with lots of examples and explanations in this book!\",\"breadcrumb\":{\"@id\":\"https:\/\/www.booksofall.com\/pt\/algorithms-notes-for-professionals\/#breadcrumb\"},\"inLanguage\":\"pt-PT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.booksofall.com\/pt\/algorithms-notes-for-professionals\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"pt-PT\",\"@id\":\"https:\/\/www.booksofall.com\/pt\/algorithms-notes-for-professionals\/#primaryimage\",\"url\":\"https:\/\/www.booksofall.com\/pt\/wp-content\/uploads\/sites\/8\/2023\/01\/004.jpg\",\"contentUrl\":\"https:\/\/www.booksofall.com\/pt\/wp-content\/uploads\/sites\/8\/2023\/01\/004.jpg\",\"width\":\"595\",\"height\":\"842\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.booksofall.com\/pt\/algorithms-notes-for-professionals\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.booksofall.com\/pt\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Categories\",\"item\":\"https:\/\/www.booksofall.com\/pt\/categories\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Algorithms &#8211; Notes for Professionals\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.booksofall.com\/pt\/#website\",\"url\":\"https:\/\/www.booksofall.com\/pt\/\",\"name\":\"BooksOfAll Portuguese\",\"description\":\"Biggest IT eBooks library and learning resources - Free eBooks for programming, computing, artificial intelligence and more.\",\"publisher\":{\"@id\":\"https:\/\/www.booksofall.com\/pt\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.booksofall.com\/pt\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"pt-PT\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.booksofall.com\/pt\/#organization\",\"name\":\"BooksOfAll Portuguese\",\"url\":\"https:\/\/www.booksofall.com\/pt\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"pt-PT\",\"@id\":\"https:\/\/www.booksofall.com\/pt\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.booksofall.com\/pt\/wp-content\/uploads\/sites\/8\/2022\/06\/booksofall-logo-2.png\",\"contentUrl\":\"https:\/\/www.booksofall.com\/pt\/wp-content\/uploads\/sites\/8\/2022\/06\/booksofall-logo-2.png\",\"width\":166,\"height\":30,\"caption\":\"BooksOfAll Portuguese\"},\"image\":{\"@id\":\"https:\/\/www.booksofall.com\/pt\/#\/schema\/logo\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Algorithms - Notes for Professionals - BooksOfAll Portuguese","description":"Algorithms are a large field that includes different approaches and ideas. Learn more about algorithms with lots of examples and explanations in this book!","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:\/\/www.booksofall.com\/pt\/algorithms-notes-for-professionals\/","og_locale":"pt_PT","og_type":"article","og_title":"Algorithms - Notes for Professionals - BooksOfAll Portuguese","og_description":"Algorithms are a large field that includes different approaches and ideas. Learn more about algorithms with lots of examples and explanations in this book!","og_url":"https:\/\/www.booksofall.com\/pt\/algorithms-notes-for-professionals\/","og_site_name":"BooksOfAll Portuguese","article_modified_time":"2023-02-07T08:42:13+00:00","og_image":[{"url":"https:\/\/www.booksofall.com\/pt\/wp-content\/uploads\/sites\/8\/2023\/01\/004.jpg","type":"","width":"","height":""},{"width":595,"height":842,"url":"https:\/\/www.booksofall.com\/pt\/wp-content\/uploads\/sites\/8\/2023\/01\/004.jpg","type":"image\/jpeg"}],"twitter_card":"summary_large_image","twitter_image":"https:\/\/www.booksofall.com\/pt\/wp-content\/uploads\/sites\/8\/2023\/01\/004.jpg","twitter_misc":{"Tempo estimado de leitura":"4 minutos"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.booksofall.com\/pt\/algorithms-notes-for-professionals\/","url":"https:\/\/www.booksofall.com\/pt\/algorithms-notes-for-professionals\/","name":"Algorithms - Notes for Professionals - BooksOfAll Portuguese","isPartOf":{"@id":"https:\/\/www.booksofall.com\/pt\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.booksofall.com\/pt\/algorithms-notes-for-professionals\/#primaryimage"},"image":{"@id":"https:\/\/www.booksofall.com\/pt\/algorithms-notes-for-professionals\/#primaryimage"},"thumbnailUrl":"https:\/\/www.booksofall.com\/pt\/wp-content\/uploads\/sites\/8\/2023\/01\/004.jpg","datePublished":"2023-01-18T06:38:39+00:00","dateModified":"2023-02-07T08:42:13+00:00","description":"Algorithms are a large field that includes different approaches and ideas. Learn more about algorithms with lots of examples and explanations in this book!","breadcrumb":{"@id":"https:\/\/www.booksofall.com\/pt\/algorithms-notes-for-professionals\/#breadcrumb"},"inLanguage":"pt-PT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.booksofall.com\/pt\/algorithms-notes-for-professionals\/"]}]},{"@type":"ImageObject","inLanguage":"pt-PT","@id":"https:\/\/www.booksofall.com\/pt\/algorithms-notes-for-professionals\/#primaryimage","url":"https:\/\/www.booksofall.com\/pt\/wp-content\/uploads\/sites\/8\/2023\/01\/004.jpg","contentUrl":"https:\/\/www.booksofall.com\/pt\/wp-content\/uploads\/sites\/8\/2023\/01\/004.jpg","width":"595","height":"842"},{"@type":"BreadcrumbList","@id":"https:\/\/www.booksofall.com\/pt\/algorithms-notes-for-professionals\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.booksofall.com\/pt\/"},{"@type":"ListItem","position":2,"name":"Categories","item":"https:\/\/www.booksofall.com\/pt\/categories\/"},{"@type":"ListItem","position":3,"name":"Algorithms &#8211; Notes for Professionals"}]},{"@type":"WebSite","@id":"https:\/\/www.booksofall.com\/pt\/#website","url":"https:\/\/www.booksofall.com\/pt\/","name":"BooksOfAll Portuguese","description":"Biggest IT eBooks library and learning resources - Free eBooks for programming, computing, artificial intelligence and more.","publisher":{"@id":"https:\/\/www.booksofall.com\/pt\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.booksofall.com\/pt\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"pt-PT"},{"@type":"Organization","@id":"https:\/\/www.booksofall.com\/pt\/#organization","name":"BooksOfAll Portuguese","url":"https:\/\/www.booksofall.com\/pt\/","logo":{"@type":"ImageObject","inLanguage":"pt-PT","@id":"https:\/\/www.booksofall.com\/pt\/#\/schema\/logo\/image\/","url":"https:\/\/www.booksofall.com\/pt\/wp-content\/uploads\/sites\/8\/2022\/06\/booksofall-logo-2.png","contentUrl":"https:\/\/www.booksofall.com\/pt\/wp-content\/uploads\/sites\/8\/2022\/06\/booksofall-logo-2.png","width":166,"height":30,"caption":"BooksOfAll Portuguese"},"image":{"@id":"https:\/\/www.booksofall.com\/pt\/#\/schema\/logo\/image\/"}}]}},"_links":{"self":[{"href":"https:\/\/www.booksofall.com\/pt\/wp-json\/wp\/v2\/product\/19829","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.booksofall.com\/pt\/wp-json\/wp\/v2\/product"}],"about":[{"href":"https:\/\/www.booksofall.com\/pt\/wp-json\/wp\/v2\/types\/product"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.booksofall.com\/pt\/wp-json\/wp\/v2\/media\/19832"}],"wp:attachment":[{"href":"https:\/\/www.booksofall.com\/pt\/wp-json\/wp\/v2\/media?parent=19829"}],"wp:term":[{"taxonomy":"product_brand","embeddable":true,"href":"https:\/\/www.booksofall.com\/pt\/wp-json\/wp\/v2\/product_brand?post=19829"},{"taxonomy":"product_cat","embeddable":true,"href":"https:\/\/www.booksofall.com\/pt\/wp-json\/wp\/v2\/product_cat?post=19829"},{"taxonomy":"product_tag","embeddable":true,"href":"https:\/\/www.booksofall.com\/pt\/wp-json\/wp\/v2\/product_tag?post=19829"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}