• School Guide
  • Class 8 Syllabus
  • Maths Notes Class 8
  • Science Notes Class 8
  • History Notes Class 8
  • Geography Notes Class 8
  • Civics Notes Class 8
  • NCERT Soln. Class 8 Maths
  • RD Sharma Soln. Class 8
  • Math Formulas Class 8

How to Use Algorithms to Solve Problems?

  • How to use Chat-GPT to solve Coding Problems?
  • Wicked Problems and How to Solve Them?
  • How to implement Genetic Algorithm using PyTorch
  • Best Data Structures and Algorithms Books
  • How to improve your DSA skills?
  • Tricks To Solve Age-Based Problems
  • The Role of Algorithms in Computing
  • Most important type of Algorithms
  • How to Identify & Solve Binary Search Problems?
  • Quiz on Algorithms | DSA MCQs
  • Introduction to Beam Search Algorithm
  • Algorithms Quiz | Sudo Placement [1.8] | Question 5
  • Top 50 Problems on Recursion Algorithm asked in SDE Interviews
  • What are Logical Puzzles And How to Solve them?
  • What is Algorithm | Introduction to Algorithms
  • Top 10 Algorithms in Interview Questions
  • Data Structures & Algorithms Guide for Developers
  • Top 50 Binary Search Tree Coding Problems for Interviews
  • Top 20 Greedy Algorithms Interview Questions

An algorithm is a process or set of rules which must be followed to complete a particular task. This is basically the step-by-step procedure to complete any task. All the tasks are followed a particular algorithm, from making a cup of tea to make high scalable software. This is the way to divide a task into several parts. If we draw an algorithm to complete a task then the task will be easier to complete.

The algorithm is used for,

  • To develop a framework for instructing computers.
  • Introduced notation of basic functions to perform basic tasks.
  • For defining and describing a big problem in small parts, so that it is very easy to execute.

Characteristics of Algorithm

  • An algorithm should be defined clearly.
  • An algorithm should produce at least one output.
  • An algorithm should have zero or more inputs.
  • An algorithm should be executed and finished in finite number of steps.
  • An algorithm should be basic and easy to perform.
  • Each step started with a specific indentation like, “Step-1”,
  • There must be “Start” as the first step and “End” as the last step of the algorithm.

Let’s take an example to make a cup of tea,

Step 1: Start

Step 2: Take some water in a bowl.

Step 3: Put the water on a gas burner .

Step 4: Turn on the gas burner 

Step 5: Wait for some time until the water is boiled.  

Step 6: Add some tea leaves to the water according to the requirement.

Step 7: Then again wait for some time until the water is getting colorful as tea.

Step 8: Then add some sugar according to taste.

Step 9: Again wait for some time until the sugar is melted.

Step 10: Turn off the gas burner and serve the tea in cups with biscuits.

Step 11: End

Here is an algorithm for making a cup of tea. This is the same for computer science problems.

There are some basics steps to make an algorithm:

  • Start – Start the algorithm
  • Input – Take the input for values in which the algorithm will execute.
  • Conditions – Perform some conditions on the inputs to get the desired output.
  • Output – Printing the outputs.
  • End – End the execution.

Let’s take some examples of algorithms for computer science problems.

Example 1. Swap two numbers with a third variable  

Step 1: Start Step 2: Take 2 numbers as input. Step 3: Declare another variable as “temp”. Step 4: Store the first variable to “temp”. Step 5: Store the second variable to the First variable. Step 6: Store the “temp” variable to the 2nd variable. Step 7: Print the First and second variables. Step 8: End

Example 2. Find the area of a rectangle

Step 1: Start Step 2: Take the Height and Width of the rectangle as input. Step 3: Declare a variable as “area” Step 4: Multiply Height and Width Step 5: Store the multiplication to “Area”, (its look like area = Height x Width) Step 6: Print “area”; Step 7: End

Example 3. Find the greatest between 3 numbers.

Step 1: Start Step 2: Take 3 numbers as input, say A, B, and C. Step 3: Check if(A>B and A>C) Step 4: Then A is greater Step 5: Print A Step 6 : Else Step 7: Check if(B>A and B>C) Step 8: Then B is greater Step 9: Print B Step 10: Else C is greater Step 11 : Print C Step 12: End

Advantages of Algorithm

  • An algorithm uses a definite procedure.
  • It is easy to understand because it is a step-by-step definition.
  • The algorithm is easy to debug if there is any error happens.
  • It is not dependent on any programming language
  • It is easier for a programmer to convert it into an actual program because the algorithm divides a problem into smaller parts.

Disadvantages of Algorithms

  • An algorithm is Time-consuming, there is specific time complexity for different algorithms.
  • Large tasks are difficult to solve in Algorithms because the time complexity may be higher, so programmers have to find a good efficient way to solve that task.
  • Looping and branching are difficult to define in algorithms.

Please Login to comment...

Similar reads.

  • School Learning
  • School Programming

Improve your Coding Skills with Practice

 alt=

What kind of Experience do you want to share?

Smart. Open. Grounded. Inventive. Read our Ideas Made to Matter.

Which program is right for you?

MIT Sloan Campus life

Through intellectual rigor and experiential learning, this full-time, two-year MBA program develops leaders who make a difference in the world.

A rigorous, hands-on program that prepares adaptive problem solvers for premier finance careers.

A 12-month program focused on applying the tools of modern data science, optimization and machine learning to solve real-world business problems.

Earn your MBA and SM in engineering with this transformative two-year program.

Combine an international MBA with a deep dive into management science. A special opportunity for partner and affiliate schools only.

A doctoral program that produces outstanding scholars who are leading in their fields of research.

Bring a business perspective to your technical and quantitative expertise with a bachelor’s degree in management, business analytics, or finance.

A joint program for mid-career professionals that integrates engineering and systems thinking. Earn your master’s degree in engineering and management.

An interdisciplinary program that combines engineering, management, and design, leading to a master’s degree in engineering and management.

Executive Programs

A full-time MBA program for mid-career leaders eager to dedicate one year of discovery for a lifetime of impact.

This 20-month MBA program equips experienced executives to enhance their impact on their organizations and the world.

Non-degree programs for senior executives and high-potential managers.

A non-degree, customizable program for mid-career professionals.

Use imagination to make the most of generative AI

Lending standards can be too tight for too long, research finds

US voters exhibit ‘flexible morals’ when confronting misinformation

Credit: Alejandro Giraldo

Ideas Made to Matter

How to use algorithms to solve everyday problems

Kara Baskin

May 8, 2017

How can I navigate the grocery store quickly? Why doesn’t anyone like my Facebook status? How can I alphabetize my bookshelves in a hurry? Apple data visualizer and MIT System Design and Management graduate Ali Almossawi solves these common dilemmas and more in his new book, “ Bad Choices: How Algorithms Can Help You Think Smarter and Live Happier ,” a quirky, illustrated guide to algorithmic thinking. 

For the uninitiated: What is an algorithm? And how can algorithms help us to think smarter?

An algorithm is a process with unambiguous steps that has a beginning and an end, and does something useful.

Algorithmic thinking is taking a step back and asking, “If it’s the case that algorithms are so useful in computing to achieve predictability, might they also be useful in everyday life, when it comes to, say, deciding between alternative ways of solving a problem or completing a task?” In all cases, we optimize for efficiency: We care about time or space.

Note the mention of “deciding between.” Computer scientists do that all the time, and I was convinced that the tools they use to evaluate competing algorithms would be of interest to a broad audience.

Why did you write this book, and who can benefit from it?

All the books I came across that tried to introduce computer science involved coding. My approach to making algorithms compelling was focusing on comparisons. I take algorithms and put them in a scene from everyday life, such as matching socks from a pile, putting books on a shelf, remembering things, driving from one point to another, or cutting an onion. These activities can be mapped to one or more fundamental algorithms, which form the basis for the field of computing and have far-reaching applications and uses.

I wrote the book with two audiences in mind. One, anyone, be it a learner or an educator, who is interested in computer science and wants an engaging and lighthearted, but not a dumbed-down, introduction to the field. Two, anyone who is already familiar with the field and wants to experience a way of explaining some of the fundamental concepts in computer science differently than how they’re taught.

I’m going to the grocery store and only have 15 minutes. What do I do?

Do you know what the grocery store looks like ahead of time? If you know what it looks like, it determines your list. How do you prioritize things on your list? Order the items in a way that allows you to avoid walking down the same aisles twice.

For me, the intriguing thing is that the grocery store is a scene from everyday life that I can use as a launch pad to talk about various related topics, like priority queues and graphs and hashing. For instance, what is the most efficient way for a machine to store a prioritized list, and what happens when the equivalent of you scratching an item from a list happens in the machine’s list? How is a store analogous to a graph (an abstraction in computer science and mathematics that defines how things are connected), and how is navigating the aisles in a store analogous to traversing a graph?

Nobody follows me on Instagram. How do I get more followers?

The concept of links and networks, which I cover in Chapter 6, is relevant here. It’s much easier to get to people whom you might be interested in and who might be interested in you if you can start within the ball of links that connects those people, rather than starting at a random spot.

You mention Instagram: There, the hashtag is one way to enter that ball of links. Tag your photos, engage with users who tag their photos with the same hashtags, and you should be on your way to stardom.

What are the secret ingredients of a successful Facebook post?

I’ve posted things on social media that have died a sad death and then posted the same thing at a later date that somehow did great. Again, if we think of it in terms that are relevant to algorithms, we’d say that the challenge with making something go viral is really getting that first spark. And to get that first spark, a person who is connected to the largest number of people who are likely to engage with that post, needs to share it.

With [my first book], “Bad Arguments,” I spent a month pouring close to $5,000 into advertising for that project with moderate results. And then one science journalist with a large audience wrote about it, and the project took off and hasn’t stopped since.

What problems do you wish you could solve via algorithm but can’t?

When we care about efficiency, thinking in terms of algorithms is useful. There are cases when that’s not the quality we want to optimize for — for instance, learning or love. I walk for several miles every day, all throughout the city, as I find it relaxing. I’ve never asked myself, “What’s the most efficient way I can traverse the streets of San Francisco?” It’s not relevant to my objective.

Algorithms are a great way of thinking about efficiency, but the question has to be, “What approach can you optimize for that objective?” That’s what worries me about self-help: Books give you a silver bullet for doing everything “right” but leave out all the nuances that make us different. What works for you might not work for me.

Which companies use algorithms well?

When you read that the overwhelming majority of the shows that users of, say, Netflix, watch are due to Netflix’s recommendation engine, you know they’re doing something right.

Related Articles

A stack of jeans with network/AI imagery overlayed on top

  • 1. Micro-Worlds
  • 2. Light-Bot in Java
  • 3. Jeroos of Santong Island
  • 4. Problem Solving and Algorithms
  • 5. Creating Jeroo Methods
  • 6. Conditionally Executing Actions
  • 7. Repeating Actions
  • 8. Handling Touch Events
  • 9. Adding Text to the Screen

Problem Solving and Algorithms

Learn a basic process for developing a solution to a problem. Nothing in this chapter is unique to using a computer to solve a problem. This process can be used to solve a wide variety of problems, including ones that have nothing to do with computers.

Problems, Solutions, and Tools

I have a problem! I need to thank Aunt Kay for the birthday present she sent me. I could send a thank you note through the mail. I could call her on the telephone. I could send her an email message. I could drive to her house and thank her in person. In fact, there are many ways I could thank her, but that's not the point. The point is that I must decide how I want to solve the problem, and use the appropriate tool to implement (carry out) my plan. The postal service, the telephone, the internet, and my automobile are tools that I can use, but none of these actually solves my problem. In a similar way, a computer does not solve problems, it's just a tool that I can use to implement my plan for solving the problem.

Knowing that Aunt Kay appreciates creative and unusual things, I have decided to hire a singing messenger to deliver my thanks. In this context, the messenger is a tool, but one that needs instructions from me. I have to tell the messenger where Aunt Kay lives, what time I would like the message to be delivered, and what lyrics I want sung. A computer program is similar to my instructions to the messenger.

The story of Aunt Kay uses a familiar context to set the stage for a useful point of view concerning computers and computer programs. The following list summarizes the key aspects of this point of view.

A computer is a tool that can be used to implement a plan for solving a problem.

A computer program is a set of instructions for a computer. These instructions describe the steps that the computer must follow to implement a plan.

An algorithm is a plan for solving a problem.

A person must design an algorithm.

A person must translate an algorithm into a computer program.

This point of view sets the stage for a process that we will use to develop solutions to Jeroo problems. The basic process is important because it can be used to solve a wide variety of problems, including ones where the solution will be written in some other programming language.

An Algorithm Development Process

Every problem solution starts with a plan. That plan is called an algorithm.

There are many ways to write an algorithm. Some are very informal, some are quite formal and mathematical in nature, and some are quite graphical. The instructions for connecting a DVD player to a television are an algorithm. A mathematical formula such as πR 2 is a special case of an algorithm. The form is not particularly important as long as it provides a good way to describe and check the logic of the plan.

The development of an algorithm (a plan) is a key step in solving a problem. Once we have an algorithm, we can translate it into a computer program in some programming language. Our algorithm development process consists of five major steps.

Step 1: Obtain a description of the problem.

Step 2: analyze the problem., step 3: develop a high-level algorithm., step 4: refine the algorithm by adding more detail., step 5: review the algorithm..

This step is much more difficult than it appears. In the following discussion, the word client refers to someone who wants to find a solution to a problem, and the word developer refers to someone who finds a way to solve the problem. The developer must create an algorithm that will solve the client's problem.

The client is responsible for creating a description of the problem, but this is often the weakest part of the process. It's quite common for a problem description to suffer from one or more of the following types of defects: (1) the description relies on unstated assumptions, (2) the description is ambiguous, (3) the description is incomplete, or (4) the description has internal contradictions. These defects are seldom due to carelessness by the client. Instead, they are due to the fact that natural languages (English, French, Korean, etc.) are rather imprecise. Part of the developer's responsibility is to identify defects in the description of a problem, and to work with the client to remedy those defects.

The purpose of this step is to determine both the starting and ending points for solving the problem. This process is analogous to a mathematician determining what is given and what must be proven. A good problem description makes it easier to perform this step.

When determining the starting point, we should start by seeking answers to the following questions:

What data are available?

Where is that data?

What formulas pertain to the problem?

What rules exist for working with the data?

What relationships exist among the data values?

When determining the ending point, we need to describe the characteristics of a solution. In other words, how will we know when we're done? Asking the following questions often helps to determine the ending point.

What new facts will we have?

What items will have changed?

What changes will have been made to those items?

What things will no longer exist?

An algorithm is a plan for solving a problem, but plans come in several levels of detail. It's usually better to start with a high-level algorithm that includes the major part of a solution, but leaves the details until later. We can use an everyday example to demonstrate a high-level algorithm.

Problem: I need a send a birthday card to my brother, Mark.

Analysis: I don't have a card. I prefer to buy a card rather than make one myself.

High-level algorithm:

Go to a store that sells greeting cards Select a card Purchase a card Mail the card

This algorithm is satisfactory for daily use, but it lacks details that would have to be added were a computer to carry out the solution. These details include answers to questions such as the following.

"Which store will I visit?"

"How will I get there: walk, drive, ride my bicycle, take the bus?"

"What kind of card does Mark like: humorous, sentimental, risqué?"

These kinds of details are considered in the next step of our process.

A high-level algorithm shows the major steps that need to be followed to solve a problem. Now we need to add details to these steps, but how much detail should we add? Unfortunately, the answer to this question depends on the situation. We have to consider who (or what) is going to implement the algorithm and how much that person (or thing) already knows how to do. If someone is going to purchase Mark's birthday card on my behalf, my instructions have to be adapted to whether or not that person is familiar with the stores in the community and how well the purchaser known my brother's taste in greeting cards.

When our goal is to develop algorithms that will lead to computer programs, we need to consider the capabilities of the computer and provide enough detail so that someone else could use our algorithm to write a computer program that follows the steps in our algorithm. As with the birthday card problem, we need to adjust the level of detail to match the ability of the programmer. When in doubt, or when you are learning, it is better to have too much detail than to have too little.

Most of our examples will move from a high-level to a detailed algorithm in a single step, but this is not always reasonable. For larger, more complex problems, it is common to go through this process several times, developing intermediate level algorithms as we go. Each time, we add more detail to the previous algorithm, stopping when we see no benefit to further refinement. This technique of gradually working from a high-level to a detailed algorithm is often called stepwise refinement .

The final step is to review the algorithm. What are we looking for? First, we need to work through the algorithm step by step to determine whether or not it will solve the original problem. Once we are satisfied that the algorithm does provide a solution to the problem, we start to look for other things. The following questions are typical of ones that should be asked whenever we review an algorithm. Asking these questions and seeking their answers is a good way to develop skills that can be applied to the next problem.

Does this algorithm solve a very specific problem or does it solve a more general problem ? If it solves a very specific problem, should it be generalized?

For example, an algorithm that computes the area of a circle having radius 5.2 meters (formula π*5.2 2 ) solves a very specific problem, but an algorithm that computes the area of any circle (formula π*R 2 ) solves a more general problem.

Can this algorithm be simplified ?

One formula for computing the perimeter of a rectangle is:

length + width + length + width

A simpler formula would be:

2.0 * ( length + width )

Is this solution similar to the solution to another problem? How are they alike? How are they different?

For example, consider the following two formulae:

Rectangle area = length * width Triangle area = 0.5 * base * height

Similarities: Each computes an area. Each multiplies two measurements.

Differences: Different measurements are used. The triangle formula contains 0.5.

Hypothesis: Perhaps every area formula involves multiplying two measurements.

Example 4.1: Pick and Plant

This section contains an extended example that demonstrates the algorithm development process. To complete the algorithm, we need to know that every Jeroo can hop forward, turn left and right, pick a flower from its current location, and plant a flower at its current location.

Problem Statement (Step 1)

A Jeroo starts at (0, 0) facing East with no flowers in its pouch. There is a flower at location (3, 0). Write a program that directs the Jeroo to pick the flower and plant it at location (3, 2). After planting the flower, the Jeroo should hop one space East and stop. There are no other nets, flowers, or Jeroos on the island.

Analysis of the Problem (Step 2)

The flower is exactly three spaces ahead of the jeroo.

The flower is to be planted exactly two spaces South of its current location.

The Jeroo is to finish facing East one space East of the planted flower.

There are no nets to worry about.

High-level Algorithm (Step 3)

Let's name the Jeroo Bobby. Bobby should do the following:

Get the flower Put the flower Hop East

Detailed Algorithm (Step 4)

Get the flower Hop 3 times Pick the flower Put the flower Turn right Hop 2 times Plant a flower Hop East Turn left Hop once

Review the Algorithm (Step 5)

The high-level algorithm partitioned the problem into three rather easy subproblems. This seems like a good technique.

This algorithm solves a very specific problem because the Jeroo and the flower are in very specific locations.

This algorithm is actually a solution to a slightly more general problem in which the Jeroo starts anywhere, and the flower is 3 spaces directly ahead of the Jeroo.

Java Code for "Pick and Plant"

A good programmer doesn't write a program all at once. Instead, the programmer will write and test the program in a series of builds. Each build adds to the previous one. The high-level algorithm will guide us in this process.

FIRST BUILD

To see this solution in action, create a new Greenfoot4Sofia scenario and use the Edit Palettes Jeroo menu command to make the Jeroo classes visible. Right-click on the Island class and create a new subclass with the name of your choice. This subclass will hold your new code.

The recommended first build contains three things:

The main method (here myProgram() in your island subclass).

Declaration and instantiation of every Jeroo that will be used.

The high-level algorithm in the form of comments.

The instantiation at the beginning of myProgram() places bobby at (0, 0), facing East, with no flowers.

Once the first build is working correctly, we can proceed to the others. In this case, each build will correspond to one step in the high-level algorithm. It may seem like a lot of work to use four builds for such a simple program, but doing so helps establish habits that will become invaluable as the programs become more complex.

SECOND BUILD

This build adds the logic to "get the flower", which in the detailed algorithm (step 4 above) consists of hopping 3 times and then picking the flower. The new code is indicated by comments that wouldn't appear in the original (they are just here to call attention to the additions). The blank lines help show the organization of the logic.

By taking a moment to run the work so far, you can confirm whether or not this step in the planned algorithm works as expected.

THIRD BUILD

This build adds the logic to "put the flower". New code is indicated by the comments that are provided here to mark the additions.

FOURTH BUILD (final)

Example 4.2: replace net with flower.

This section contains a second example that demonstrates the algorithm development process.

There are two Jeroos. One Jeroo starts at (0, 0) facing North with one flower in its pouch. The second starts at (0, 2) facing East with one flower in its pouch. There is a net at location (3, 2). Write a program that directs the first Jeroo to give its flower to the second one. After receiving the flower, the second Jeroo must disable the net, and plant a flower in its place. After planting the flower, the Jeroo must turn and face South. There are no other nets, flowers, or Jeroos on the island.

Jeroo_2 is exactly two spaces behind Jeroo_1.

The only net is exactly three spaces ahead of Jeroo_2.

Each Jeroo has exactly one flower.

Jeroo_2 will have two flowers after receiving one from Jeroo_1. One flower must be used to disable the net. The other flower must be planted at the location of the net, i.e. (3, 2).

Jeroo_1 will finish at (0, 1) facing South.

Jeroo_2 is to finish at (3, 2) facing South.

Each Jeroo will finish with 0 flowers in its pouch. One flower was used to disable the net, and the other was planted.

Let's name the first Jeroo Ann and the second one Andy.

Ann should do the following: Find Andy (but don't collide with him) Give a flower to Andy (he will be straight ahead) After receiving the flower, Andy should do the following: Find the net (but don't hop onto it) Disable the net Plant a flower at the location of the net Face South
Ann should do the following: Find Andy Turn around (either left or right twice) Hop (to location (0, 1)) Give a flower to Andy Give ahead Now Andy should do the following: Find the net Hop twice (to location (2, 2)) Disable the net Toss Plant a flower at the location of the net Hop (to location (3, 2)) Plant a flower Face South Turn right

The high-level algorithm helps manage the details.

This algorithm solves a very specific problem, but the specific locations are not important. The only thing that is important is the starting location of the Jeroos relative to one another and the location of the net relative to the second Jeroo's location and direction.

Java Code for "Replace Net with Flower"

As before, the code should be written incrementally as a series of builds. Four builds will be suitable for this problem. As usual, the first build will contain the main method, the declaration and instantiation of the Jeroo objects, and the high-level algorithm in the form of comments. The second build will have Ann give her flower to Andy. The third build will have Andy locate and disable the net. In the final build, Andy will place the flower and turn East.

This build creates the main method, instantiates the Jeroos, and outlines the high-level algorithm. In this example, the main method would be myProgram() contained within a subclass of Island .

This build adds the logic for Ann to locate Andy and give him a flower.

This build adds the logic for Andy to locate and disable the net.

This build adds the logic for Andy to place a flower at (3, 2) and turn South.

Logo for TRU Pressbooks

Want to create or adapt books like this? Learn more about how Pressbooks supports open publishing practices.

8.2 Problem-Solving: Heuristics and Algorithms

Learning objectives.

  • Describe the differences between heuristics and algorithms in information processing.

When faced with a problem to solve, should you go with intuition or with more measured, logical reasoning? Obviously, we use both of these approaches. Some of the decisions we make are rapid, emotional, and automatic. Daniel Kahneman (2011) calls this “fast” thinking. By definition, fast thinking saves time. For example, you may quickly decide to buy something because it is on sale; your fast brain has perceived a bargain, and you go for it quickly. On the other hand, “slow” thinking requires more effort; applying this in the same scenario might cause us not to buy the item because we have reasoned that we don’t really need it, that it is still too expensive, and so on. Using slow and fast thinking does not guarantee good decision-making if they are employed at the wrong time. Sometimes it is not clear which is called for, because many decisions have a level of uncertainty built into them. In this section, we will explore some of the applications of these tendencies to think fast or slow.

We will look further into our thought processes, more specifically, into some of the problem-solving strategies that we use. Heuristics are information-processing strategies that are useful in many cases but may lead to errors when misapplied. A heuristic is a principle with broad application, essentially an educated guess about something. We use heuristics all the time, for example, when deciding what groceries to buy from the supermarket, when looking for a library book, when choosing the best route to drive through town to avoid traffic congestion, and so on. Heuristics can be thought of as aids to decision making; they allow us to reach a solution without a lot of cognitive effort or time.

The benefit of heuristics in helping us reach decisions fairly easily is also the potential downfall: the solution provided by the use of heuristics is not necessarily the best one. Let’s consider some of the most frequently applied, and misapplied, heuristics in the table below.

In many cases, we base our judgments on information that seems to represent, or match, what we expect will happen, while ignoring other potentially more relevant statistical information. When we do so, we are using the representativeness heuristic . Consider, for instance, the data presented in the table below. Let’s say that you went to a hospital, and you checked the records of the babies that were born on that given day. Which pattern of births do you think you are most likely to find?

Most people think that list B is more likely, probably because list B looks more random, and matches — or is “representative of” — our ideas about randomness, but statisticians know that any pattern of four girls and four boys is mathematically equally likely. Whether a boy or girl is born first has no bearing on what sex will be born second; these are independent events, each with a 50:50 chance of being a boy or a girl. The problem is that we have a schema of what randomness should be like, which does not always match what is mathematically the case. Similarly, people who see a flipped coin come up “heads” five times in a row will frequently predict, and perhaps even wager money, that “tails” will be next. This behaviour is known as the gambler’s fallacy . Mathematically, the gambler’s fallacy is an error: the likelihood of any single coin flip being “tails” is always 50%, regardless of how many times it has come up “heads” in the past.

The representativeness heuristic may explain why we judge people on the basis of appearance. Suppose you meet your new next-door neighbour, who drives a loud motorcycle, has many tattoos, wears leather, and has long hair. Later, you try to guess their occupation. What comes to mind most readily? Are they a teacher? Insurance salesman? IT specialist? Librarian? Drug dealer? The representativeness heuristic will lead you to compare your neighbour to the prototypes you have for these occupations and choose the one that they seem to represent the best. Thus, your judgment is affected by how much your neibour seems to resemble each of these groups. Sometimes these judgments are accurate, but they often fail because they do not account for base rates , which is the actual frequency with which these groups exist. In this case, the group with the lowest base rate is probably drug dealer.

Our judgments can also be influenced by how easy it is to retrieve a memory. The tendency to make judgments of the frequency or likelihood that an event occurs on the basis of the ease with which it can be retrieved from memory is known as the availability heuristic (MacLeod & Campbell, 1992; Tversky & Kahneman, 1973). Imagine, for instance, that I asked you to indicate whether there are more words in the English language that begin with the letter “R” or that have the letter “R” as the third letter. You would probably answer this question by trying to think of words that have each of the characteristics, thinking of all the words you know that begin with “R” and all that have “R” in the third position. Because it is much easier to retrieve words by their first letter than by their third, we may incorrectly guess that there are more words that begin with “R,” even though there are in fact more words that have “R” as the third letter.

The availability heuristic may explain why we tend to overestimate the likelihood of crimes or disasters; those that are reported widely in the news are more readily imaginable, and therefore, we tend to overestimate how often they occur. Things that we find easy to imagine, or to remember from watching the news, are estimated to occur frequently. Anything that gets a lot of news coverage is easy to imagine. Availability bias does not just affect our thinking. It can change behaviour. For example, homicides are usually widely reported in the news, leading people to make inaccurate assumptions about the frequency of murder. In Canada, the murder rate has dropped steadily since the 1970s (Statistics Canada, 2018), but this information tends not to be reported, leading people to overestimate the probability of being affected by violent crime. In another example, doctors who recently treated patients suffering from a particular condition were more likely to diagnose the condition in subsequent patients because they overestimated the prevalence of the condition (Poses & Anthony, 1991).

The anchoring and adjustment heuristic is another example of how fast thinking can lead to a decision that might not be optimal. Anchoring and adjustment is easily seen when we are faced with buying something that does not have a fixed price. For example, if you are interested in a used car, and the asking price is $10,000, what price do you think you might offer? Using $10,000 as an anchor, you are likely to adjust your offer from there, and perhaps offer $9000 or $9500. Never mind that $10,000 may not be a reasonable anchoring price. Anchoring and adjustment does not just happen when we’re buying something. It can also be used in any situation that calls for judgment under uncertainty, such as sentencing decisions in criminal cases (Bennett, 2014), and it applies to groups as well as individuals (Rutledge, 1993).

In contrast to heuristics, which can be thought of as problem-solving strategies based on educated guesses, algorithms are problem-solving strategies that use rules. Algorithms are generally a logical set of steps that, if applied correctly, should be accurate. For example, you could make a cake using heuristics — relying on your previous baking experience and guessing at the number and amount of ingredients, baking time, and so on — or using an algorithm. The latter would require a recipe which would provide step-by-step instructions; the recipe is the algorithm. Unless you are an extremely accomplished baker, the algorithm should provide you with a better cake than using heuristics would. While heuristics offer a solution that might be correct, a correctly applied algorithm is guaranteed to provide a correct solution. Of course, not all problems can be solved by algorithms.

As with heuristics, the use of algorithmic processing interacts with behaviour and emotion. Understanding what strategy might provide the best solution requires knowledge and experience. As we will see in the next section, we are prone to a number of cognitive biases that persist despite knowledge and experience.

Key Takeaways

  • We use a variety of shortcuts in our information processing, such as the representativeness, availability, and anchoring and adjustment heuristics. These help us to make fast judgments but may lead to errors.
  • Algorithms are problem-solving strategies that are based on rules rather than guesses. Algorithms, if applied correctly, are far less likely to result in errors or incorrect solutions than heuristics. Algorithms are based on logic.

Bennett, M. W. (2014). Confronting cognitive ‘anchoring effect’ and ‘blind spot’ biases in federal sentencing: A modest solution for reforming and fundamental flaw. Journal of Criminal Law and Criminology , 104 (3), 489-534.

Kahneman, D. (2011). Thinking, fast and slow. New York, NY: Farrar, Straus and Giroux.

MacLeod, C., & Campbell, L. (1992). Memory accessibility and probability judgments: An experimental evaluation of the availability heuristic.  Journal of Personality and Social Psychology, 63 (6), 890–902.

Poses, R. M., & Anthony, M. (1991). Availability, wishful thinking, and physicians’ diagnostic judgments for patients with suspected bacteremia.  Medical Decision Making,  11 , 159-68.

Rutledge, R. W. (1993). The effects of group decisions and group-shifts on use of the anchoring and adjustment heuristic. Social Behavior and Personality, 21 (3), 215-226.

Statistics Canada. (2018). Ho micide in Canada, 2017 . Retrieved from https://www150.statcan.gc.ca/n1/en/daily-quotidien/181121/dq181121a-eng.pdf

Tversky, A., & Kahneman, D. (1973). Availability: A heuristic for judging frequency and probability.  Cognitive Psychology, 5 , 207–232.

Psychology - 1st Canadian Edition Copyright © 2020 by Sally Walters is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License , except where otherwise noted.

Share This Book

Learn Python practically and Get Certified .

Popular Tutorials

Popular examples, reference materials, learn python interactively, dsa introduction.

  • What is an algorithm?
  • Data Structure and Types
  • Why learn DSA?
  • Asymptotic Notations
  • Master Theorem
  • Divide and Conquer Algorithm

Data Structures (I)

  • Types of Queue
  • Circular Queue
  • Priority Queue

Data Structures (II)

  • Linked List
  • Linked List Operations
  • Types of Linked List
  • Heap Data Structure
  • Fibonacci Heap
  • Decrease Key and Delete Node Operations on a Fibonacci Heap

Tree based DSA (I)

  • Tree Data Structure
  • Tree Traversal
  • Binary Tree
  • Full Binary Tree
  • Perfect Binary Tree
  • Complete Binary Tree
  • Balanced Binary Tree
  • Binary Search Tree

Tree based DSA (II)

  • Insertion in a B-tree
  • Deletion from a B-tree
  • Insertion on a B+ Tree
  • Deletion from a B+ Tree
  • Red-Black Tree
  • Red-Black Tree Insertion
  • Red-Black Tree Deletion

Graph based DSA

  • Graph Data Structure
  • Spanning Tree
  • Strongly Connected Components
  • Adjacency Matrix
  • Adjacency List
  • DFS Algorithm
  • Breadth-first Search

Bellman Ford's Algorithm

Sorting and Searching Algorithms

  • Bubble Sort
  • Selection Sort
  • Insertion Sort
  • Counting Sort
  • Bucket Sort
  • Linear Search
  • Binary Search

Greedy Algorithms

Greedy Algorithm

  • Ford-Fulkerson Algorithm
  • Dijkstra's Algorithm
  • Kruskal's Algorithm
  • Prim's Algorithm
  • Huffman Coding

Dynamic Programming

  • Floyd-Warshall Algorithm
  • Longest Common Sequence

Other Algorithms

  • Backtracking Algorithm
  • Rabin-Karp Algorithm

DSA Tutorials

Merge Sort Algorithm

  • Selection Sort Algorithm

What is an Algorithm?

In computer programming terms, an algorithm is a set of well-defined instructions to solve a particular problem. It takes a set of input(s) and produces the desired output. For example,

An algorithm to add two numbers:

Take two number inputs

Add numbers using the + operator

Display the result

Qualities of a Good Algorithm

  • Input and output should be defined precisely.
  • Each step in the algorithm should be clear and unambiguous.
  • Algorithms should be most effective among many different ways to solve a problem.
  • An algorithm shouldn't include computer code. Instead, the algorithm should be written in such a way that it can be used in different programming languages.

Algorithm Examples

Algorithm to add two numbers

Algorithm to find the largest among three numbers

Algorithm to find all the roots of the quadratic equation

Algorithm to find the factorial

Algorithm to check prime number

Algorithm of Fibonacci series

Algorithm 1: Add two numbers entered by the user

Algorithm 2: find the largest number among three numbers, algorithm 3: find roots of a quadratic equation ax 2 + bx + c = 0, algorithm 4: find the factorial of a number, algorithm 5: check whether a number is prime or not, algorithm 6: find the fibonacci series till the term less than 1000, table of contents.

  • Qualities of Good Algorithms
  • Add Two Numbers
  • Find Largest Number
  • Roots of Quatratic Equation
  • Find Factorial of a Number
  • Check Prime Number
  • Find Fibonacci Series

Sorry about that.

Related Tutorials

DS & Algorithms

DEV Community

DEV Community

Ezra Schwepker

Posted on Apr 10, 2019

Algorithm Problem Solving Strategies

Algorithm puzzles are an unfortunately common way to weed out candidates in the application process. However, when you aren't stressing over the job search, they're actually a lot of fun, like crossword puzzles for coders.

Solving them presents unique challenges that you won't encounter when spinning up Yet Another Crud App and exposes you to concepts that you might not already be familiar with. Practicing algorithm challenges will improve your broader problem solving abilities, as well as cement a problem solving process that is more generically useful.

Much like other types of puzzles, there are strategies that give you an early foothold into the problem and a way to break it down into smaller, more approachable chunks. With an actual puzzle, you might sort the pieces into coherent groups of similar colors or features, find look for obvious matches and grow outwards. With minesweeper, you might start with a random click, and then move around the exposed edges, marking off obvious mines and exposes obvious clear areas, only clicking randomly once more when you've exhausted all possibilities.

While there are strategies for approaching similar kinds of algorithms, I would recommend that you start with a broader problem solving strategy that you embrace as a general habit, and not just when you're grinding LeetCode as interview prep.

Be Strategic, Think First

Rather than diving in, approach the problem in stages:

  • Analyze the problem
  • Restate the problem
  • Write out examples of input and output
  • Break the problem into its component parts
  • Outline a solution in psuedo-code
  • Step through your example data with your psuedo-code
  • Test your solution against your examples

(If you're familiar with this approach, skip down to Algorithm Patterns)

Analyze the Problem

You may have had a flash of insight when you first saw the problem. This is typically your mind connecting to some prior experience. Hold on to that insight! However, you should still spend some time looking at the problem, particularly for ways that your insight differs from the actual question.

Any well written puzzle has the components needed to answer the problem contained in a sentence or two. However just because you read the problem doesn't mean you understand the problem. And if you don't understand the problem, you will stumble about aimlessly, or solve what you assumed the problem was.

Look for key words which determine the shape of the challenge.

Identify the input. Identify the desired output. Identify critical keywords and phrases.

For example, LeetCode #26

Given a [sorted] [array] nums, [remove the duplicates] [in-place] such that each element appear only once and [return the new length]. Do not allocate extra space for another array, you must do this by modifying the input array in-place with [O(1) extra memory].
  • an array. So we know we're probably going to do some kind of iteration.
  • an array of numbers. That's more implied rather than specifically stated and doesn't really matter as much as we can use the same set of conditionals.
  • length of altered array
  • side effect: a modified array

Critical Words and Phrases:

  • sorted: repeated elements will be next to each other
  • remove...duplicates
  • in-place: the array itself must be destructively modified. This constraint dictates what array methods we may use.
  • O(1) extra memory: we are limited to O(1) space complexity, allowing us to define variables, but not create a copy of the array.

Restate the Problem

Now, in our own words, rephrase this so it is meaningful to ourselves. If you are in an interviewing situation, you may restate it back to the interviewer, both to set it in your own mind, and to make sure that you heard and understood them correctly.

Given a sorted array of numbers, passed by reference, destructively modify the original array in-place by removing duplicate, so that each value only appears once. Return the length of the modified array.

Write out Example Inputs and Expected Outputs

All we are doing is mapping inputs to outputs. The challenge is figuring out how to get from A to B, however first we need to establish what A and B are . Even if you are given test cases, write your own. Looking at something doesn't create nearly as much understanding as doing it for yourself.

This is also a great time to explore your understanding of the problem and look for quirks that might trip up a naive solution. That includes edge cases like empty inputs, an array filled with duplicates of the same value, a massive data set, etc. We don't need to worry about anything outside of the constraints of the problem

Write out at least 3 examples:

Given the inputs, do you have enough information to map to the result? If you don't, take a step back and continue examining the problem before continuing. If you are interviewing, feel free to ask for clarification.

Look for a simple and consistent process that you can apply regardless of the value to reach the outcome. If you end up with a convoluted series of steps and exceptions, you've likely gone too far and passed over a simpler solution.

Break the Problem into Small Parts

Starting with the simplest possible example, simply the problem down to an essential puzzle and build upon that. In this case, that is an array of three elements, two duplicated, e.g. [1, 1, 2] . Reducing the problem to such a small case makes it more approachable and clarifies the the first step you need to take. Your task from there is to develop a procedure which solves that simple case and holds true for all other cases in the problem set.

So we know we need to do a couple things:

  • Iterate through an array
  • Keep track of where in the array we are
  • Check adjacent values for equality
  • Destructively remove any duplicate values after the first occurrence
  • Get the final array length and return it

This is a relatively simple example problem, however there is a gotcha lurking in it: lots of iteration methods don't play nicely with removing elements from the array while you're iterating through the array, because the index values change. You may end up skipping a duplicate because the pointer incremented over it.

This gotcha indicates that we'll want to use an approach that gives us explicit control of iteration.

In a more involved problem, we might consider some or all of these components into helper functions, allowing us to write a clear and succinct solution, as well as test the validity of each of our sub-parts separately.

Psuedocode the Solution

If we've clearly grasped the problem, identified the core tasks and hopefully spotted the flaws in our own assumptions and any gotchas, we write out a human-legible description of what our approach will be. Hopefully once we've done that we can cleanly transform it into working code.

How you write pseudocode is up to you. Your notation doesn't need to be perfectly spelled and grammatically correct. It can be a gestural combination of code and words meant to convey meaning. Your pseudocode will provide a meaningful roadmap that you can refer back to if you find yourself lost deep in the particulars of implementation, so make sure that you record enough to be useful later.

If you're interviewing, this is a great opportunity to walk the interviewer through your intent. And if you're running out of time, you will at least have something on the board that demonstrates your problem solving approach.

Recommendations:

  • start with a function signature: removeDuplicates :: (Array) -> number
  • if whiteboarding, leave plenty of space to write your actual code
  • if using an IDE, write comments and keep them separate from your code so you can reference back later on.
  • write it as a series of steps and use bullet points

Since we're looking for duplicates, that means we need to perform a comparison. We can look ahead of our current position in the array, or we can look behind.

We start by exiting if our array is only 0 or 1 elements in size, partly because these cases satisfy the conditions of the problem: there are no duplicates possible, and partly because they'll break our code if we try and compare the first value with a second that doesn't exist.

We also establish our iteration exit condition, and because we'll be using a look-ahead, we make sure to stop before we reach the last element.

Because we don't move our pointer position until after we've dealt with any duplicates, we should be clear of the shifting indices issue.

Step Through the Sample Data

Take a moment and mentally run some of the sample data through our pseudocode:

Are we missing anything?

There may be an issue with the last example: [1, 1, 1, 1, 1] . What happens if we remove all of the duplicates, and then try and move on to the next element in our array without checking to see if there are any?

We'll want to make sure that our end condition catches any changes in the array length.

Time for rubber to meet the road. This is where you have all of the assumptions you didn't even know you made come back to haunt you. The better you were able to plan, the fewer there will be.

Personally I like to put in my return values first. That way I'm clear on what my goal is, and I've also captured the first case of empty or single element arrays.

Yup, we're going with a standard for-loop. I prefer not to use them if there's more appropriate or cleaner syntax, but for this particular problem, we need the ability to control our iteration.

And that works out of the box, except for:

Turns out the existence check I snuck in the while loop resolves to falsy if the array value is 0 . Thanks JavaScript! So let's just rework that real quick and do a look behind instead of look ahead, which actually cleans the code up a tad as well:

And that passes. It's a memory efficient solution, we've only defined 1 variable besides the array reference. And it is of average speed, which we could improve upon.

But mostly it was a simple example of a process:

  • Write examples
  • Break into small problems
  • Outline in pseudocode
  • Step through pseudocode with examples

Algorithm Patterns

Aside from specific data structures and algorithms which have known and fairly standardized approaches, algorithm challenges tend to fall into categories that suggest similar solution approaches. Learning these approaches gives you a foothold into the problem.

Multiple Pointers

When we first learn to iterate through a collection, typically an array, we do so with a single pointer with an index going from the lowest value to the highest. This works for some operations and is simple to consider and code. However for problems involving comparing multiple elements, particularly ones where their position in the collection is important, finding corresponding value with a single pointer requires iterating through the array at least once for each value, an O(n 2) operation.

If instead we use multiple multiple points we can potentially reduce the computation down to an O(n) operation.

There are two common strategies: Two Pointer and Sliding Window

Two Pointer

Why not start at both ends and work your way in? Or start at a value or pair of values and expand outwards. This is a great approach for finding the largest sequence in a collection.

Because you are handling two points, you will need to define a rule to ensure that they do not cross over each other.

Sliding Window

Instead of placing two points at the outer bounds, we can march through our array sequentially moving two pointers in parallel. The width of our window may grow or shrink according to the problem set, but it continues to progress across the collection, capturing a snapshot of whatever sequence best fits the desired outcome.

Divide and Conquer

Divide and Conquer often involves a recursive approach: applying the same rule to divide a collection until you've broken it down into the smallest components and identify the answer.

Binary Search and Merge Sort are both excellent examples of recursive subdivision leading to a solution.

O(1) Lookup: Object/Dictionary/Hash

Hashed Key:Value stores, called Objects, Dictionaries or Hashes depending upon your coding language, are incredibly useful tools for storing information when counting frequency, checking for duplicates or the complement of an answer. As there

You may store the value, or you may store the value that you are looking for instead. For example, when looking for zero-sum pairs in an array, we can save the complement rather than the value itself.

Fundamentals of Algorithmic Problem Solving (video) Algorithmic Problem Solving for Programmers Top 10 Algorithms in Interview Questions Improving your Algorithms and Data Structure Skills

Top comments (3)

pic

Templates let you quickly answer FAQs or store snippets for re-use.

yangbahn profile image

  • Location New York, NY
  • Education Cooper Union BFA, NYU MFA - Visual Art
  • Joined Jan 21, 2021

This is a great break down of how to approach solving algorithm problems. I really appreciated the step by step explanations and concrete examples. Thanks!

maxoralbay profile image

  • Location Kazakhstan, Shymkent
  • Work Middle Software developer
  • Joined Feb 18, 2021

Thanks! It is a great tutor how to start solve the problem! And don't worry if someone said about typo in the words. The context is important! I will keep your strategic as main for myself

ericdouglas profile image

  • Joined Feb 13, 2020

I did not finish the reading yet but just want to point that in several places you have a typo in the word Pseudocode . Do a search using the word "psuedo" and you will find it in 3 places.

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink .

Hide child comments as well

For further actions, you may consider blocking this person and/or reporting abuse

jetthoughts_61 profile image

Communication Agreement in a remote environment

JT Dev - May 15

How to know what your team is doing?

sushcod3 profile image

Flexbox CSS: Cheatsheet

Sushmoy - May 15

audreymengue profile image

Vos commandes Git quotidiennes

Audrey Mengue - May 15

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

  • Bipolar Disorder
  • Therapy Center
  • When To See a Therapist
  • Types of Therapy
  • Best Online Therapy
  • Best Couples Therapy
  • Best Family Therapy
  • Managing Stress
  • Sleep and Dreaming
  • Understanding Emotions
  • Self-Improvement
  • Healthy Relationships
  • Student Resources
  • Personality Types
  • Guided Meditations
  • Verywell Mind Insights
  • 2024 Verywell Mind 25
  • Mental Health in the Classroom
  • Editorial Process
  • Meet Our Review Board
  • Crisis Support

What Is an Algorithm in Psychology?

Definition, Examples, and Uses

Kendra Cherry, MS, is a psychosocial rehabilitation specialist, psychology educator, and author of the "Everything Psychology Book."

example of algorithm problem solving

 James Lacy, MLS, is a fact-checker and researcher.

example of algorithm problem solving

How Does an Algorithm Work?

Examples of algorithms.

  • Reasons to Use Algorithms
  • Potential Pitfalls

Algorithms vs. Heuristics

When solving a problem , choosing the right approach is often the key to arriving at the best solution. In psychology, one of these problem-solving approaches is known as an algorithm. While often thought of purely as a mathematical term, the same type of process can be followed in psychology to find the correct answer when solving a problem or making a decision.

An algorithm is a defined set of step-by-step procedures that provides the correct answer to a particular problem. By following the instructions correctly, you are guaranteed to arrive at the right answer.

At a Glance

Algorithms involve following specific steps in order to reach a solution to a problem. They can be a great tool when you need an accurate solution but tend to be more time-consuming than other methods.

This article discusses how algorithms are used as an approach to problem-solving. It also covers how psychologists compare this approach to other problem-solving methods.

An algorithm is often expressed in the form of a graph, where a square represents each step. Arrows then branch off from each step to point to possible directions that you may take to solve the problem.

In some cases, you must follow a particular set of steps to solve the problem. In other instances, you might be able to follow different paths that will all lead to the same solution.

Algorithms are essential step-by-step approaches to solving a problem. Rather than guessing or using trial-and-error, this approach is more likely to guarantee a specific solution. 

Using an algorithm can help you solve day-to-day problems you face, but it can also help mental health professionals find ways to help people cope with mental health problems.

For example, a therapist might use an algorithm to treat a person experiencing something like anxiety. Because the therapist knows that a particular approach is likely to be effective, they would recommend a series of specific, focused steps as part of their intervention.

There are many different examples of how algorithms can be used in daily life. Some common ones include:

  • A recipe for cooking a particular dish
  • The method a search engine uses to find information on the internet
  • Instructions for how to assemble a bicycle
  • Instructions for how to solve a Rubik's cube
  • A process to determine what type of treatment is most appropriate for certain types of mental health conditions

Doctors and mental health professionals often use algorithms to diagnose mental disorders . For example, they may use a step-by-step approach when they evaluate people.

This might involve asking the individual about their symptoms and their medical history. The doctor may also conduct lab tests, physical exams, or psychological assessments.

Using this information, they then utilize the "Diagnostic and Statistical Manual of Mental Disorders" (DSM-5-TR) to make a diagnosis.

Reasons to Use Algorithms in Psychology

The upside of using an algorithm to solve a problem or make a decision is that yields the best possible answer every time. There are situations where using an algorithm can be the best approach:

When Accuracy Is Crucial

Algorithms can be particularly useful in situations when accuracy is critical. They are also a good choice when similar problems need to be frequently solved.

Computer programs can often be designed to speed up this process. Data then needs to be placed in the system so that the algorithm can be executed for the correct solution.

Artificial intelligence may also be a tool for making clinical assessments in healthcare situations.

When Each Decision Needs to Follow the Same Process

Such step-by-step approaches can be useful in situations where each decision must be made following the same process. Because the process follows a prescribed procedure, you can be sure that you will reach the correct answer each time.

Potential Pitfalls When Using Algorithms

The downside of using an algorithm to solve the problem is that this process tends to be very time-consuming.

So if you face a situation where a decision must be made very quickly, you might be better off using a different problem-solving strategy.

For example, an emergency room doctor making a decision about how to treat a patient could use an algorithm approach. However, this would be very time-consuming and treatment needs to be implemented quickly.

In this instance, the doctor would instead rely on their expertise and past experiences to very quickly choose what they feel is the right treatment approach.

Algorithms can sometimes be very complex and may only apply to specific situations. This can limit their use and make them less generalizable when working with larger populations.

Algorithms can be a great problem-solving choice when the answer needs to be 100% accurate or when each decision needs to follow the same process. A different approach might be needed if speed is the primary concern.

In psychology, algorithms are frequently contrasted with heuristics . Both can be useful when problem-solving, but it is important to understand the differences between them.

What Is a Heuristic?

A heuristic is a mental shortcut that allows people to quickly make judgments and solve problems.

These mental shortcuts are typically informed by our past experiences and allow us to act quickly. However, heuristics are really more of a rule-of-thumb; they don't always guarantee a correct solution.

So how do you determine when to use a heuristic and when to use an algorithm? When problem-solving, deciding which method to use depends on the need for either accuracy or speed.

When to Use an Algorithm

If complete accuracy is required, it is best to use an algorithm. By using an algorithm, accuracy is increased and potential mistakes are minimized.

If you are working in a situation where you absolutely need the correct or best possible answer, your best bet is to use an algorithm. When you are solving problems for your math homework, you don't want to risk your grade on a guess.

By following an algorithm, you can ensure that you will arrive at the correct answer to each problem.

When to Use a Heuristic

On the other hand, if time is an issue, then it may be best to use a heuristic. Mistakes may occur, but this approach allows for speedy decisions when time is of the essence.

Heuristics are more commonly used in everyday situations, such as figuring out the best route to get from point A to point B. While you could use an algorithm to map out every possible route and determine which one would be the fastest, that would be a very time-consuming process. Instead, your best option would be to use a route that you know has worked well in the past.

Psychologists who study problem-solving have described two main processes people utilize to reach conclusions: algorithms and heuristics. Knowing which approach to use is important because these two methods can vary in terms of speed and accuracy.

While each situation is unique, you may want to use an algorithm when being accurate is the primary concern. But if time is of the essence, then an algorithm is likely not the best choice.

Lang JM, Ford JD, Fitzgerald MM. An algorithm for determining use of trauma-focused cognitive-behavioral therapy . Psychotherapy (Chic) . 2010;47(4):554-69. doi:10.1037/a0021184

Stein DJ, Shoptaw SJ, Vigo DV, et al. Psychiatric diagnosis and treatment in the 21st century: paradigm shifts versus incremental integration .  World Psychiatry . 2022;21(3):393-414. doi:10.1002/wps.20998

Bobadilla-Suarez S, Love BC. Fast or frugal, but not both: decision heuristics under time pressure . J Exp Psychol Learn Mem Cogn . 2018;44(1):24-33. doi:10.1037/xlm0000419

Giordano C, Brennan M, Mohamed B, Rashidi P, Modave F, Tighe P. Accessing artificial intelligence for clinical decision-making .  Front Digit Health . 2021;3:645232. doi:10.3389/fdgth.2021.645232

By Kendra Cherry, MSEd Kendra Cherry, MS, is a psychosocial rehabilitation specialist, psychology educator, and author of the "Everything Psychology Book."

Sphero makes remarkably cool, programmable robots and STEAM-based educational tools that transform the way kids learn, create and invent through coding, science, music, and the arts.

  • Lessons & Resources
  • Schedule a Virtual Demo
  • Professional Development
  • Standards Alignment
  • Funding & Grants
  • Case Studies & Whitepapers
  • App Downloads
  • Sphero BOLT
  • Sphero indi
  • Sphero RVR+
  • Sphero littleBits
  • Sphero Blueprint
  • Sphero Mini
  • Computer Science Foundations (Sphero BOLT)
  • Early Elementary
  • Upper Elementary
  • Middle School
  • Past Year's Challenges

Sphero logo

Enter your e-mail and password:

New customer? Create your account

Lost password? Recover password

Recover password

Enter your email:

Remembered your password? Back to login

Create my account

Please fill in the information below:

Already have an account? Login here

6 Examples of Algorithms In Everyday Life

Algorithms are all around us in the real world, like traffic lights, and how they work.

We teach our kids from a very early age how to do everyday tasks. We show them how to tie their shoes, walk up the stairs, snap their fingers, whistle, and even how to set the table using a step-by-step procedure. 

From following a recipe to driving a car, everything we do has a process to follow. As kids grow and face more complex problems to solve, they need a strong foundation in algorithmic design and computational thinking to accomplish their goals.

Algorithms and computational thinking are so important for young learners because they teach kids how to solve problems and develop step-by-step processes, both at school and outside the classroom. 

We asked two STEM education experts, Laurie Guyon and David Czechowski, how they best explain real-world algorithm examples to their students and compiled them here. 

What is an algorithm?

An algorithm is a set of rules or instructions used to solve complex problems. In many STEM fields, algorithms are used by computer programs to streamline processes. However, algorithms aren’t limited to STEM; they’re found everywhere.

Why Algorithms are Important in Early Education

Algorithms are in everything we do. They’re a crucial part of computational thinking and problem-solving in many areas of life, as we use algorithms to accurately and efficiently execute tasks. 

Laurie Guyon, Sphero Hero and Coordinator for Model Schools in New York, shared, “As a former sixth-grade English teacher, I used algorithmic design in essay writing to talk about sequencing, storyboarding, plot diagrams, and following steps to write a quality essay. We even called the editing process ‘debugging,’ because I found students were more likely to edit their papers if they saw the purpose of making sure their writing made sense to the reader. If we discussed their sentences as lines of code that a human had to read, they understood the importance of the editing process.”

The same can be said for just about anything we do. If you have ever watched a cooking show, the chef walks you through the step-by-step process of creating a delicious meal. Someone who investigates crime has a procedure to discern what happened in an incident and who could be at fault. Algorithms are in everything we do, so it’s important that young learners understand how to recognize and utilize them, Guyon adds.

6 Examples of Real-World Algorithms

Whether algorithms are used in places that aren’t at all surprising, like Google, or in a manual activity that is more unexpected, like brushing your teeth, algorithms play a role in the human experience every single day, Guyon goes on to explain.

1. Sorting Papers

A teacher sorting papers in alphabetical order is an example of a real-world algorithm.

Imagine a teacher sorting their students’ papers according to the alphabetical order of their first names. This type of task is similar to the function of a sorting algorithm, like a bucket sort . By looking at only the first letter of the first name, you can remove a lot of unnecessary information. This is an automated process that makes sorting more efficient.

2. Facial Recognition

Every day we see someone we know: a loved one, a coworker, or even an eccentric neighbor. When we recognize somebody’s face, we’re drawing upon data we’ve previously collected on the size and position of that person’s facial features. That information is then analyzed internally to automatically recognize others.

Facial recognition, both through people we know and through technology, is an example of a real-world algorithm.

Algorithms can automate this process for computers; however, facial recognition is not perfect. In the Netflix series “ Coded Bias ,” Joy Buolamwini, an activist and computer scientist based at MIT, discusses how algorithms used for facial recognition can be biased. This investigative series finds that facial recognition algorithms often do not recognize dark-skinned faces accurately, uncovering the need for additional work when creating algorithms based on human design.

3. Google Search

Even an action as seemingly simple as a Google search is only possible with the help of algorithms. Say, for example, you want to know if an elephant can swim. How you phrase the question to Google is the input you are asking the computer to determine. 

Google search is a good example of a real-world algorithm.

Google doesn’t even need all the words of the question “can an elephant swim?” For example, try searching for “swimming elephant” and see what you get. You will find that immediately, the output or the results show videos of elephants swimming, followed by more on the subject. Google uses an algorithm to generate these answers without needing the entirety of the question.

4. Duplicating Outcomes  

A teenage boy references a cookbook in the kitchen. Following a recipe is a good example of real-world algorithms in action.

David Czechowski, Computer Science and Technology Teacher at Hyde Park Central Schools , explains this example. “If we want to do well at a given task, it can be extremely helpful to look at previous successful examples from other people. A great daily example of this is using a recipe while cooking. Sure, you might be able to figure out how to make delicious pasta on your own through trial and error, but following a step-by-step recipe from a well-known chef helps ensure success.”

5. Traffic Lights

Czechowski adds, “Here’s an algorithm we frequently experience; the next time you're in your car stuck at a red light, consider the algorithm the traffic light is executing.”

Traffic lights are a great example of how algorithms are used in the real world, all around us.

Most traffic lights don’t automatically cycle through green, yellow, and red. Rather, there are sensory inputs that determine the signals’ timing based on the flow of traffic. The algorithm is a well-constructed, step-by-step order that directs the traffic appropriately (although it may not feel like it when you’re sitting at a red light). 

6. Bus Schedules

Every weekday morning, thousands of buses criss-cross neighborhoods picking up students. Mapping out efficient bus routes is an overwhelming manual task to execute without an algorithm to automate the calculations and schedule the right students for the right addresses at the right time. This routing issue is classically referred to as “ The Traveling Salesman Problem " and is even used as an exercise for theoretical computer science, according to Czechowski.

A woman waits for a bus. The schedule busses follow to make on-time arrivals and departures is an example of a real-world algorithm.

Algorithms are all around us, so close and common that we don’t even recognize them as algorithms. From cooking to looking up directions to something simple like tying your shoes, finding algorithms in your day-to-day life may not be as hard as you think.

How Administrators Can Build Confidence with Algorithms

Algorithmic thinking should be a crucial facet in modern education programs, but many schools overlook this topic or are unsure how to approach it. Administrators can take steps to ensure that algorithmic thinking and design are present in their schools.

Administrator’s Corner: Algorithmic thinking can also improve the onboarding or upskilling of teachers. 

When designing professional learning opportunities for current or future teachers, I like to follow an outline or an algorithmic process. I start with a question or activity to get participants engaged, build community, and think about the topic. From there, I like to do something to get them excited about the subject. We dive into the meat of the matter, with lots of time for questions and reflection. This algorithm allows participants to be actively engaged in the learning process and keeps a natural flow for success.

Show Real-World Examples of Algorithms with Sphero

Algorithm design doesn’t have to be complex or daunting. It already plays an important role in our daily lives, even in the simplest tasks we do like Googling questions or organizing papers. Algorithmic thinking is an integral part of computational thinking and is now a necessary life skill.

Young learners can develop algorithmic thinking and design skills both in and out of the classroom with the help of Sphero’s programmable robots and STEM kits .

example of algorithm problem solving

Written by:

Sphero Team

Keep your inbox inspired. Sign up for product updates, exclusive offers, and teacher resources.

Popular posts

Sphero Heroes posing for picture together.

Featured products

Sphero BOLT Power Pack + Sphero City and Golf Code Mat.

enjoyalgorithms

EnjoyMathematics

Problem-Solving Approaches in Data Structures and Algorithms

This blog highlights some popular problem-solving strategies for solving problems in DSA. Learning to apply these strategies could be one of the best milestones for the learners in mastering data structure and algorithms.

Top 10 problem solving techniques in data structures and algorithms

An Incremental approach using Single and Nested loops

One of the simple ideas of our daily problem-solving activities is that we build the partial solution step by step using a loop. There is a different variation to it:

  • Input-centric strategy: At each iteration step, we process one input and build the partial solution.
  • Output-centric strategy: At each iteration step, we add one output to the solution and build the partial solution.
  • Iterative improvement strategy: Here, we start with some easily available approximations of a solution and continuously improve upon it to reach the final solution.

Here are some approaches based on loop: Using a single loop and variables, Using nested loops and variables, Incrementing the loop by a constant (more than 1), Using the loop twice (Double traversal), Using a single loop and prefix array (or extra memory), etc.

Example problems:   Insertion Sort ,  Finding max and min in an array ,  Valid mountain array ,  Find equilibrium index of an array ,  Dutch national flag problem ,  Sort an array in a waveform .

Decrease and Conquer Approach

This strategy is based on finding the solution to a given problem via its one sub-problem solution. Such an approach leads naturally to a recursive algorithm, which reduces the problem to a sequence of smaller input sizes. Until it becomes small enough to be solved, i.e., it reaches the recursion’s base case.

Example problems:   Euclid algorithm of finding GCD ,  Binary Search ,  Josephus problem

Problem-solving using Binary Search

When an array has some order property similar to the sorted array, we can use the binary search idea to solve several searching problems efficiently in O(logn) time complexity. For doing this, we need to modify the standard binary search algorithm based on the conditions given in the problem. The core idea is simple: calculate the mid-index and iterate over the left or right half of the array.

Problem-solving using binary search visualization

Example problems: Find Peak Element , Search a sorted 2D matrix , Find the square root of an integer , Search in Rotated Sorted Array

Divide and Conquer Approach

This strategy is about dividing a problem into  more than one subproblems,  solving each of them, and then, if necessary, combining their solutions to get a solution to the original problem. We solve many fundamental problems efficiently in computer science by using this strategy.

Divide and conquer approach visualization

Example problems:   Merge Sort ,  Quick Sort ,  Median of two sorted arrays

Two Pointers Approach

The two-pointer approach helps us optimize time and space complexity in the case of many searching problems on arrays and linked lists. Here pointers can be pairs of array indices or pointer references to an object. This approach aims to simultaneously iterate over two different input parts to perform fewer operations. There are three variations of this approach:

Pointers are moving in the same direction with the same pace:   Merging two sorted arrays or linked lists, Finding the intersection of two arrays or linked lists , Checking an array is a subset of another array , etc.

Pointers are moving in the same direction at a different pace (Fast and slow pointers):   Partition process in the quick sort , Remove duplicates from the sorted array , Find the middle node in a linked list , Detect loop in a linked list , Move all zeroes to the end , Remove nth node from list end , etc.

Pointers are moving in the opposite direction:  Reversing an array, Check pair sum in an array , Finding triplet with zero-sum , Rainwater trapping problem , Container with most water , etc.

Two pointers approach visualization

Sliding Window Approach

A sliding window concept is commonly used in solving array/string problems. Here, the window is a contiguous sequence of elements defined by the start and ends indices. We perform some operations on elements within the window and “slide” it in a forward direction by incrementing the left or right end.

This approach can be effective whenever the problem consists of tasks that must be performed on a contiguous block of a fixed or variable size. This could help us improve time complexity in so many problems by converting the nested loop solution into a single loop solution.

Example problems: Longest substring without repeating characters , Count distinct elements in every window , Max continuous series of 1s , Find max consecutive 1's in an array , etc.

Transform and Conquer Approach

This approach is based on transforming a coding problem into another coding problem with some particular property that makes the problem easier to solve. In other words, here we solve the problem is solved in two stages:

  • Transformation stage: We transform the original problem into another easier problem to solve.
  • Conquering stage: Now, we solve the transformed problem.

Example problems: Pre-sorting based algorithms (Finding the closest pair of points, checking whether all the elements in a given array are distinct, etc.)

Problem-solving using BFS and DFS Traversal

Most tree and graph problems can be solved using DFS and BFS traversal. If the problem is to search for something closer to the root (or source node), we can prefer BFS, and if we need to search for something in-depth, we can choose DFS.

Sometimes, we can use both BFS and DFS traversals when node order is not required. But in some cases, such things are not possible. We need to identify the use case of both traversals to solve the problems efficiently. For example, in binary tree problems:

  • We use preorder traversal in a situation when we need to explore all the tree nodes before inspecting any leaves.
  • Inorder traversal of BST generates the node's data in increasing order. So we can use inorder to solve several BST problems.
  • We can use postorder traversal when we need to explore all the leaf nodes before inspecting any internal nodes.
  • Sometimes, we need some specific information about some level. In this situation, BFS traversal helps us to find the output easily.

BFS and DFS traversal visualization

To solve tree and graph problems, sometimes we pass extra variables or pointers to the function parameters, use helper functions, use parent pointers, store some additional data inside the node, and use data structures like the stack, queue, and priority queue, etc.

Example problems: Find min depth of a binary tree , Merge two binary trees , Find the height of a binary tree , Find the absolute minimum difference in a BST , The kth largest element in a BST , Course scheduling problem , bipartite graph , Find the left view of a binary tree , etc.

Problem-solving using the Data Structures

The data structure is one of the powerful tools of problem-solving in algorithms. It helps us perform some of the critical operations efficiently and improves the time complexity of the solution. Here are some of the key insights:

  • Many coding problems require an effcient way to perform the search, insert and delete operations. We can perform all these operations using the hash table in O(1) time average. It's a kind of time-memory tradeoff, where we use extra space to store elements in the hash table to improve performance.
  • Sometimes we need to store data in the stack (LIFO order) or queue (FIFO order) to solve several coding problems. 
  • Suppose there is a requirement to continuously insert or remove maximum or minimum element (Or element with min or max priority). In that case, we can use a heap (or priority queue) to solve the problem efficiently.
  • Sometimes, we store data in Trie, AVL Tree, Segment Tree, etc., to perform some critical operations efficiently. 

Various types of data structures in programming

Example problems: Next greater element , Valid Parentheses , Largest rectangle in a histogram , Sliding window maximum , kth smallest element in an array , Top k frequent elements , Longest common prefix , Range sum query , Longest consecutive sequence , Check equal array , LFU cache , LRU cache , Counting sort

Dynamic Programming

Dynamic programming is one of the most popular techniques for solving problems with overlapping or repeated subproblems. Here rather than solving overlapping subproblems repeatedly, we solve each smaller subproblems only once and store the results in memory. We can solve a lot of optimization and counting problems using the idea of dynamic programming.

Dynamic programming idea

Example problems: Finding nth Fibonacci,  Longest Common Subsequence ,  Climbing Stairs Problem ,  Maximum Subarray Sum ,  Minimum number of Jumps to reach End ,  Minimum Coin Change

Greedy Approach

This solves an optimization problem by expanding a partially constructed solution until a complete solution is reached. We take a greedy choice at each step and add it to the partially constructed solution. This idea produces the optimal global solution without violating the problem’s constraints.

  • The greedy choice is the best alternative available at each step is made in the hope that a sequence of locally optimal choices will yield a (globally) optimal solution to the entire problem.
  • This approach works in some cases but fails in others. Usually, it is not difficult to design a greedy algorithm itself, but a more difficult task is to prove that it produces an optimal solution.

Example problems: Fractional Knapsack, Dijkstra algorithm, The activity selection problem

Exhaustive Search

This strategy explores all possibilities of solutions until a solution to the problem is found. Therefore, problems are rarely offered to a person to solve the problem using this strategy.

The most important limitation of exhaustive search is its inefficiency. As a rule, the number of solution candidates that need to be processed grows at least exponentially with the problem size, making the approach inappropriate not only for a human but often for a computer as well.

But in some situations, there is a need to explore all possible solution spaces in a coding problem. For example: Find all permutations of a string , Print all subsets , etc.

Backtracking

Backtracking is an improvement over the approach of exhaustive search. It is a method for generating a solution by avoiding unnecessary possibilities of the solutions! The main idea is to build a solution one piece at a time and evaluate each partial solution as follows:

  • If a partial solution can be developed further without violating the problem’s constraints, it is done by taking the first remaining valid option at the next stage. ( Think! )
  • Suppose there is no valid option at the next stage, i.e., If there is a violation of the problem constraint, the algorithm backtracks to replace the partial solution’s previous stage with the following option for that stage. ( Think! )

Backtracking solution of 4-queen problem

In simple words, backtracking involves undoing several wrong choices — the smaller this number, the faster the algorithm finds a solution. In the worst-case scenario, a backtracking algorithm may end up generating all the solutions as an exhaustive search, but this rarely happens!

Example problems: N-queen problem , Find all k combinations , Combination sum , Sudoku solver , etc.

Problem-solving using Bit manipulation and Numbers theory

Some of the coding problems are, by default, mathematical, but sometimes we need to identify the hidden mathematical properties inside the problem. So the idea of number theory and bit manipulation is helpful in so many cases.

Sometimes understanding the bit pattern of the input and processing data at the bit level help us design an efficient solution. The best part is that the computer performs each bit-wise operation in constant time. Even sometimes, bit manipulation can reduce the requirement of extra loops and improve the performance by a considerable margin.

Example problems: Reverse bits , Add binary string , Check the power of two , Find the missing number , etc.

Hope you enjoyed the blog. Later we will write a separate blog on each problem-solving approach. Enjoy learning, Enjoy algorithms!

Share Your Insights

Don’t fill this out if you’re human:

More from EnjoyAlgorithms

Self-paced courses and blogs, coding interview, machine learning, system design, oop concepts, our newsletter.

Subscribe to get well designed content on data structure and algorithms, machine learning, system design, object orientd programming and math.

©2023 Code Algorithms Pvt. Ltd.

All rights reserved.

Codementor

  • Find Mentors
  • Web Programming Web Programming AngularJS ASP.NET Django Express HTML/CSS jQuery Laravel Node.js Rails React Redux Vue.js
  • Mobile App Programming Mobile App Programming Android iOS Ionic Kotlin React Native Swift Xcode Cordova Titanium
  • Programming Language Programming Language C C++ C# Go Java JavaScript PHP Python R Ruby TypeScript
  • Data Science/Engineering Data Science/Engineering AI Machine Learning Matlab Tableau Tensorflow
  • Database/Operations Database/Operations AWS Database Docker GCP Heroku Linux MongoDB MySQL Postgres SQL
  • Others Others Arduino Bash Electron Firebase Game Programming Git Rasberry Pi Selenium WebDriver Stripe Unity 3D Visual Studio Wordpress
  • Programming Tutors Programming Tutors Java C# Python Computer Science
  • Find Freelancers
  • How it Works
  • BECOME A MENTOR

3 Essential Algorithm Examples You Should Know

algorithm examples

There are certain algorithms that come up again and again. In this tutorial, we will explore three of the most common: searching, sorting, and adding to/removing from a linked list. The ideas surrounding these algorithm examples permeate throughout many other algorithms . Understanding these three examples, will help us build a solid foundation so we can tackle future algorithm problems with confidence!

Algorithm Examples, #1: Binary Search

Binary search is an essential search algorithm that takes in a sorted array and returns the index of the value we are searching for. We do this with the following steps:

  • Find the midpoint of the sorted array.
  • Compare the midpoint to the value of interest.
  • If the midpoint is larger than the value, perform binary search on right half of the array.
  • If the midpoint is smaller than the value, perform binary search on left half of the array.
  • Repeat these steps until the midpoint value is equal to the value of interest or we know the value is not in the array.

From the steps above, it is clear that our solution can be recursive. We will pass in a smaller array to our method on each iteration until our array only contains the value we are interested in. The tricky parts are indexing our array properly and keeping track of our index offset on each iteration so that we can return the index of our value from the original array. See below for our version of the binary search algorithm.

Binary search has a time complexity of O(logn) . We know this because if we double the size of our input array, we only need one more iteration of our algorithm to arrive at our final answer. This is why binary search is such a significant algorithm in computer science.

Algorithm Examples, #2: Merge Sort

Merge sort,uses a similar “divide and conquer” methodology to efficiently sort arrays. See the following steps for how merge sort is implemented.

  • Return if array is only one element long, because it is already sorted.
  • Divide array into two halves until it cannot be divided anymore.

algorithm examples

  • Merge smaller arrays in sorted order until we have our original sorted array.

To implement merge sort, we will define two methods. One will take care of the splitting up of the array and the other will take care of merging two unsorted arrays back into a single sorted array. We call the dividing-up-method ( merge_sort ) recursively until our array is only one element long. We then merge them back together and finally return our sorted array. See below:

Merge Sort has a time complexity of O(nlogn) , which is the best possible time complexity for a sorting algorithm. By dividing and conquering, we dramatically improve the efficiency of sorting, which is already a computationally expensive process.

Algorithm Examples, #3: Adding and Removing From a Linked List

The linked list is a fundamental computer science data structure, that is most useful for it’s constant time insertion and deletion. By using nodes and pointers, we can perform some processes much more efficiently than if we were to use an array. See below for a schematic:

algorithm examples

With a linked list, we can delete items from the middle of a collection without having to shift over the rest of the data structure in memory, like we would have to if we were using an array. By choosing the best data structure for our needs, we can reach optimal efficiency!

What’s Next?

These three algorithm examples are just the surface of fundamental algorithms we should know to both create efficient programs and succeed at technical interviews . Here are some more algorithms we can explore on our own to further our knowledge.

  • Traverse a binary search tree
  • Minimum spanning tree
  • Reverse a string in place

These are difficult concepts to grasp, so we just have to keep practicing and understand more algorithm examples!

Other tutorials you might be interested to read:

  • Introduction to Greedy Algorithms
  • Two Algorithms for Solving Vigenere Cipher in Ruby
  • Implementing Google’s Two-Step Authentication to Your App
  • 6 Ruby Best Practices Beginners Should Know

Author’s Bio

algorithm examples

Sign Up and Get Help Now

' height=

Please accept our cookies! 🍪

Codementor and its third-party tools use cookies to gather statistics and offer you personalized content and experience. Read about how we use cookies and how to withdraw your consent in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.

Please accept our cookies! Read Cookie Policy 🍪

How to Solve an Algorithm Problem? | With Examples

developer team coding javascript

If you’re stuck on an algorithm problem and not sure how to proceed, this blog post is for you! We’ll go over some general tips on solving algorithm problems, as well as a specific example of an algorithm .

Table of content:

Introduction.

  • What are the 4 steps of algorithmic problem solving?
  • Conclusion and References

[365 Toy Project: 022/365] Batman: Scarlet Part 4 - Solve the problem - Solve an Algorithm.

What is an Algorithm?

What is an algorithm? Put simply, an algorithm is a step-by-step procedure for solving a problem. Algorithms can be written in any programming language, but they all share some common characteristics. First and foremost, algorithms are sequence tasks . That means that the steps in the algorithm must be done in order, and each step depends on the results of the previous steps. Secondly, algorithms are deterministic: given the same input data, exactly the same program will produce the same output every time. Finally, there are some measures for an algorithm to be efficient. Time and space: those two measures determine how efficient your algorithm is.

Computer geometric digital connection structure. Business inteligence technology background. Wirefra

How to Solve an Algorithm Problem?

We’ll walk through some steps for solving a particular algorithm .

First, it’s important to know the basics of algorithms: every problem can be broken down into a sequence of steps that can be solved. This is known as the analysis of algorithms . Sketch out the basic structure of your algorithm on paper first or a board to avoid confusion. write some thoughts about which does what.

If a problem involves mathematical operations, conceptualizing it in terms of equations may be helpful. Break down the equation into its component parts and see if any of those particular pieces can be simplified or eliminated altogether. If so, that will lead to a solution for the whole equation.

Another strategy is to try reversing what initially seems like an impossible task. Algorithms problems often have stages were doing something one-way results in an error message or produces no useful output at all. Reverse engineer those steps and see if anything productive comes out.

What are the 4 steps of algorithmic problem-solving? and Example #1

Now that you know what an algorithm is, let’s jump into some examples and take a look at how these techniques can be put into practice…

In the following we will use the problem challenge from leetcode number #387 :

1) Understand the problem

The goal of any algorithm is to solve a problem.  When solving an algorithm problem, it is important to understand the problem and the steps involved in solving it. This understanding will allow you to correctly follow the instructions and complete the task. Answer the common questions to be sure that you really understand the problem. Questions like what it does and what kind of input I’m expecting. what kind of output I should receive? Are there some exceptions I should be aware of? etc…

The goal of this challenge is to write a function that takes in a string and returns the index of the first letter in the string that does not repeat. For example, if the string is “nerd”, the function should return 0, because the first letter “n” is the first non-repeating letter in the string. If the string is “abcdefg”, the function should return 0, because the first letter “a” is the first non-repeating letter in the string.

If the string does not contain any non-repeating letters, the function should return -1. For example, if the input string is “abcabc”, the function should return -1, because no letter in the string is unique or non-repeating.

2) Break the problem down

When solving algorithms problems , breaking them down into smaller parts is usually the best way to go. Once you understand how each part works and interacts with the others, you can solve the problem more quickly.

To solve this challenge, we need to do the following:

  • Iterate over the letters in the input string, and for each letter, keep track of how many times it appears in the string. We can do this using an object, dictionary, or map, where the keys are the letters in the string, and the values are the counts for each letter.
  • Once we have counted the occurrences of each letter in the string, we need to find the index of the first letter that has a count of 1 (i.e. the first non-repeating letter). To do this, we can iterate over the letters in the string again, and for each letter, check if its count in the object/dictionary is 1. If it is, we return the index of the letter.
  • If we reach the end of the loop without finding any value that has only 1 or non-repeating letters, we return -1 to indicate that no non-repeating letters were found.

3) Find your solution

We found one solution and the key steps in this solution are to keep track of the counts of each letter in the input string, and then to search for the first letter with a count of 1.  If the count of this letter is 1 meaning that this letter only shows one time in the string. These steps can be implemented in a variety of ways, depending on the language and tools you are using to solve the challenge.

We will be demonstrating the solution with two programming languages JavaScript and Python:

The source code in JavaScript:

Here are some examples of how this function can be used:

The source code in Python :

4) Check your solution

Checking your solution again answers some questions like can I write a better code? by better I mean is the code I provided covering all cases of inputs? is it efficient? and by efficient, I mean using fewer computer resources when possible. If you’re comfortable with your answers then check if there is another solution out there for the same problem you solved, if any are found. go through them I learned a lot by doing that. Also get some feedback on your code, that way you’ll learn many ways of approaching a problem to solve it.

As we mentioned above we asked ourselves these questions but the algorithm we wrote couldn’t go through all the different cases successfully: for example, The code can’t handle the case when we handled two cases of the same character “L” and “l” in the word “Level”

So we need to address that in the following:

Now let’s revisit the code that we wrote up and see if we can come up with another solution that will cover the all different cases of a character.

The source code in JavaScript :

Now that you learned from the first example, let’s jump into another challenge and apply the same techniques we used above:

This example from leetcode problem #125 Valid Palindrome

Learn as much information as you can about the problem what is a Palindrome? Ask yourself what input you expect and what output is expected.

The Palindrome is a word, phrase, or sentence that is spelled backward as forwards. We expect a string and we can do a function that first cleans that string from any non-alphanumeric, then reverses it and compares it with the original string.

Here is a step-by-step explanation of the algorithm in plain English:

  • Convert all uppercase letters in the string to lowercase. This is done so that the case of the letters in the string does not affect the outcome of the comparison.
  • Remove all non-alphanumeric characters from the string. This is done because only alphanumeric characters are relevant for determining if a string is a palindrome.
  • Reverse the resulting string. This is done so that we can compare the reversed string with the original string.
  • Compare the reversed string with the original string. If they are the same, then the original string is a palindrome. Otherwise, it is not.

Here is an example of how this algorithm would work on the string “A man, a plan, a canal: Panama”:

  • The string is converted to lowercase, so it becomes “a man, a plan, a canal: panama”.
  • All non-alphanumeric characters are removed, so the string becomes “amanaplanacanalpanama”.
  • The string is reversed, so it becomes “amanaplanacanalpanama”.
  • The reversed string is compared with the original string, and since they are the same, the function returns true, indicating that the original string is a palindrome.

According to the steps we wrote in the previous stage, let’s put them into action and code it up.

The source code in Python:

We can make it more efficient by using the pointers method let’s break it down into a few points below:

  • Create left and right pointers (will be represented by indices)
  • Make each pointer move to the middle direction
  • While moving to check each letter for both pointers are the same

Quantum computer technology concept. Deep learning artificial intelligence. Big data algorithms visu

Conclusion and references

There are many resources available to help you out, and with more practice , you’ll be able to solve many algorithm problems that come your way . This video is one of the great resources to learn about algorithms and data structures from FreeCodeCamp

It is important to keep a cool head and not get bogged down in frustration. Algorithms problems can be difficult, but with patience and perseverance, they can be solved.

When you are solving an algorithm problem, it is important to be able to check your solution against other solutions if possible to see how others approach the same problem. This is will help you to retain and understand the logic behind the different solutions so you’ll need this kind of knowledge in the future solving problems.

By following the steps outlined in this article, you will be able to solve algorithm problems with ease. Remember to keep a notebook or excel sheet with all of your solutions so that you can revisit them later on that way you will gain maximum retention of the logic.

If you want to learn more about algorithms and programming , sign up for our mailing list. We’ll send you tips, tricks, and resources to help you improve your skills.

example of algorithm problem solving

Ahmed Radwan

Reach out if you want to join me and write articles with the nerds 🙂

How to Make Your Corporate Website Stand Out With These 10 Tips

How to write clean code and best practices, you may also like, top 100 problems on leetcode and its solutions – part1, learn essential javascript methods and objects, react: what is the one-way data flow and jsx rules.

  • Smart Devices
  • Programming
  • Web Development
  • Presentation
  • Infographics

My Coding Place logo

MY CODING PLACE

STEM skills from Austin, TX

[email protected]

512-593-2729

  • Jun 18, 2021

Problem-Solving With Algorithms

example of algorithm problem solving

Algorithms are used by both computers and humans to make interconnected decisions throughout our world. Google's search algorithm sorts through billions of webpages, presenting desired information to you in milliseconds. GPS systems manage massive systems of transport, ride sharing, and shipping. Algorithmic trading executes high-speed decisions to determine optimal investments faster than any human. While these algorithms may sound intimidating, all algorithms are essentially detailed sets of instructions that computers follow to arrive at an answer . Humans also constantly utilize (simpler) algorithms: for example, a recipe to make dinner is an algorithm.

For kids, understanding the process of building an algorithm helps them build a strong foundation in logical thinking and problem solving. Algorithmic thinking in kids develops the cross-disciplinary skills to generate creative, original solutions to a wide array of problems in STEM and beyond. In this article, we'll walk through an example of an algorithm and real-world uses of algorithms across multiple fields.

Historical origins of algorithms

The term algorithm comes from 9th century Persian mathematician and geographer Muhammad ibn Musa al-Khwarizmi. The term algorithm was derived from the Latinization of his name to "Algoirtmi" when his book On the Calculations with Hindu Numerals was spread into Europe and translated into Latin as Algoritmi de numero Indorum . This book was critical to the development and utilization of the decimal system we use today. Al-Khwarizmi developed a systematic approach to solving linear and quadratic equations , which was then termed algebra. This algorithmic approach established the basis for modern mathematics.

In 1936, Alan Turing defined a foundational concept for computer scientists in his paper on the Turing machine. He illustrated that problems could be broken down and solved by machines executing algorithms to perform operations .

What is an algorithm?

An algorithm is a detailed, step-by-step process followed in order to accomplish a specific task or to solve a specific problem .

Computer algorithms can appear complex, but the underlying concept is approachable for both adults and kids. We can define an algorithm by writing out the step-by-step instructions, thinking about things in terms of discrete steps. For example, our algorithm for a child's morning routine could be the following:

Wake up and turn off alarm

Get dressed

Brush teeth

Eat breakfast

Go to school

How do algorithms shape our world?

Google's PageRank algorithm determines how pages on the internet are displayed and ranked based on their relevance to your search. In less than a second, interrelated search algorithms process information extremely quickly, interpreting your query and returning personalized results.

Sites such as Amazon and Netflix base recommendations on collaborative filtering algorithms that look at other uses with similar interests and tastes and subsequently deliver predictions for purchases and shows.

Sorting information into logical order for better presentation and easier analysis is a fundamental consideration for interfaces and databases. Thus, efficient sorting of data is a very common algorithmic challenge. For a visual explanation of various sorting algorithms, this video presents 15 Sorting Algorithms in 6 Minutes , including merge sort and quick sort.

Mapping applications such as Google Maps need to calculate routes through cities, taking into account distance, traffic, and accidents. Tools such as Google Flights consider also routes through many airports while considering layovers, prices, and time. Next, we'll look at Dijkstra's algorithm , an algorithm that helps us find these optimal paths.

Shortest Path: Dijkstra's Algorithm

Consider the process of flying from New York City to San Francisco. There are a large number of different routes to get there: some are direct flights, but some have multiple stops. If we want to calculate the shortest way to get from New York City to San Francisco, we can look at a map with each city represented as a dot with routes between them. We could attach cost, distance, and time to each of these routes. That way, we could more easily weigh our options.

For example, we could fly from New York to Atlanta, and then from Atlanta to San Francisco, which would likely increase the cost, distance, and time required. If we want to figure out what the optimal path is for our specifications, we can create a graph that represents all of these interconnected cities. These cities are represented by nodes , and their connections ( edges ) are labeled with weights that represent the cost, distance, and time data we want to consider. These nodes and edges are represented by a graph .

How do we use this weighted graph that represents the 1,200 international airports and the flights between them? Dijkstra's algorithm is a famous pathfinding algorithm that determines the shortest path between weighted nodes in a graph. Dijkstra first came up with the algorithm as a "twenty-minute invention" in 1956 while considering what the shortest way to travel from Rotterdam to Groningen was. The algorithm is approachable and makes sense even without the context of computer programming.

Let's go back to our previous example and say that all the direct flights are sold out, so now we have to find a route with multiple stops, and we are purely optimizing for price. Beginning from New York City, we examine the nodes (airports) that are connected - let's say the options are flying to Atlanta ($150) and Denver ($300). We mark each node with the cumulative price so far. Then, let's say from Atlanta, we can fly to Denver ($100) or San Francisco ($200). Now, Denver is labeled as $250 ($150 + $100) and San Francisco is labeled as $350 ($150 + 200). Finally, let's say we can fly from Denver to San Francisco for $150. This is not optimal, as we already have an option that will get us to San Francisco for $350. So, we have found that the cheapest route is New York City -> Atlanta -> San Francisco.

In reality, there would be many more route options to consider, but the process the algorithm follows remains the same. The idea is to start at the origin and follow each possible route and update the price at each city to the cheapest way we can get there, repeating until we've considered all the possible routes to get to the destination. We've purposely left out some details, but this is the big picture. In more formal terms, we might describe the algorithm this way:

example of algorithm problem solving

To go from point A to point B, the algorithm begins from point A, then looks for the unvisited node with the lowest weight. From that node, it looks at all of the connecting nodes and considers those weights. If this makes routes cost less than before, then the distance to that node is updated. For example, if the previous weight from A to C was 10, but the distance from A to B is 3 and the distance from B to C is 4, then we can update the new cost of going from A to C as a total of 7. From there, the algorithm repeats the steps of traversing the lowest possible distance to the next unvisited node until the final point is reached, and the lowest total cost is determined.

Because the essential steps are not overly complicated, much of the work of repeated calculation and consideration is shifted to the computer. That is the value of an algorithm, and why they are so useful in computer programming to break down tasks into chunks that can be solved through specific implementations.

Why are algorithms important for kids to learn?

Even if we're not conscious of it, we use algorithms all the time. Learning how to create algorithms not only lays a strong foundation in programming skills, but is also useful for developing logical thinking skills beyond writing computer code. Being able to understand and implement an algorithm in code requires students to practice their structured thinking and reasoning abilities.

Here are some problems you can ask your child to discuss algorithmic solutions with you:

How do we know if a number is odd or even?

How do we calculate all of the factors of a number (i.e. the numbers that divide into it without remainder)?

How can we tell if a number is prime?

Given a list of 10 numbers in random order, how can we put them order?

How can kids learn to program an algorithm?

In all of our online courses, students develop algorithmic thinking for solving problems. Through our private classes, our instructors are there to actively guide the student through learning new concepts, building their own projects, and solving problems in their code.

Throughout our courses, students are asked to consider problems like:

In order for the player to win the game, what conditions have to be met?

How can we keep track of the score in our game?

How can we count the number of times each letter appears in a word?

What are the steps we have to take to swap the smallest and largest numbers in a list of numbers?

In summary, the process of solving problems requires algorithmic thinking, or the process of breaking a problem down into repeatable steps. We encourage students to do this in all of our classes. Then, students learn to translate the logic into code. Coding is a tool to solve problems, but the end goal is for students to gain an understanding of approaches to problem-solving and to gain critical thinking skills that will benefit them in any activity.

This article originally appeared on junilearning.com

  • STEM education
  • Cognitive Development
  • Learn To Code

Recent Posts

What Is An Algorithm and Why Are They Important

Getuplearn – Communication, Marketing, HRM, Tutorial

What is Problem Solving Algorithm?, Steps, Representation

Table of Contents

  • 1 What is Problem Solving Algorithm?
  • 2 Definition of Problem Solving Algorithm
  • 3.1 Analysing the Problem
  • 3.2 Developing an Algorithm
  • 3.4 Testing and Debugging
  • 4.1 Flowchart
  • 4.2 Pseudo code

What is Problem Solving Algorithm?

Computers are used for solving various day-to-day problems and thus problem solving is an essential skill that a computer science student should know. It is pertinent to mention that computers themselves cannot solve a problem. Precise step-by-step instructions should be given by us to solve the problem.

Problem Solving Algorithm

Thus, the success of a computer in solving a problem depends on how correctly and precisely we define the problem, design a solution (algorithm) and implement the solution (program) using a programming language.

Thus, problem solving is the process of identifying a problem, developing an algorithm for the identified problem and finally implementing the algorithm to develop a computer program.

Definition of Problem Solving Algorithm

These are some simple definition of problem solving algorithm which given below:

Steps for Problem Solving

When problems are straightforward and easy, we can easily find the solution. But a complex problem requires a methodical approach to find the right solution. In other words, we have to apply problem solving techniques.

Problem solving begins with the precise identification of the problem and ends with a complete working solution in terms of a program or software. Key steps required for solving a problem using a computer.

For Example: Suppose while driving, a vehicle starts making a strange noise. We might not know how to solve the problem right away. First, we need to identify from where the noise is coming? In case the problem cannot be solved by us, then we need to take the vehicle to a mechanic.

The mechanic will analyse the problem to identify the source of the noise, make a plan about the work to be done and finally repair the vehicle in order to remove the noise. From the example, it is explicit that, finding the solution to a problem might consist of multiple steps.

Following are Steps for Problem Solving :

Analysing the Problem

Developing an algorithm, testing and debugging.

Steps for Problem Solving

It is important to clearly understand a problem before we begin to find the solution for it. If we are not clear as to what is to be solved, we may end up developing a program which may not solve our purpose.

Thus, we need to read and analyse the problem statement carefully in order to list the principal components of the problem and decide the core functionalities that our solution should have. By analysing a problem, we would be able to figure out what are the inputs that our program should accept and the outputs that it should produce.

It is essential to device a solution before writing a program code for a given problem. The solution is represented in natural language and is called an algorithm. We can imagine an algorithm like a very well-written recipe for a dish, with clearly defined steps that, if followed, one will end up preparing the dish.

We start with a tentative solution plan and keep on refining the algorithm until the algorithm is able to capture all the aspects of the desired solution. For a given problem, more than one algorithm is possible and we have to select the most suitable solution.

After finalising the algorithm, we need to convert the algorithm into the format which can be understood by the computer to generate the desired solution. Different high level programming languages can be used for writing a program. It is equally important to record the details of the coding procedures followed and document the solution. This is helpful when revisiting the programs at a later stage.

The program created should be tested on various parameters. The program should meet the requirements of the user. It must respond within the expected time. It should generate correct output for all possible inputs. In the presence of syntactical errors, no output will be obtained. In case the output generated is incorrect, then the program should be checked for logical errors, if any.

Software industry follows standardised testing methods like unit or component testing, integration testing, system testing, and acceptance testing while developing complex applications. This is to ensure that the software meets all the business and technical requirements and works as expected.

The errors or defects found in the testing phases are debugged or rectified and the program is again tested. This continues till all the errors are removed from the program. Once the software application has been developed, tested and delivered to the user, still problems in terms of functioning can come up and need to be resolved from time to time.

The maintenance of the solution, thus, involves fixing the problems faced by the user, answering the queries of the user and even serving the request for addition or modification of features.

Representation of Algorithms

Using their algorithmic thinking skills, the software designers or programmers analyse the problem and identify the logical steps that need to be followed to reach a solution. Once the steps are identified, the need is to write down these steps along with the required input and desired output.

There are two common methods of representing an algorithm —flowchart and pseudocode. Either of the methods can be used to represent an algorithm while keeping in mind the following:

  • It showcases the logic of the problem solution, excluding any implementational details.
  • It clearly reveals the flow of control during execution of the program.

A flowchart is a visual representation of an algorithm . A flowchart is a diagram made up of boxes, diamonds and other shapes, connected by arrows. Each shape represents a step of the solution process and the arrow represents the order or link among the steps.

A flow chart is a step by step diagrammatic representation of the logic paths to solve a given problem. Or A flowchart is visual or graphical representation of an algorithm .

The flowcharts are pictorial representation of the methods to b used to solve a given problem and help a great deal to analyze the problem and plan its solution in a systematic and orderly manner. A flowchart when translated in to a proper computer language, results in a complete program.

Advantages of Flowcharts:

  • The flowchart shows the logic of a problem displayed in pictorial fashion which felicitates easier checking of an algorithm
  • The Flowchart is good means of communication to other users. It is also a compact means of recording an algorithm solution to a problem.
  • The flowchart allows the problem solver to break the problem into parts. These parts can be connected to make master chart.
  • The flowchart is a permanent record of the solution which can be consulted at a later time.

Differences between Algorithm and Flowchart

Pseudo code.

The Pseudo code is neither an algorithm nor a program. It is an abstract form of a program. It consists of English like statements which perform the specific operations. It is defined for an algorithm. It does not use any graphical representation.

In pseudo code , the program is represented in terms of words and phrases, but the syntax of program is not strictly followed.

Advantages of Pseudocode

  • Before writing codes in a high level language, a pseudocode of a program helps in representing the basic functionality of the intended program.
  • By writing the code first in a human readable language, the programmer safeguards against leaving out any important step. Besides, for non-programmers, actual programs are difficult to read and understand.
  • But pseudocode helps them to review the steps to confirm that the proposed implementation is going to achieve the desire output.

Related posts:

  • 10 Types of Computers | History of Computers, Advantages
  • What is Microprocessor? Evolution of Microprocessor, Types, Features
  • Types of Computer Memory, Characteristics, Primary Memory, Secondary Memory
  • Data and Information: Definition, Characteristics, Types, Channels, Approaches
  • What is Cloud Computing? Classification, Characteristics, Principles, Types of Cloud Providers
  • What is Debugging? Types of Errors
  • Types of Storage Devices, Advantages, Examples
  • 10 Evolution of Computing Machine, History
  • What are Functions of Operating System? 6 Functions
  • Advantages and Disadvantages of Operating System
  • Data Representation in Computer: Number Systems, Characters, Audio, Image and Video
  • What are Data Types in C++? Types
  • What are Operators in C? Different Types of Operators in C
  • What are Expressions in C? Types
  • What are Decision Making Statements in C? Types

Ethical Issues in Business

Ethical Issues in Business | in Setting a New Business

Types of ESOPs

Different Types of ESOPs | Explained

Exit Strategy: Meaning, Importance, Key Steps to Formulating

6 Important Elements of Marketing Plan

5 Cs of Credit in a Business Plan | Explained

Key to Success | Need for Business Planning

example of algorithm problem solving

Chapter: Introduction to the Design and Analysis of Algorithms

Fundamentals of Algorithmic Problem Solving

Let us start by reiterating an important point made in the introduction to this chapter:

We can consider algorithms to be procedural solutions to problems.

These solutions are not answers but specific instructions for getting answers. It is this emphasis on precisely defined constructive procedures that makes computer science distinct from other disciplines. In particular, this distinguishes it from the-oretical mathematics, whose practitioners are typically satisfied with just proving the existence of a solution to a problem and, possibly, investigating the solution’s properties.

We now list and briefly discuss a sequence of steps one typically goes through in designing and analyzing an algorithm (Figure 1.2).

Understanding the Problem

From a practical perspective, the first thing you need to do before designing an algorithm is to understand completely the problem given. Read the problem’s description carefully and ask questions if you have any doubts about the problem, do a few small examples by hand, think about special cases, and ask questions again if needed.

There are a few types of problems that arise in computing applications quite often. We review them in the next section. If the problem in question is one of them, you might be able to use a known algorithm for solving it. Of course, it helps to understand how such an algorithm works and to know its strengths and weaknesses, especially if you have to choose among several available algorithms. But often you will not find a readily available algorithm and will have to design your own. The sequence of steps outlined in this section should help you in this exciting but not always easy task.

An input to an algorithm specifies an instance of the problem the algorithm solves. It is very important to specify exactly the set of instances the algorithm needs to handle. (As an example, recall the variations in the set of instances for the three greatest common divisor algorithms discussed in the previous section.) If you fail to do this, your algorithm may work correctly for a majority of inputs but crash on some “boundary” value. Remember that a correct algorithm is not one that works most of the time, but one that works correctly for all legitimate inputs.

Do not skimp on this first step of the algorithmic problem-solving process; otherwise, you will run the risk of unnecessary rework.

Ascertaining the Capabilities of the Computational Device

Once you completely understand a problem, you need to ascertain the capabilities of the computational device the algorithm is intended for. The vast majority of 

example of algorithm problem solving

algorithms in use today are still destined to be programmed for a computer closely resembling the von Neumann machine—a computer architecture outlined by the prominent Hungarian-American mathematician John von Neumann (1903– 1957), in collaboration with A. Burks and H. Goldstine, in 1946. The essence of this architecture is captured by the so-called random-access machine ( RAM ). Its central assumption is that instructions are executed one after another, one operation at a time. Accordingly, algorithms designed to be executed on such machines are called sequential algorithms .

The central assumption of the RAM model does not hold for some newer computers that can execute operations concurrently, i.e., in parallel. Algorithms that take advantage of this capability are called parallel algorithms . Still, studying the classic techniques for design and analysis of algorithms under the RAM model remains the cornerstone of algorithmics for the foreseeable future.

Should you worry about the speed and amount of memory of a computer at your disposal? If you are designing an algorithm as a scientific exercise, the answer is a qualified no. As you will see in Section 2.1, most computer scientists prefer to study algorithms in terms independent of specification parameters for a particular computer. If you are designing an algorithm as a practical tool, the answer may depend on a problem you need to solve. Even the “slow” computers of today are almost unimaginably fast. Consequently, in many situations you need not worry about a computer being too slow for the task. There are important problems, however, that are very complex by their nature, or have to process huge volumes of data, or deal with applications where the time is critical. In such situations, it is imperative to be aware of the speed and memory available on a particular computer system.

Choosing between Exact and Approximate Problem Solving

The next principal decision is to choose between solving the problem exactly or solving it approximately. In the former case, an algorithm is called an exact algo-rithm ; in the latter case, an algorithm is called an approximation algorithm . Why would one opt for an approximation algorithm? First, there are important prob-lems that simply cannot be solved exactly for most of their instances; examples include extracting square roots, solving nonlinear equations, and evaluating def-inite integrals. Second, available algorithms for solving a problem exactly can be unacceptably slow because of the problem’s intrinsic complexity. This happens, in particular, for many problems involving a very large number of choices; you will see examples of such difficult problems in Chapters 3, 11, and 12. Third, an ap-proximation algorithm can be a part of a more sophisticated algorithm that solves a problem exactly.

Algorithm Design Techniques

Now, with all the components of the algorithmic problem solving in place, how do you design an algorithm to solve a given problem? This is the main question this book seeks to answer by teaching you several general design techniques.

What is an algorithm design technique?

An algorithm design technique (or “strategy” or “paradigm”) is a general approach to solving problems algorithmically that is applicable to a variety of problems from different areas of computing.

Check this book’s table of contents and you will see that a majority of its chapters are devoted to individual design techniques. They distill a few key ideas that have proven to be useful in designing algorithms. Learning these techniques is of utmost importance for the following reasons.

First, they provide guidance for designing algorithms for new problems, i.e., problems for which there is no known satisfactory algorithm. Therefore—to use the language of a famous proverb—learning such techniques is akin to learning to fish as opposed to being given a fish caught by somebody else. It is not true, of course, that each of these general techniques will be necessarily applicable to every problem you may encounter. But taken together, they do constitute a powerful collection of tools that you will find quite handy in your studies and work.

Second, algorithms are the cornerstone of computer science. Every science is interested in classifying its principal subject, and computer science is no exception. Algorithm design techniques make it possible to classify algorithms according to an underlying design idea; therefore, they can serve as a natural way to both categorize and study algorithms.

Designing an Algorithm and Data Structures

While the algorithm design techniques do provide a powerful set of general ap-proaches to algorithmic problem solving, designing an algorithm for a particular problem may still be a challenging task. Some design techniques can be simply inapplicable to the problem in question. Sometimes, several techniques need to be combined, and there are algorithms that are hard to pinpoint as applications of the known design techniques. Even when a particular design technique is ap-plicable, getting an algorithm often requires a nontrivial ingenuity on the part of the algorithm designer. With practice, both tasks—choosing among the general techniques and applying them—get easier, but they are rarely easy.

Of course, one should pay close attention to choosing data structures appro-priate for the operations performed by the algorithm. For example, the sieve of Eratosthenes introduced in Section 1.1 would run longer if we used a linked list instead of an array in its implementation (why?). Also note that some of the al-gorithm design techniques discussed in Chapters 6 and 7 depend intimately on structuring or restructuring data specifying a problem’s instance. Many years ago, an influential textbook proclaimed the fundamental importance of both algo-rithms and data structures for computer programming by its very title: Algorithms + Data Structures = Programs [Wir76]. In the new world of object-oriented programming, data structures remain crucially important for both design and analysis of algorithms. We review basic data structures in Section 1.4.

Methods of Specifying an Algorithm

Once you have designed an algorithm, you need to specify it in some fashion. In Section 1.1, to give you an example, Euclid’s algorithm is described in words (in a free and also a step-by-step form) and in pseudocode. These are the two options that are most widely used nowadays for specifying algorithms.

Using a natural language has an obvious appeal; however, the inherent ambi-guity of any natural language makes a succinct and clear description of algorithms surprisingly difficult. Nevertheless, being able to do this is an important skill that you should strive to develop in the process of learning algorithms.

Pseudocode is a mixture of a natural language and programming language-like constructs. Pseudocode is usually more precise than natural language, and its usage often yields more succinct algorithm descriptions. Surprisingly, computer scientists have never agreed on a single form of pseudocode, leaving textbook authors with a need to design their own “dialects.” Fortunately, these dialects are so close to each other that anyone familiar with a modern programming language should be able to understand them all.

This book’s dialect was selected to cause minimal difficulty for a reader. For the sake of simplicity, we omit declarations of variables and use indentation to show the scope of such statements as for , if , and while . As you saw in the previous section, we use an arrow “ ← ” for the assignment operation and two slashes “ // ” for comments.

In the earlier days of computing, the dominant vehicle for specifying algo-rithms was a flowchart , a method of expressing an algorithm by a collection of connected geometric shapes containing descriptions of the algorithm’s steps. This representation technique has proved to be inconvenient for all but very simple algorithms; nowadays, it can be found only in old algorithm books.

The state of the art of computing has not yet reached a point where an algorithm’s description—be it in a natural language or pseudocode—can be fed into an electronic computer directly. Instead, it needs to be converted into a computer program written in a particular computer language. We can look at such a program as yet another way of specifying the algorithm, although it is preferable to consider it as the algorithm’s implementation.

Proving an Algorithm’s Correctness

Once an algorithm has been specified, you have to prove its correctness . That is, you have to prove that the algorithm yields a required result for every legitimate input in a finite amount of time. For example, the correctness of Euclid’s algorithm for computing the greatest common divisor stems from the correctness of the equality gcd (m, n) = gcd (n, m mod n) (which, in turn, needs a proof; see Problem 7 in Exercises 1.1), the simple observation that the second integer gets smaller on every iteration of the algorithm, and the fact that the algorithm stops when the second integer becomes 0.

For some algorithms, a proof of correctness is quite easy; for others, it can be quite complex. A common technique for proving correctness is to use mathemati-cal induction because an algorithm’s iterations provide a natural sequence of steps needed for such proofs. It might be worth mentioning that although tracing the algorithm’s performance for a few specific inputs can be a very worthwhile activ-ity, it cannot prove the algorithm’s correctness conclusively. But in order to show that an algorithm is incorrect, you need just one instance of its input for which the algorithm fails.

The notion of correctness for approximation algorithms is less straightforward than it is for exact algorithms. For an approximation algorithm, we usually would like to be able to show that the error produced by the algorithm does not exceed a predefined limit. You can find examples of such investigations in Chapter 12.

Analyzing an Algorithm

We usually want our algorithms to possess several qualities. After correctness, by far the most important is efficiency . In fact, there are two kinds of algorithm efficiency: time efficiency , indicating how fast the algorithm runs, and space ef-ficiency , indicating how much extra memory it uses. A general framework and specific techniques for analyzing an algorithm’s efficiency appear in Chapter 2.

Another desirable characteristic of an algorithm is simplicity . Unlike effi-ciency, which can be precisely defined and investigated with mathematical rigor, simplicity, like beauty, is to a considerable degree in the eye of the beholder. For example, most people would agree that Euclid’s algorithm is simpler than the middle-school procedure for computing gcd (m, n) , but it is not clear whether Eu-clid’s algorithm is simpler than the consecutive integer checking algorithm. Still, simplicity is an important algorithm characteristic to strive for. Why? Because sim-pler algorithms are easier to understand and easier to program; consequently, the resulting programs usually contain fewer bugs. There is also the undeniable aes-thetic appeal of simplicity. Sometimes simpler algorithms are also more efficient than more complicated alternatives. Unfortunately, it is not always true, in which case a judicious compromise needs to be made.

Yet another desirable characteristic of an algorithm is generality . There are, in fact, two issues here: generality of the problem the algorithm solves and the set of inputs it accepts. On the first issue, note that it is sometimes easier to design an algorithm for a problem posed in more general terms. Consider, for example, the problem of determining whether two integers are relatively prime, i.e., whether their only common divisor is equal to 1. It is easier to design an algorithm for a more general problem of computing the greatest common divisor of two integers and, to solve the former problem, check whether the gcd is 1 or not. There are situations, however, where designing a more general algorithm is unnecessary or difficult or even impossible. For example, it is unnecessary to sort a list of n numbers to find its median, which is its n/ 2 th smallest element. To give another example, the standard formula for roots of a quadratic equation cannot be generalized to handle polynomials of arbitrary degrees.

As to the set of inputs, your main concern should be designing an algorithm that can handle a set of inputs that is natural for the problem at hand. For example, excluding integers equal to 1 as possible inputs for a greatest common divisor algorithm would be quite unnatural. On the other hand, although the standard formula for the roots of a quadratic equation holds for complex coefficients, we would normally not implement it on this level of generality unless this capability is explicitly required.

If you are not satisfied with the algorithm’s efficiency, simplicity, or generality, you must return to the drawing board and redesign the algorithm. In fact, even if your evaluation is positive, it is still worth searching for other algorithmic solutions. Recall the three different algorithms in the previous section for computing the greatest common divisor: generally, you should not expect to get the best algorithm on the first try. At the very least, you should try to fine-tune the algorithm you already have. For example, we made several improvements in our implementation of the sieve of Eratosthenes compared with its initial outline in Section 1.1. (Can you identify them?) You will do well if you keep in mind the following observation of Antoine de Saint-Exupery,´ the French writer, pilot, and aircraft designer: “A designer knows he has arrived at perfection not when there is no longer anything to add, but when there is no longer anything to take away.” 1

Coding an Algorithm

  Most algorithms are destined to be ultimately implemented as computer pro-grams. Programming an algorithm presents both a peril and an opportunity. The peril lies in the possibility of making the transition from an algorithm to a pro-gram either incorrectly or very inefficiently. Some influential computer scientists strongly believe that unless the correctness of a computer program is proven with full mathematical rigor, the program cannot be considered correct. They have developed special techniques for doing such proofs (see [Gri81]), but the power of these techniques of formal verification is limited so far to very small programs.

As a practical matter, the validity of programs is still established by testing. Testing of computer programs is an art rather than a science, but that does not mean that there is nothing in it to learn. Look up books devoted to testing and debugging; even more important, test and debug your program thoroughly whenever you implement an algorithm.

Also note that throughout the book, we assume that inputs to algorithms belong to the specified sets and hence require no verification. When implementing algorithms as programs to be used in actual applications, you should provide such verifications.

Of course, implementing an algorithm correctly is necessary but not sufficient: you would not like to diminish your algorithm’s power by an inefficient implemen-tation. Modern compilers do provide a certain safety net in this regard, especially when they are used in their code optimization mode. Still, you need to be aware of such standard tricks as computing a loop’s invariant (an expression that does not change its value) outside the loop, collecting common subexpressions, replac-ing expensive operations by cheap ones, and so on. (See [Ker99] and [Ben00] for a good discussion of code tuning and other issues related to algorithm program-ming.) Typically, such improvements can speed up a program only by a constant factor, whereas a better algorithm can make a difference in running time by orders of magnitude. But once an algorithm is selected, a 10–50% speedup may be worth an effort.

A working program provides an additional opportunity in allowing an em-pirical analysis of the underlying algorithm. Such an analysis is based on timing the program on several inputs and then analyzing the results obtained. We dis-cuss the advantages and disadvantages of this approach to analyzing algorithms in Section 2.6.

In conclusion, let us emphasize again the main lesson of the process depicted in Figure 1.2:

As a rule, a good algorithm is a result of repeated effort and rework.

Even if you have been fortunate enough to get an algorithmic idea that seems perfect, you should still try to see whether it can be improved.

Actually, this is good news since it makes the ultimate result so much more enjoyable. (Yes, I did think of naming this book The Joy of Algorithms .) On the other hand, how does one know when to stop? In the real world, more often than not a project’s schedule or the impatience of your boss will stop you. And so it should be: perfection is expensive and in fact not always called for. Designing an algorithm is an engineering-like activity that calls for compromises among competing goals under the constraints of available resources, with the designer’s time being one of the resources.

In the academic world, the question leads to an interesting but usually difficult investigation of an algorithm’s optimality . Actually, this question is not about the efficiency of an algorithm but about the complexity of the problem it solves: What is the minimum amount of effort any algorithm will need to exert to solve the problem? For some problems, the answer to this question is known. For example, any algorithm that sorts an array by comparing values of its elements needs about n log 2 n comparisons for some arrays of size n (see Section 11.2). But for many seemingly easy problems such as integer multiplication, computer scientists do not yet have a final answer.

Another important issue of algorithmic problem solving is the question of whether or not every problem can be solved by an algorithm. We are not talking here about problems that do not have a solution, such as finding real roots of a quadratic equation with a negative discriminant. For such cases, an output indicating that the problem does not have a solution is all we can and should expect from an algorithm. Nor are we talking about ambiguously stated problems. Even some unambiguous problems that must have a simple yes or no answer are “undecidable,” i.e., unsolvable by any algorithm. An important example of such a problem appears in Section 11.3. Fortunately, a vast majority of problems in practical computing can be solved by an algorithm.

Before leaving this section, let us be sure that you do not have the misconception—possibly caused by the somewhat mechanical nature of the diagram of Figure 1.2—that designing an algorithm is a dull activity. There is nothing further from the truth: inventing (or discovering?) algorithms is a very creative and rewarding process. This book is designed to convince you that this is the case.

Exercises 1.2

             Old World puzzle A peasant finds himself on a riverbank with a wolf, a goat, and a head of cabbage. He needs to transport all three to the other side of the river in his boat. However, the boat has room for only the peasant himself and one other item (either the wolf, the goat, or the cabbage). In his absence, the wolf would eat the goat, and the goat would eat the cabbage. Solve this problem for the peasant or prove it has no solution. (Note: The peasant is a vegetarian but does not like cabbage and hence can eat neither the goat nor the cabbage to help him solve the problem. And it goes without saying that the wolf is a protected species.)

            New World puzzle There are four people who want to cross a rickety bridge; they all begin on the same side. You have 17 minutes to get them all across to the other side. It is night, and they have one flashlight. A maximum of two people can cross the bridge at one time. Any party that crosses, either one or two people, must have the flashlight with them. The flashlight must be walked back and forth; it cannot be thrown, for example. Person 1 takes 1 minute to cross the bridge, person 2 takes 2 minutes, person 3 takes 5 minutes, and person 4 takes 10 minutes. A pair must walk together at the rate of the slower person’s pace. (Note: According to a rumor on the Internet, interviewers at a well-known software company located near Seattle have given this problem to interviewees.)

            Which of the following formulas can be considered an algorithm for comput-ing the area of a triangle whose side lengths are given positive numbers a , b , and c ?

example of algorithm problem solving

            Write pseudocode for an algorithm for finding real roots of equation ax 2 + bx + c = 0 for arbitrary real coefficients a, b, and c. (You may assume the availability of the square root function sqrt (x). )

            Describe the standard algorithm for finding the binary representation of a positive decimal integer

                     in English.

                     in pseudocode.

            Describe the algorithm used by your favorite ATM machine in dispensing cash. (You may give your description in either English or pseudocode, which-ever you find more convenient.)

            a.  Can the problem of computing the number π be solved exactly?

                     How many instances does this problem have?

Look up an algorithm for this problem on the Internet.

                                                                    Give an example of a problem other than computing the greatest common divisor for which you know more than one algorithm. Which of them is simpler? Which is more efficient?

                                                                    Consider the following algorithm for finding the distance between the two closest elements in an array of numbers.

ALGORITHM                       MinDistance (A [0 ..n − 1] )

//Input: Array A [0 ..n − 1] of numbers

//Output: Minimum distance between two of its elements dmin ← ∞

for i ← 0 to n − 1 do

for j ← 0 to n − 1 do

if i  = j and |A[i] − A[j ]| < dmin dmin ← |A[i] − A[j ]|

return dmin

Make as many improvements as you can in this algorithmic solution to the problem. If you need to, you may change the algorithm altogether; if not, improve the implementation given.

One of the most influential books on problem solving, titled How To Solve It [Pol57], was written by the Hungarian-American mathematician George Polya´ (1887–1985). Polya´ summarized his ideas in a four-point summary. Find this summary on the Internet or, better yet, in his book, and compare it with the plan outlined in Section 1.2. What do they have in common? How are they different?

Related Topics

Privacy Policy , Terms and Conditions , DMCA Policy and Compliant

Copyright © 2018-2024 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.

example of algorithm problem solving

  • Spencer Greenberg
  • 23 hours ago
  • 14 min read

Problem-Solving Techniques That Work For All Types of Challenges

Essay by Spencer Greenberg, Clearer Thinking founder

A lot of people don’t realize that there are general purpose problem solving techniques that cut across domains. They can help you deal with thorny challenges in work, your personal life, startups, or even if you’re trying to prove a new theorem in math.

Below are the 26 general purpose problem solving techniques that I like best, along with a one-word name I picked for each, and hypothetical examples to illustrate what sort of strategy I’m referring to.

Consider opening up this list whenever you’re stuck solving a challenging problem. It’s likely that one or more of these techniques can help!

example of algorithm problem solving

1. Clarifying

Try to define the problem you are facing as precisely as you can, maybe by writing down a detailed description of exactly what the problem is and what constraints exist for a solution, or by describing it in detail to another person. This may lead to you realizing the problem is not quite what you had thought, or that it has a more obvious solution than you thought.

Life Example

“I thought that I needed to find a new job, but when I thought really carefully about what I don’t like about my current job, I realized that I could likely fix those things by talking to my boss or even, potentially, just by thinking about them differently.”

Startup Example

“we thought we had a problem with users not wanting to sign up for the product, but when we carefully investigated what the problem really was, we discovered it was actually more of a problem of users wanting the product but then growing frustrated because of bad interface design.”

2. Subdividing

Break the problem down into smaller problems in such a way that if you solve each of the small problems, you will have solved the entire problem. Once a problem is subdivided it can also sometimes be parallelized (e.g., by involving different people to work on the different components).

“My goal is to get company Z to become a partner with my company, and that seems hard, so let me break that goal into the steps of (a) listing the ways that company Z would benefit from becoming a partner with us, (b) finding an employee at company Z who would be responsive to hearing about these benefits, and (c) tracking down someone who can introduce me to that employee.”

Math Example

“I want to prove that a certain property applies to all functions of a specific type, so I start by (a) showing that every function of that type can be written as a sum of a more specific type of function, then I show that (b) the property applies to each function of the more specific type, and finally I show that (c) if the property applies to each function in a set of functions then it applies to arbitrary sums of those functions as well.”

3. Simplifying

Think of the simplest variation of the problem that you expect you can solve that shares important features in common with your problem, and see if solving this simpler problem gives you ideas for how to solve the more difficult version.

“I don’t know how to hire a CTO, but I do know how to hire a software engineer because I’ve done it many times, and good CTOs will often themselves be good software engineers, so how can I tweak my software engineer hiring to make it appropriate for hiring a CTO?”

“I don’t know how to calculate this integral as it is, but if I remove one of the free parameters, I actually do know how to calculate it, and maybe doing that calculation will give me insight into the solution of the more complex integral.”

4. Crowd-sourcing 

Use suggestions from multiple people to gain insight into how to solve the problem, for instance by posting on Facebook or Twitter requesting people’s help, or by posting to a Q&A site like Quora, or by sending emails to 10 people you know explaining the problem and requesting assistance.

Business Example

“Do you have experience outsourcing manufacturing to China? If so, I’d appreciate hearing your thoughts about how to approach choosing a vendor.”

Health Example

“I have trouble getting myself to stick to doing exercise daily. If you also used to have trouble getting yourself to exercise but don’t anymore, I’d love to know what worked to make it easier for you.”

5. Splintering

If the problem you are trying to solve has special cases that a solution to the general problem would also apply to, consider just one or two of these special cases as examples and solve the problem just for those cases first. Then see if a solution to one of those special cases helps you solve the problem in general.

“I want to figure out how to improve employee retention in general, let me examine how I could have improved retention in the case of the last three people that quit.”

“I want to figure out how to convince a large number of people to become customers, let me first figure out how to convince just Bill and John to become customers since they seem like the sort of customer I want to attract, and see what general lessons I learn from doing that.”

Read the books or textbooks that seem most related to the topic, and see whether they provide a solution to the problem, or teach you enough related information that you can now solve it yourself.

Economics Example

“Economists probably have already figured out reasonable ways to estimate demand elasticity, let’s see what an econometrics textbook says rather than trying to invent a technique from scratch.”

Mental Health Example

“I’ve been feeling depressed for a long time, maybe I should read some well-liked books about depression.”

7. Searching

Think of a similar problem that you think practitioners, bloggers or academics might have already solved and search online (e.g., via google, Q&A sites, or google scholar academic paper search) to see if anyone has done a write-up about how they solved it.

Advertising Example

“I’m having trouble figuring out the right advertising keywords to bid on for my specific product, I bet someone has a blog post describing how to approach choosing keywords for other related products.”

Machine Learning Example

“I can’t get this neural network to train properly in my specific case, I wonder if someone has written a tutorial about how to apply neural networks to related problems.”

8. Unconstraining

List all the constraints of the problem, then temporarily ignore one or more of the constraints that make the problem especially hard, and try to solve it without those constraints. If you can, then see if you can modify that unconstrained solution until it becomes a solution for the fully constrained problem.

“I need to hire someone who can do work at the intersection of machine learning and cryptography, let me drop the constraint of having cryptography experience and recruit machine learning people, then pick from among them a person that seems both generally capable and well positioned to learn the necessary cryptography.”

Computer Science Example

“I need to implement a certain algorithm, and it needs to be efficient, but that seems very difficult, so let me first figure out how to implement an inefficient version of the algorithm (i.e., drop the efficiency constraint), then at the end I will try to figure out how to optimize that algorithm for efficiency.”

9. Distracting

Fill your mind with everything you know about the problem, including facts, constraints, challenges, considerations, etc. and then stop thinking about the problem, and go and do a relaxing activity that requires little focus, such as walking, swimming, cooking, napping or taking a bath to see if new ideas or potential solutions pop into your mind unexpectedly as your subconscious continues to work on the problem without your attention.

“For three days, I’ve been trying to solve this problem at work, but the solution only came to me when I was strolling in the woods and not even thinking about it.”

Example from mathematician Henri Poincaré

“The incidents of the travel made me forget my mathematical work. Having reached Coutances, we entered an omnibus to go someplace or other. At the moment when I put my foot on the step, the idea came to me, without anything in my former thoughts seeming to have paved the way for it, that the transformations I had used to define the Fuchsian functions were identical with those of non-Euclidean geometry.”

10. Reexamining

Write down all the assumptions you’ve been making about the problem or about what a solution should I look like (yes – make an actual list). Then start challenging them one by one to see if they are actually needed or whether some may be unnecessary or mistaken.

Psychology Example

“We were assuming in our lab experiments that when people get angry they have some underlying reason behind it, but there may be some anger that is better modeled as a chemical fluctuation that is only loosely related to what happens in the lab, such as when people are quick to anger because they are hungry.”

“I need to construct a function that has this strange property, and so far I’ve assumed that the function must be smooth, but if it doesn’t actually need to be then perhaps I can construct just such a function out of simple linear pieces that are glued together.”

11. Reframing

Try to see the problem differently. For instance, by flipping the default, analyzing the inverse of the problem instead, thinking about how you would achieve the opposite of what you want, or shifting to an opposing perspective.

If we were building this company over again completely from scratch, what would we do differently in the design of our product, and can we pivot the product in that direction right now?”

“Should move to New York to take a job that pays $20,000 more per year? Well, if I already lived in New York, the decision to stay there rather than taking a $20,000 pay cut to move here would be an easy one. So maybe I’m overly focused on the current default of not being in New York and the short term unpleasantness of relocating.”

Marketing Example

“If I were one of our typical potential customers, what would I do to try to find a product like ours?”

12. Brainstorming

Set a timer for at least 5 minutes, and generate as many plausible solutions or ideas that you can without worrying about quality at all. Evaluate the ideas only at the end after the timer goes off.

“I’m going to set a timer for 5 minutes and come up with at least three new ways I could go about looking for a co-founder.”

“I’m going to set a timer for 20 minutes and come up with at least five possible explanations for why I’ve been feeling so anxious lately.”

13. Experting

Find an expert (or someone highly knowledgeable) in the topic area and ask their opinion about the best way to solve the problem.

“Why do you think most attempts at creating digital medical records failed, and what would someone have to do differently to have a reasonable chance at success?”

“What sort of optimization algorithm would be most efficient for minimizing the objective functions of this type?”

14. Eggheading

Ask the smartest person you know how they would solve the problem. Be sure to send an email in advance, describing the details so that this person has time to deeply consider the problem before you discuss it.

“Given the information I sent you about our competitors and the interviews we’ve done with potential customers, in which direction would you pivot our product if you were me (and why)?”

Research Example

“Given the information I sent you about our goals and the fact that our previous research attempts have gotten nowhere, how would you approach researching this topic to find the answer we need?”

15. Guessing

Start with a guess for what the solution could be, now check if it actually works and if not, start tweaking that guess to see if you can morph it into something that could work.

“I don’t know what price to use for the product we’re selling, so let me start with an initial guess and then begin trying to sell the thing, and tweak the price down if it seems to be a sticking point for customers, and tweak the price up if the customers don’t seem to pay much attention to the price.”

“My off the cuff intuition says that this differential equation might have a solution of the form x^a * e^(b x)for some a or b, let me plug it into the equation to see if indeed it satisfies the equation for any choice of a and b, and if not, let me see if I can tweak it to make something similar work.”

“I don’t know what the most effective diet for me would be, so I’ll just use my intuition to ban from my diet some foods that seem both unhealthy and addictive, and see if that helps.”

16. Comparing

Think of similar domains you already understand or similar problems you have already solved in the past, and see whether your knowledge of those domains or solutions to those similar problems may work as a complete or partial solution here.

“I don’t know how to find someone to fix things in my apartment, but I have found a good house cleaner before by asking a few friends who they use, so maybe I can simply use the same approach for finding a person to fix things.”

“This equation I’m trying to simplify reminds me of work I’m familiar with related to Kullback-Leibler divergence, I wonder if results from information theory could be applied in this case.”

17. Outsourcing

Consider whether you can hire someone to solve this problem, instead of figuring out how to solve it yourself.

“I don’t really understand how to get media attention for my company, so let me hire a public relations firm and let them handle the process.”

“I have no fashion sense, but I’d like to look better. Maybe I should hire someone fashionable who works in apparel to go shopping with me and help me choose what I should wear.”

18. Experimenting

Rapidly develop possible solutions and test them out (in sequence, or in parallel) by applying cheap and fast experiments. Discard those that don’t work, or iterate on them to improve them based on what you learn from the experiments.

“We don’t know if people will like a product like the one we have in mind, but we can put together a functioning prototype quickly, show five people that seem like they could be potential users, and iterate or create an entirely new design based on how they respond.”

“I don’t know if cutting out sugar will help improve my energy levels, but I can try it for two weeks and see if I notice any differences.”

19. Generalizing

Consider the more general case of the specific problem you are trying to solve, and then work on solving the general version instead. Paradoxically, it is sometimes easier to make progress on the general case rather than a specific one because it increases your focus on the structure of the problem rather than unimportant details.

“I want to figure out how to get this particular key employee more motivated to do good work, let me construct a model of what makes employees motivated to do good work in general, then I’ll apply it to this case.”

“I want to solve this specific differential equation, but it’s clearly a special case of a more general class of differential equations, let me study the general class and see what I can learn about them first and then apply what I learn to the specific case.”

20. Approximating

Consider whether a partial or approximate solution would be acceptable and, if so, aim for that instead of a full or exact solution.

“Our goal is to figure out which truck to send out for which delivery, which theoretically depends on many factors such as current location, traffic conditions, truck capacity, fuel efficiency, how many hours the driver has been on duty, the number of people manning each truck, the hourly rate we pay each driver, etc. etc. Maybe if we focus on just the three variables that we think are most important, we can find a good enough solution.”

“Finding a solution to this equation seems difficult, but if I approximate one of the terms linearly it becomes much easier, and maybe for the range of values we’re interested in, that’s close enough to an exact solution!”

21. Annihilating

Try to prove that the problem you are attempting to solve is actually impossible. If you succeed, you may save yourself a lot of time working on something impossible. Furthermore, in attempting to prove that the problem is impossible, you may gain insight into what makes it actually possible to solve, or if it turns out to truly be impossible, figure out how you could tweak the problem to make it solvable.

“I’m struggling to find a design for a theoretical voting system that has properties X, Y, and Z, let me see if I can instead prove that no such voting system with these three properties could possibly exist.”

“My goal has been to prove that this property always applies to this class of functions, let me see if I can generate a counterexample to prove that this goal is actually impossible.”

Physics Example

“I was trying to design a physical system with certain properties, but I now realize that if such a system could be realized, then it would allow for perpetual motion, and therefore it is impossible to build the sort of system I had in mind.”

22. Modeling

Try to build an explicit model of the situation, including what elements there are and how they related to each other. For instance, try drawing a diagram or flow chart that encapsulates your understanding of all the important information that relates to the problem.

“I’ve noticed that there are certain situations that cause me to freak out that would not bother other people. So what are the common elements when this happens, and how do they seem to relate to each other and to the way I end up feeling? Let me see if I can draw a diagram of this on paper.”

“What are all the different groups (e.g., providers, payers, patients) involved in the healthcare system, and if we diagram how they interact with each other, will that give us ideas for how we can sell our healthcare product?”

23. Brute forcing

One-by-one, consider every possible solution to the problem until you’ve found a good one or exhausted them all.

Startup example

“We’re not sure the order that these four parts of the user registration process should go in, so let’s make a list of all 24 possible orderings, and examine them one by one to see which makes the most sense.”

“It’s not clear how to pick which of these machine learning methods to use on this problem, but since we have lots of data, we can just try each of the algorithms and see which makes the most accurate predictions on data we’ve held to the side for testing.”

24. Refocusing

Forget about trying to solve the problem, and instead consider why you are trying to solve it. Then consider if there is a different problem you can work on that is aimed at producing the same sort of value in a different way.

Startup Example 1

“Maybe instead of trying increasingly hard to figure out how to get this type of consumer to buy, we need to switch our focus to the problem of how to sell to businesses, since what we actually care about is selling it, not selling it to one particular group.”

Startup Example 2

“I’ve been banging my head against the wall trying to implement this extremely complex feature, but there are lots of features that users would find just as valuable that are much easier to implement, maybe I should focus on those instead.”

25. Sidestepping

Consider whether you really want to spend more time trying to solve this problem and whether you can avoid the problem by instead working on totally different problems that you also care about.

“We’ve tried selling our solution to replace Excel for 12 months without much success, maybe we should go back to the drawing board and consider designing a totally new product. Our assumptions about customer needs seem to simply have been wrong.”

“I’ve spent six months on this math problem with little progress, but there are two other math problems I’m equally excited about, so maybe I should spend some time investigating whether one of those may be more tractable.”

26. Aggregating

Consider whether multiple problems you’re now experiencing might, in fact, be caused by the same source of difficulty, rather than being independent problems.

“I seem to be having conflict with a few different friends right now – could it be that I’m doing something without realizing it that is increasing my chance of conflict with all of them?”

“Three employees have quit in the last month. Perhaps the primary problem isn’t really about convincing this one important employee to stay, which is how I was framing it, but rather, about identifying why people keep leaving more generally.”

Recent Posts

Remembering Daniel Kahneman: 7 theories that can help you understand how you think

Test how well you understand human psychology with our new quiz

10 Times Scientists Admitted They Were Wrong, and What You Can Learn from Them

An Ulm-like algorithm for generalized inverse eigenvalue problems

  • Original Paper
  • Published: 09 May 2024

Cite this article

example of algorithm problem solving

  • Yusong Luo 1 &
  • Weiping Shen 1  

46 Accesses

Explore all metrics

In this paper, we study the numerical solutions of the generalized inverse eigenvalue problem (for short, GIEP). Motivated by Ulm’s method for solving general nonlinear equations and the algorithm of Aishima (J. Comput. Appl. Math. 367 , 112485 2020 ) for the GIEP, we propose here an Ulm-like algorithm for the GIEP. Compared with other existing methods for the GIEP, the proposed algorithm avoids solving the (approximate) Jacobian equations and so it seems more stable. Assuming that the relative generalized Jacobian matrices at a solution are nonsingular, we prove the quadratic convergence property of the proposed algorithm. Incidentally, we extend the work of Luo et al. (J. Nonlinear Convex Anal. 24 , 2309–2328 2023 ) for the inverse eigenvalue problem (for short, IEP) to the GIEP. Some numerical examples are provided and comparisons with other algorithms are made.

This is a preview of subscription content, log in via an institution to check access.

Access this article

Price includes VAT (Russian Federation)

Instant access to the full article PDF.

Rent this article via DeepDyve

Institutional subscriptions

example of algorithm problem solving

Similar content being viewed by others

example of algorithm problem solving

Riemannian inexact Newton method for structured inverse eigenvalue and singular value problems

example of algorithm problem solving

Disguised and new quasi-Newton methods for nonlinear eigenvalue problems

Solving an abstract nonlinear eigenvalue problem by the inverse iteration method, data availability.

No datasets were generated or analysed during the current study.

Code Availability

Not applicable.

Aishima, K.: A quadratically convergent algorithm based on matrix equations for inverse eigenvalue problems. Linear Algebra Appl. 542 , 310–333 (2018)

Article   MathSciNet   Google Scholar  

Aishima, K.: A quadratically convergent algorithm for inverse eigenvalue problems with multiple eigenvalues. Linear Algebra Appl. 549 , 30–52 (2018)

Aishima, K.: A quadratically convergent algorithm for inverse generalized eigenvalue problems. J. Comput. Appl. Math. 367 , 112485 (2020)

Arela-Pérez, S., Lozano, C., Nina, H., Pickmann-Soto, H., Rodríguez, J.: The new inverse eigenvalue problems for periodic and generalized periodic Jacobi matrices from their extremal spectral data. Linear Algebra Appl. 659 , 55–72 (2023)

Bai, Z.J., Chan, R.H., Morini, B.: An inexact Cayley transform method for inverse eigenvalue problems. Inverse Probl. 20 , 1675–1689 (2004)

Bai, Z.J., Jin, X.Q.: A note on the Ulm-like method for inverse eigenvalue problems. Recent Advances in Scientific Computing and Matrix Analysis, 1–7 (2011)

Behera, K.K.: A generalized inverse eigenvalue problem and m-functions. Linear Algebra Appl. 622 , 46–65 (2021)

Cai, J., Chen, J.: Iterative solutions of generalized inverse eigenvalue problem for partially bisymmetric matrices. Linear Multilinear A. 65 , 1643–1654 (2017)

Chan, R.H., Chung, H.L., Xu, S.F.: The inexact Newton-like method for inverse eigenvalue problem. BIT Numer. Math. 43 , 7–20 (2003)

Chu, M.T., Golub, G.H.: Structured inverse eigenvalue problems. Acta Numer. 11 , 1–71 (2002)

Dai, H.: An algorithm for symmetric generalized inverse eigenvalue problems. Linear Algebra Appl. 296 , 79–98 (1999)

Dai, H., Lancaster, P.: Newton’s method for a generalized inverse eigenvalue problem. Numer. Linear Algebra Appl. 4 , 1–21 (1997)

Dai, H., Bai, Z.Z., Wei, Y.: On the solvability condition and numerical algorithm for the parameterized generalized inverse eigenvalue problem. SIAM J. Matrix Anal. Appl. 36 , 707–726 (2015)

Dalvand, Z., Hajarian, M.: Newton-like and inexact Newton-like methods for a parameterized generalized inverse eigenvalue problem. Math. Methods Appl. Sci. 44 , 4217–4234 (2021)

Dalvand, Z., Hajarian, M., Roman, J.E.: An extension of the Cayley transform method for a parameterized generalized inverse eigenvalue problem. Numer. Linear Algebra Appl. 27 , e2327 (2020)

Ezquerro, J.A., Hernández, M.A.: The Ulm method under mild differentiability conditions. Numer. Math. 109 , 193–207 (2008)

Friedland, S., Nocedal, J., Overton, M.L.: The formulation and analysis of numerical methods for inverse eigenvalue problems. SIAM J. Numer. Anal. 24 , 634–667 (1987)

Gajewski, A., Zyczkowski, M.: Optimal structural design under stability constraints. Kluwer Academic, Dordrecht, The Natherlands (1988)

Book   Google Scholar  

Galperin, A., Waksman, Z.: Ulm’s method under regular smoothness. Numer. Funct. Anal. Optim. 19 , 285–307 (1998)

Ghanbari, K.: A survey on inverse and generalized inverse eigenvalue problems for Jacobi matrices. Appl. Math. Comput. 195 , 355–363 (2008)

MathSciNet   Google Scholar  

Ghanbari, K.: m-functions and inverse generalized eigenvalue problem. Inverse Probl. 17 , 211 (2001)

Golub, G.H., Van Loan, C.F.: Matrix Computations, 3rd edn. Johns Hopkins University Press, Baltimore (1996)

Google Scholar  

Grandhi, R.: Structural optimization with frequency constraints-Areview. AIAA J. 31 , 2296–2303 (1993)

Article   Google Scholar  

Gutiérrez, J.M., Hernández, M.A., Romero, N.: A note on a modification of Moser’s method. J. Complex. 24 , 185–197 (2008)

Hald, O.: On discrete and numerical Sturm-Liouville problems. New York University, New York (1972)

Hald, O.: On a Newton-Moser type method. Numer. Math. 23 , 411–426 (1975)

Harman, H.: Modern factor analysis. University of Chicago Press, Chicago (1976)

Joseph, K.T.: Inverse eigenvalue problem in structural design. AIAA J. 30 , 2890–2896 (1992)

Li, R.C.: A perturbation bound for definite pencils. Linear Algebra Appl. 179 , 191–202 (1993)

Luo, Y.S., Shen, W.P., Luo, E.P.: A quadratically convergent algorithm for inverse eigenvalue problems. J. Nonlinear Convex Anal. 24 , 2309–2328 (2023)

Ma, W.: Two-step Ulm-Chebyshev-like Cayley transform method for inverse eigenvalue problems. Int. J. of Comput. Math. 99 , 391–406 (2022)

Shen, W.P., Li, C., Jin, X.Q.: A Ulm-like method for inverse eigenvalue problems. Appl. Numer. Math. 61 , 356–367 (2011)

Shen, W.P., Li, C., Jin, X.Q.: An inexact Cayley transform method for inverse eigenvalue problems with multiple eigenvalues. Inverse Probl. 31 , 085007 (2015)

Shen, W.P., Li, C., Jin, X.Q.: An Ulm-like Cayley transform method for inverse eigenvalue problems with multiple eigenvalues. Numer. Math. -Theory Me. 9 , 664–685 (2016)

Sivan, D.D., Ram, Y.M.: Mass and stiffness modifications to achieve desired natural frequencies. Commun. Numer. Methods Engrg. 12 , 531–542 (1996)

Sun, D., Sun, J.: Strong semismoothness of eigenvalues of symmetric matrices and its application to inverse eigenvalue problems. SIAM J. Numer. Anal. 40 , 2352–2367 (2002)

Sun, J.G.: Multiple eigenvalue sensitivity analysis. Linear Algebra Appl. 137 , 183–211 (1990)

Ulm, S.: On iterative methods with successive approximation of the inverse operator. Izv. Akad. Nauk Est. SSR 16 , 403–411 (1967)

Wen, C.T., Chen, X.S., Sun, H.W.: A two-step inexact Newton-Chebyshev-like method for inverse eigenvalue problems. Linear Algebra Appl. 585 , 241–262 (2020)

Xie, H.Q., Dai, H.: Inverse eigenvalue problem in structural dynamics design. Number. Math. J. Chinese Univ. 15 , 97–106 (2006)

Zehnder, E.J.: A remark about Newton’s method, Commun. Pure. Appl. Math. 27 , 361–366 (1974)

Zhang, H., Yuan, Y.: Generalized inverse eigenvalue problems for Hermitian and J-Hamiltonian/skew-Hamiltonian matrices. Appl. Math. Comput. 361 , 609–616 (2019)

Download references

Acknowledgements

We would like to thank the anonymous referees for their helpful and valuable comments which lead to the improvement of this paper.

This work was supported in part by the National Natural Science Foundation of China (grant 12071441).

Author information

Authors and affiliations.

School of Mathematical Sciences, Zhejiang Normal University, Jinhua, 321004, People’s Republic of China

Yusong Luo & Weiping Shen

You can also search for this author in PubMed   Google Scholar

Contributions

Yusong Luo and Weiping Shen wrote the main manuscript text. Both authors reviewed the manuscript.

Corresponding author

Correspondence to Weiping Shen .

Ethics declarations

Competing interests.

The authors declare no competing interests.

Ethics approval

Consent to participate.

All authors participated.

Consent for publication

All authors agreed to publish.

Additional information

Publisher's note.

Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.

Rights and permissions

Springer Nature or its licensor (e.g. a society or other partner) holds exclusive rights to this article under a publishing agreement with the author(s) or other rightsholder(s); author self-archiving of the accepted manuscript version of this article is solely governed by the terms of such publishing agreement and applicable law.

Reprints and permissions

About this article

Luo, Y., Shen, W. An Ulm-like algorithm for generalized inverse eigenvalue problems. Numer Algor (2024). https://doi.org/10.1007/s11075-024-01845-5

Download citation

Received : 29 November 2023

Accepted : 29 April 2024

Published : 09 May 2024

DOI : https://doi.org/10.1007/s11075-024-01845-5

Share this article

Anyone you share the following link with will be able to read this content:

Sorry, a shareable link is not currently available for this article.

Provided by the Springer Nature SharedIt content-sharing initiative

  • Generalized inverse eigenvalue problem
  • Newton’s method
  • Ulm’s method
  • Quadratic convergence

Mathematics Subject Classification (2010)

  • Find a journal
  • Publish with us
  • Track your research

IMAGES

  1. Unit2 algorithmic problem_solving

    example of algorithm problem solving

  2. Algorithm and Flowchart

    example of algorithm problem solving

  3. PPT

    example of algorithm problem solving

  4. Problem-solving algorithm

    example of algorithm problem solving

  5. DAA 1 7 Fundamentals of Algorithmic problem solving

    example of algorithm problem solving

  6. What is Problem Solving Algorithm?, Steps, Representation

    example of algorithm problem solving

VIDEO

  1. What is an Algorithm With Explanation in hindi|Algorithms in hindi|M3-R5 O level|Python Tutorials-1

  2. Basic Algorithm (Problem solving)

  3. For which problem algorithm be written? एल्गोरिथम कैसे प्रॉब्लम्स के लिए लिख सकते हैं?

  4. What is an algorithm

  5. Algorithmic Problem Solving with Python Ep04

  6. Strassen's Matrix Multiplication

COMMENTS

  1. How to Use Algorithms to Solve Problems?

    Let's take some examples of algorithms for computer science problems. Example 1. Swap two numbers with a third variable. Step 1: Start. Step 2: Take 2 numbers as input. Step 3: Declare another variable as "temp". Step 4: Store the first variable to "temp". Step 5: Store the second variable to the First variable.

  2. The building blocks of algorithms

    An algorithm is a step by step process that describes how to solve a problem in a way that always gives a correct answer. When there are multiple algorithms for a particular problem (and there often are!), the best algorithm is typically the one that solves it the fastest.

  3. How to use algorithms to solve everyday problems

    My approach to making algorithms compelling was focusing on comparisons. I take algorithms and put them in a scene from everyday life, such as matching socks from a pile, putting books on a shelf, remembering things, driving from one point to another, or cutting an onion. These activities can be mapped to one or more fundamental algorithms ...

  4. 4. Problem Solving and Algorithms

    An algorithm is a plan for solving a problem, but plans come in several levels of detail. It's usually better to start with a high-level algorithm that includes the major part of a solution, but leaves the details until later. ... For example, an algorithm that computes the area of a circle having radius 5.2 meters (formula π*5.2 2) solves a ...

  5. PDF Principles of Algorithmic Problem Solving

    by Euler, algorithmic problem solving has been a popular intellectual pursuit during the last few thousand years. For a long time, it was a purely mathemati-cal endeavor with algorithms meant to be executed by hand. During the recent decades algorithmic problem solving has evolved. What was mainly a topic of

  6. What Is an Algorithm?

    An algorithm is a sequence of instructions that a computer must perform to solve a well-defined problem. It essentially defines what the computer needs to do and how to do it. Algorithms can instruct a computer how to perform a calculation, process data, or make a decision. The best way to understand an algorithm is to think of it as a recipe ...

  7. 8.2 Problem-Solving: Heuristics and Algorithms

    Algorithms. In contrast to heuristics, which can be thought of as problem-solving strategies based on educated guesses, algorithms are problem-solving strategies that use rules. Algorithms are generally a logical set of steps that, if applied correctly, should be accurate. For example, you could make a cake using heuristics — relying on your ...

  8. What is an Algorithm?

    In computer programming terms, an algorithm is a set of well-defined instructions to solve a particular problem. It takes a set of input (s) and produces the desired output. For example, An algorithm to add two numbers: Take two number inputs. Add numbers using the + operator. Display the result.

  9. Algorithm Problem Solving Strategies

    Be Strategic, Think First. Rather than diving in, approach the problem in stages: Think: Analyze the problem. Restate the problem. Write out examples of input and output. Break the problem into its component parts. Outline a solution in psuedo-code. Step through your example data with your psuedo-code.

  10. The Algorithm Problem Solving Approach in Psychology

    In psychology, one of these problem-solving approaches is known as an algorithm. While often thought of purely as a mathematical term, the same type of process can be followed in psychology to find the correct answer when solving a problem or making a decision. An algorithm is a defined set of step-by-step procedures that provides the correct ...

  11. 6 Real World Algorithm Examples for Students

    6 Examples of Real-World Algorithms. Whether algorithms are used in places that aren't at all surprising, like Google, or in a manual activity that is more unexpected, like brushing your teeth, algorithms play a role in the human experience every single day, Guyon goes on to explain. 1. Sorting Papers. Imagine a teacher sorting their students ...

  12. Problem-Solving Approaches in Data Structures and Algorithms

    Divide and Conquer Approach. This strategy is about dividing a problem into more than one subproblems, solving each of them, and then, if necessary, combining their solutions to get a solution to the original problem. We solve many fundamental problems efficiently in computer science by using this strategy. Example problems: Merge Sort , Quick ...

  13. 3 Essential Algorithm Examples You Should Know

    Algorithm Examples, #1: Binary Search. Binary search is an essential search algorithm that takes in a sorted array and returns the index of the value we are searching for. We do this with the following steps: Find the midpoint of the sorted array. Compare the midpoint to the value of interest. If the midpoint is larger than the value, perform ...

  14. How to Solve an Algorithm Problem?

    2) Break the problem down. Here is a step-by-step explanation of the algorithm in plain English: Convert all uppercase letters in the string to lowercase. This is done so that the case of the letters in the string does not affect the outcome of the comparison. Remove all non-alphanumeric characters from the string.

  15. Top 20 Algorithms Problems for Coding Interviews with Solutions

    Here are 20+ algorithms problems you can practice. This list included questions on essential searching and sorting algorithms like binary search, quick sort, counting sort, etc. ... For example ...

  16. Problem-Solving With Algorithms

    An algorithm is a detailed, step-by-step process followed in order to accomplish a specific task or to solve a specific problem. Computer algorithms can appear complex, but the underlying concept is approachable for both adults and kids. We can define an algorithm by writing out the step-by-step instructions, thinking about things in terms of ...

  17. What is Problem Solving Algorithm?, Steps, Representation

    1. A method of representing the step-by-step logical procedure for solving a problem. Flowchart is diagrammatic representation of an algorithm. It is constructed using different types of boxes and symbols. 2. It contains step-by-step English descriptions, each step representing a particular operation leading to solution of problem.

  18. Fundamentals of Algorithmic Problem Solving

    An input to an algorithm specifies an instance of the problem the algorithm solves. It is very important to specify exactly the set of instances the algorithm needs to handle. (As an example, recall the variations in the set of instances for the three greatest common divisor algorithms discussed in the previous section.)

  19. Top 25 Algorithms Every Programmer Should Know

    The following is a list of the top 25 algorithms every programmer and computer science student should know. Binary Search Algorithm. Breadth First Search (BFS) Algorithm. Depth First Search (DFS ...

  20. Problem-Solving Strategies: Definition and 5 Techniques to Try

    In insight problem-solving, the cognitive processes that help you solve a problem happen outside your conscious awareness. 4. Working backward. Working backward is a problem-solving approach often ...

  21. Problem-Solving Techniques That Work For All Types of Challenges

    Consider opening up this list whenever you're stuck solving a challenging problem. It's likely that one or more of these techniques can help! 1. Clarifying. Try to define the problem you are facing as precisely as you can, maybe by writing down a detailed description of exactly what the problem is and what constraints exist for a solution ...

  22. Maze-solving algorithm

    A maze-solving algorithm is an automated method for solving a maze. The random mouse, wall follower, Pledge, and Trémaux's algorithms are designed to be used inside the maze by a traveler with no prior knowledge of the maze, whereas the dead-end filling and shortest path algorithms are designed to be used by a person or computer program that ...

  23. How to solve this Phonepe's Graph Problem

    Sum up each path []. - Form each path sum, reduce the last k element. - Sum of the path [i] - reduced k elements. - Return minimum sum from previous step (for all the paths). - user24714692. 16 hours ago. 3. Same code challenge as here -- same writing on the image. - trincot.

  24. An Ulm-like algorithm for generalized inverse eigenvalue problems

    In this paper, we study the numerical solutions of the generalized inverse eigenvalue problem (for short, GIEP). Motivated by Ulm's method for solving general nonlinear equations and the algorithm of Aishima (J. Comput. Appl. Math. 367, 112485 2020) for the GIEP, we propose here an Ulm-like algorithm for the GIEP. Compared with other existing methods for the GIEP, the proposed algorithm ...

  25. Know the Difference Between Algorithm and Program

    The algorithm will solve problems recursively. It will find a solution to a problem by solving one piece of the problem at a time. If one of the solutions fails, it is removed, and the algorithm backtracks to find another solution. Example: Queens Problem; Divide and Conquer Algorithm - As the name suggests, the algorithm is divided into two ...

  26. Research on Multi-Objective Flexible Job Shop Scheduling Problem with

    An improved shuffled frog leading algorithm is designed to solve it through the optimization of the initial solution population, the improvement of evolutionary operations, and the incorporation of Pareto sorting. ... and the experimental results confirm the satisfactory performance of the proposed algorithm. Finally, a problem example is ...

  27. A variational quantum algorithm-based numerical method for solving

    This paper presents a numerical method based on the variational quantum algorithm to solve potential and Stokes flow problems. In this method, the governing equations for potential and Stokes flows can be respectively written in the form of Laplace's equation and Stokes equations using velocity potential, stream function and vorticity formulations. Then the finite difference method and the ...