Do you have creative ideas that you wish you could transform into code?
Do you want to boost your problem solving and logic skills?
Do you want to enhance your career by adopting an algorithmic mindset?
In our increasingly digital world, coding is an essential skill. Communicating an algorithm to a machine to perform a set of tasks is vital. Beginner's Guide to Code Algorithms: Experiments to Enhance Productivity and Solve Problems written by Deepankar Maitra teaches you how to think like a programmer. The author unravels the secret behind writing code â building a good algorithm. Algorithmic thinking leads to asking the right question and enables a shift from issue resolution to value creation. Having this mindset will make you more marketable to employers.
This book takes you on a problem-solving journey to expand your mind and increase your willingness to experiment with code.
You will:
Learn the art of building an algorithm through hands-on exercises
Understand how to develop code for inspiring productivity concepts
Build a mentality of developing algorithms to solve problems
Develop, test, review, and improve code through guided experimentation
This book is designed to develop a culture of logical thinking through intellectual stimulation. It will benefit students and teachers of programming, business professionals, as well as experienced users of Microsoft Excel who wish to become proficient with macros.
Trusted by 375,005 students
Access to over 1.5 million titles for a fair monthly price.
Algorithm is a word used in computer science. It simply means a step-by-step instruction. But it encapsulates the essence of computer programming, because without a step-by-step instruction a computer cannot perform a useful task. Therefore, it means much more than that.
The word algorithm has the same root as the word Algebra. With an Arab past, it came from ninth-century Persian mathematician MuḼammad ibn MĹŤsÄ al-KhwÄrizmÄŤ. Al-KhwÄrizmÄŤ (Arabic: اŮŘŽŮاعز٠Ű, c. 780â850) was a Persian mathematician, astronomer, geographer, and scholar whose name means âthe native of Khwarazmâ, a region that was part of Greater Iran and is now in Uzbekistan.
About 825 ad, al-Khwarizmi wrote an Arabic language treatise on the HinduâArabic numeral system, which was translated into Latin during the 12th century under the title Algoritmi de numero Indorum. This title means âAlgoritmi on the numbers of the Indiansâ, where âAlgoritmiâ was the translatorâs Latinization of al-Khwarizmiâs name. The modern sense of this word was introduced in the 19th century. By the way, al-Khwarizmi was the most widely read mathematician in Europe in the late Middle Ages, primarily through another of his books, the Algebra.
Algorithms are part of our understanding of life and is used by all fields and disciplines to convey a process. Some are small and famous. Like the book âEat, Love, Prayâ. Or the recent hotel/restaurant ad: âEat, Drink, Sleep, Repeatâ. Some are long and detailed, such as a recipe.
How to make chocolate chip cookies
Ingredients
- 2 cups all-purpose flour
- 1 teaspoon baking soda
- Fine salt
- 1 stick (12 tablespoons) unsalted butter, at room temperature
- 1 cup packed light brown sugar
- 1 cup granulated sugar
- 2 large eggs
- 1 teaspoon pure vanilla extract
- One 12-ounce bag semisweet chocolate chips
Process
Preheat to 375 degrees F
Stir together the flour, baking soda, and 1 teaspoon salt in a large bowl.
Beat the butter and both sugars, eggs, vanilla, and flour about 4 minutes. Stir in the chocolate chips.
Scoop 12 tablespoons of dough about 2 inches apart onto each prepared baking sheet. Roll the dough into balls with slightly wet hands.
Bake, rotating the cookie sheets from upper to lower racks halfway through, until golden but still soft in the center, 12 to 15 minutes.
Wait for a few minutes on the baking sheet, and then transfer to a rack to cool completely.
Figure 1.1 Making chocolate chip cookies.
In the computer world, an algorithm is used to code the program, hence needs to be somewhat detailed. But the role of the algorithm is to facilitate the creation of the programâjust like a recipe. Once the chocolate chip cookie is made, the recipe is not useful, until you are ready to make the next batch!
The discussion on algorithms is not complete without the concept of some important attributes . A good algorithm needs to be:
Accurate
Repeatable
Concise
Optimized
These four qualities can be easily understood with the recipe example.
The recipe is accurate, in the sense that it can create tasty chocolate chip cookies. Note the emphasis on âtastyâ. The recipe does not create âhealthyâ cookies. For that matter, the word âhealthyâ has its own set of attributes, which are somewhat subjective (does healthy mean less carb? More protein? Less cholesterol? More vitamins?) and mutually interdependent (higher magnesium and phosphorus in a readily available ingredient like brown sugar may also mean higher carb).
Repeatable is easily demonstrated by being able to use the recipe again and again for making delicious cookies. A recipe would not be so repeatable if it requires an ingredient that is tough to procure. Or sometimes the product is self-destructive, which does not make it repeatable. A good example of a self-destructive algorithm is a video shoot of an accident.
Concise is a quality of being able to express in a few words. For example, I want to say that I suffer from a problem where my lens in my right eye is unable to focus light beyond a distance in front of my retina. I can express it with the term âmyopiaâ. While this is just a better way to communicate in this instance, for an algorithm that is concise, it can have a huge consequence, such as reduce the cost of producing a vaccine by 50% or increase the chances striking oil in the ground by 30%.
The dictionary meaning of âoptimizedâ is âmake the best or most effective use of a situation, opportunity, or resourceâ. Optimized is a quality that is the hardest to understand. Optimized can mean many things based on the âsituation, opportunity or resourceâ that is optimized. For example, the Tesla model 3 is the most fuel-efficient car in the âmidsizeâ class of cars in 2020, as determined by fueleconomy.gov. Note that I had to qualify this statement by the year and the âclassâ. Even in 2020, the most fuel-efficient class of âcompactâ cars is not Teslaâit is Volkswagen e-Golf. And the most fuel-efficient âmidsizeâ car in 2015 was Nissan Leaf.
The point I want you to take away from this discussion is that no good quality is an absolute value. True for life as well, the qualities that make the evaluation of anything âgoodâ or âbadâ are bound by the parameters that are used to judge them.
We will discuss these qualities further in the next few chapters, as we dive deep into the programs that I will introduce to get you inspired.
So why do we need algorithms?
Algorithms are to program development what a recipe is to the preparation of a dishâa bit more in some respects and a bit less in others.
An algorithm for a program describes how the code needs to be written in conceptual terms.
Even though there is no precise measurement like a recipe, an algorithm is a documentation of technique that is indispensable for the programmer. Just as you cannot make cookies without a recipe, you cannot write a program that solves a specific problem without an algorithm.
An algorithm usually has six parts to it:
Inputs
Outputs
Variables
Statements
Conditional Statements
Repetitions
The input is what is available for the processor to work withâfor example, the flour and the sugar.
The output is the cookie but can be other things as well, such as a timer that chimes when the cooking is done (audible output), or the mixers and plates that need to be washed after the cookie is made (visible outputs).
Variables are receptacles that temporarily store something so that you can remember it or use it later on. For example, you have a glass of water and you need to use only half of it now and half later. You will need another glass to pour the other half until you need it. Now suppose that you do not have a measuring stick to measure the height of the glass, and you do not want to rely on your judgment to determine whether it is exactly halfâwhat do you do? You get another glass that looks exactly like the other two glasses. You pour the full glass into the two empty ones and check their heights by placing them side by side. If one is higher, you pour a little bit from the glass with the greater height to the glass with the lesser height.
A statement is usually an instruction to do somethingâthe most common being moving data from one variable to another. In the glass example above, pouring water from one glass to another in an attempt to equalize is a statement.
A condition is a decision point that helps the situation direct the execution of a statement from a choice of more than one statement. In our example above, checking the water level in one glass is higher than the other is a condition. That helps one decide whether to pour the water from the left glass to the right, or from the right glass to the left. Pouring water from one glass to another is a conditional statement. Pouring from left to right is one statement, from right to left is another, and the condition helps us decide which one should be done.
Chances are that just one pour will not equalize the glasses. If you are like me, as soon as I have poured the higher to the lower, the lower now becomes higher! So, we need to do the exact opposite, until we find that the heights are the same. This is known as a repetition. Often described in programming languages as âDo Loopsâ, âWhile Loopsâ and âDo Untilsââthis is the critical part of an algorithm that is immensely useful for a programâbecause it is the repetitive work that a computer program does best, by relieving the human being from this task.
Now let us look at a problem that we can solve using a spreadsheet to understand these six structures in business terms.
Imagine that I am a sales executive in a shoe company that operates in three states. I need to send a report to my boss that summarizes the sales for all three states in one spreadsheet. I have each state in a separate spreadsheet as shown below.
Figure 1.2Sales figures by state.
Figure 1.2 Continued I need to execute the following steps to make my boss happy:
Open a new spreadsheet
Copy spreadsheet A from cells A1 to C7
Paste this in the new spreadsheet in cell A1
Copy spreadsheet B from cells B1 to C7 (note that we did not copy rows 1 and 2 againâsince these are part of the header)
Paste this in the new spreadsheet in cell A8 (note that the row has now advanced to 7 in the new spreadsheet)
Copy spreadsheet C from cells B1 to C7
Paste this in the new spreadsheet in cell A13 (note that the row has now advanced to 12 in the new spreadsheet)
Save new spreadsheet
Send to Boss via email
The final spreadsheet would look something like this.
Figure 1.3Combined spreadsheet.
While this is a precise set of steps to accomplish this task, this is completely manual. If I had 50 states to deal with, this would be taking me too long! I...
Table of contents
Cover
Half-Title Page
Title Page
Copyright Page
Dedication
Table of Contents
Preface
Introduction
1 What Is an Algorithm?
2 Build Your Own Game with a Simple Algorithm: Tic Tac Toe
3 Explore Your Deductive Logic: Solve a Sudoku Forever
4 Introduction to Multiplatform Integration: Build Your Own Remote Control
5 The Organizer: Build Your Own Virtual Filing Cabinet
6 Merging Sheets: Combine Multiple Workbooks of the Same Format into One Workbook Automatically
7 Introduction to Graphs: Create Your Own Interface Diagram Instantly
8 Shaping up: Analyze a Picture and Document Its Components in Text
9 Real-Time Currency Conversion: An Introduction to Simple Web Scraping Techniques
10 The Genius of Collaboration: Build a Burglar Alarm Using a Free Webcam Application
11 Advanced Graphics: Complex Visualizations and More
The Final Word
List of Figures
Bibliography
A Little Bit of Computer Science
Index
Frequently asked questions
Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription
No, books cannot be downloaded as external files, such as PDFs, for use outside of Perlego. However, you can download books within the Perlego app for offline reading on mobile or tablet. Learn how to download books offline
Perlego offers two plans: Essential and Complete
Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.5M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Both plans are available with monthly, semester, or annual billing cycles.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1.5 million books across 990+ topics, weâve got you covered! Learn about our mission
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more about Read Aloud
Yes! You can use the Perlego app on both iOS and Android devices to read anytime, anywhere â even offline. Perfect for commutes or when youâre on the go. Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app
Yes, you can access Beginner's Guide to Code Algorithms by Deepankar Maitra in PDF and/or ePUB format, as well as other popular books in Computer Science & Computer Science General. We have over 1.5 million books available in our catalogue for you to explore.