Problem-Solving Strategies PDF
Document Details
Uploaded by Deleted User
Tags
Summary
This document details problem-solving strategies, focusing on algorithms and heuristics. It explains how to approach problems, starting with understanding the problem and defining the goal, then moving towards creating a strategy and using methods like trial and error, algorithms, and heuristics. It emphasizes the importance of different approaches for various problems.
Full Transcript
# PROBLEM-SOLVING STRATEGIES ## 1.1 Introduction Typically, the term "problem" refers to a situation where the solution is not immediately apparent. Formally, a problem is defined by the following four conditions or parameters: - Initial situation - Goal - A set of resources that can be used to m...
# PROBLEM-SOLVING STRATEGIES ## 1.1 Introduction Typically, the term "problem" refers to a situation where the solution is not immediately apparent. Formally, a problem is defined by the following four conditions or parameters: - Initial situation - Goal - A set of resources that can be used to move from the starting situation to the desired goal. These may be limits on these resources, such as rules and guidelines on what is allowed when solving the problem. - A commitment to using your own knowledge, skills, and energy to reach the goal. If one or more of these components are missing, the problem is not well-defined. Critical thinking involves using cognitive skills or strategies to increase the likelihood of a desirable outcome. Problem solving is the process of moving from an initial situation to a desired goal by designing and carrying out steps to achieve it. This includes answering questions, solving problems, accomplishing tasks, and making decisions, all of which require critical thinking. Students are often expected to recognize, pose, clarify, and solve complex and challenging problems that they have not encountered before. Although algorithms are now primarily associated with software and computers, their origins go back much further. They have been used intuitively for centuries in the form of regulatory systems, instructions, game rules, architectural plans, and musical scores. An algorithm is a procedure for decision-making or a set of instructions that consist of a finite number of rules. It can also be defined as a finite sequence of clear, basic instructions that precisely describe how to solve a specific problem. This definition applies to various fields, including mathematics, fine art, and music. However, the most well-known application of algorithms is in computer programming, where a program is an algorithm written in a language that a computer can process. This chapter focuses on using computational approaches to solve problems by employing algorithms to achieve defined goals in a computer-enabled format. ## 1.2 Problem-Solving Strategies Defined When faced with a problem, whether it's a complex math puzzle or a malfunctioning printer, the key is to outline a strategy to solve or repair it. The first step is clearly identifying the problem. Then, you can apply one of several problem-solving strategies in the hopes of finding a solution. A problem-solving strategy is a plan used to find solutions or tackle challenges. Each strategy includes specific steps to follow. For example, trial and error is one common strategy. These approaches provide guidelines to help you solve business problems or industry issues effectively. To solve problems successfully, you need to identify the problem, choose the right approach, and follow a plan tailored to the specific issue. ## 1.3 Importance of Understanding Multiple Problem-solving Strategies Problems can be classified into two categories: ill-defined and well-defined problems. Ill-defined problems lack clear goals, solution paths, and expected solutions. In contrast, well-defined problems have specific goals, clear solutions, and known expected outcomes. Problem solving often involves logical reasoning, interpreting the problem’s meaning, and sometimes abstract thinking and creativity to find innovative solutions. Different methods for studying problem solving include introspection, simulation, computer modeling, and experimentation. It is important to understand how different problem-solving strategies work because various problems need different approaches for the best solution. By mastering several strategies, you can more effectively choose the right one when facing future challenges. This helps you solve problems faster and build stronger critical thinking skills. ## 1.4 Trial and Error A trial-and-error approach to problem-solving involves trying various solutions and eliminating those that do not work. This method can be useful if you have only a few options. For instance, if a printer is broken, you might start by checking the ink levels. If that doesnot work, you could check for a paper jam, or ensure the printer is connected to the laptop. Using trial and error, you keep trying different solutions until you solve the problem. Although it is not the most time-efficient strategy, it is commonly used. It is also a basic learning method used by every organism to learn a new behaviour. ## 1.5 Algorithm and Heuristics A common type of strategy is an algorithm. An algorithm is a problem-solving formula that provides step-by-step instructions to achieve a desired outcome (Kahneman, 2011). You can think of an algorithm as a recipe with detailed instructions that produce the same result every time. Algorithms are frequently used in our everyday lives, especially in computer science. For example, when you run an internet search, search engines like Google use algorithms to determine which entries appear first. Similarly, Facebook uses algorithms to decide which posts to display on your newsfeed. Can you think of other situations where algorithms are used? A heuristic is another type of problem-solving strategy. While an algorithm must be followed exactly to produce a correct result, a heuristic is a general problem-solving framework. Think of heuristics as mental shortcuts used to solve problems. A “rule of thumb” is an example of a heuristic. It saves time and energy when making decisions, but despite its efficiency, it is not always the best method for making rational decisions. Different types of heuristics are used in various situations, and the impulse to use a heuristic occurs when one of five conditions is met: 1. When one is faced with too much information 2. When the time to make a decision is limited 3. When the decision to be made is unimportant 4. When there is access to very little information to use in making the decision 5. When an appropriate heuristic happens to come to mind in the same moment Working backwards is a useful heuristic where you start solving the problem by focusing on the end result. People commonly use this heuristic to plan their daily events, often without even realizing it. Consider an example: Imagine you need to arrive at an important meeting by 3:00 PM. To plan your day using the working backwards heuristic, you start from the end goal and think about the steps needed to get there. You consider that it takes 30 minutes to get to the meeting location, so you need to leave by 2:30 PM. Before that, you need an hour to prepare, so you start getting ready at 1:30 PM. If you also want to finish a task that takes an hour before getting ready, you need to start that task by 12:30 PM. By working backwards, you effectively plan your day to ensure you arrive at the meeting on time. Another useful heuristic is breaking a large goal or task into a series of smaller steps. Students often use this method to complete a large research project or a long essay. For example, they typically start by brainstorming, developing a thesis or main topic, researching the topic, organizing their information into an outline, writing a rough draft, revising and editing the draft, developing a final draft, organizing the reference list, and proof-reading their work before submitting the project. This approach makes the large task less overwhelming by dividing it into manageable steps. ## 1.6 Means-Ends Analysis This strategy involves choosing and analyzing actions in a series of smaller steps to move closer to the goal. One example of means-end analysis can be seen in the Tower of Hanoi puzzle. This puzzle can be described as a word problem. A French mathematician Édouard Lucas invented a game puzzle called Tower of Hanoi in 1883. This puzzle game is related to a religious temple of Hanoi, Vietnam, the name of the temple was the Tower of Hanoi. This temple has three towers which are surrounded by sixty-four golden disks in the temple. The temple priests used to pass these disks from one tower to another with traditional rules. According to the monks, the world would end when the first disk came back. That’s why it is also called the Tower of Brahma puzzle. In this context, The Tower of Hanoi is designed as a mathematical puzzle involving disks of varying sizes that can be stacked on top of each other. The puzzle features three towers, and the disks are initially arranged in ascending order on these towers as shown in the figure 1.1. The Tower of Hanoi problem consists of three vertical rods on a base, with several disks of different sizes that can slide onto any rod. The puzzle starts with the disks neatly stacked in ascending order of size on one rod, with the smallest disk on top, forming a conical shape. The goal is to move the entire stack to another rod while obeying these rules: 1. Only one disk can be moved at a time. 2. Each move involves taking the top disk from one stack and placing it on top of another stack. 3. No disk may be placed on top of a smaller disk. With 3 disks, the Tower of Hanoi puzzle can be solved in 7 moves. The minimum number of moves required to solve a Tower of Hanoi puzzle is given by the formula 2" - 1 where n is the number of disks. For example, if there were 14 disks, the minimum number of moves needed to solve the puzzle would be 214 – 1 = 16,383 moves. There are various approaches to solving the Tower of Hanoi and its related problems, including iterative solutions, recursive solutions, non-recursive solutions, binary and Gray-code solutions, and graphical representations. An iterative solution involves moving the smallest disk one position, then moving the next disk one position. If there is no tower position in the chosen direction, move the disks to the opposite end and continue in the same direction. This method completes the puzzle in the minimum number of moves when there are 3 disks. Recursive solutions involve breaking the puzzle down into a series of sub-problems, each of which can be solved using the same general procedures. The total solution is then found by combining these sub-solutions. Recursion is a technique for iterating over an operation by having a function call itself repeatedly until it arrives at a result. The following figure 1.2 illustrates the concepts in detail. Here, the following steps are performed to get the solution. 1. Move n-1 disks from source to the auxiliary. 2. Move nth disk from source to destination. 3. Move n-1 disks from auxiliary to destination. Non-recursive solutions recognize regularities in the procedures needed to solve the problem. For example, by counting the moves starting at 1, the position of the disk to be moved during move m can be determined by the number of times m can be divided by 2. This indicates that every odd move involves the smallest disk. This recognition allows for the following algorithm: Move the smallest disk to the peg that it has not recently come from. Move another disk legally (there will only be one possibility). There are several other problem-solving strategies that can be adopted in various situations, such as leveraging past experiences, bringing in a facilitator, developing a decision matrix for evaluation, asking peers for help, and stepping away from the problem for a while. ## 1.7 Backtracking Backtracking algorithms are problem-solving strategies that explore various options to find the optimal solution. They operate by testing different paths, and if a path doesn’t lead to a solution, they backtrack and try another route until they find the correct one. It’s similar to solving a puzzle by experimenting with different pieces until they fit together perfectly. Backtracking is a problem-solving algorithmic technique that involves finding a solution incrementally by trying different options and undoing them if they lead to a dead end. It is frequently employed in scenarios where you must consider several options in order to find a solution, such as when figuring out Sudoku puzzles or finding a way around mazes. When an algorithm encounters a dead end, it goes back to the original decision point and continues searching for a different route until a solution is discovered or all options have been considered. A simple real-life example of backtracking is finding the correct PIN for a locked device. Suppose you forget the PIN to unlock your smartphone, and you’re trying to guess it. Here’s how backtracking applies: - Try a combination: You start by entering a possible PIN. - Check if it works: After entering the PIN, the device checks if it’s correct. - If incorrect, backtrack and try another: If the entered PIN is incorrect, you “backtrack” by discarding that attempt and trying a different PIN combination. - Continue until successful or all options are tried: This process continues until you either find the correct PIN and unlock the device or exhaust all possible combinations. In this example, backtracking helps systematically explore each possible PIN combination until the correct one is found. The following example of route map will illustrates the stages of backtracking in detail. In the diagram above, routes from Muvattupuzha to various places are shown. Suppose you have this map and want to reach Aluva. You start by trying the first path: Muvattupuzha -> Perumbavur -> Angamaly. Upon reaching Angamaly, you find it’s a dead end with no further routes. So, you backtrack to the starting point, Muvattupuzha, and try the second path: Muvattupuzha -> Kolenchery –> Ernakulam. However, Ernakulam also turns out to be a dead end. Backtracking again, you finally try the third route: Muvattupuzha -> Kothamangalam -> Perumbavur -> Aluva. This time, you successfully reach your destination, Aluva. # THE PROBLEM SOLVING PROCESS ## 2.1 Introduction Regardless of the area of study, computer science is fundamentally about solving problems with computers. Therefore, it is crucial to first understand the computer’s information processing model. The problems we aim to solve can originate from real-world scenarios or the abstract world. To address these problems effectively, we need a standard systematic approach. The model shown in Figure 2.1 below assumes a single CPU (Central Processing Unit). Many modern computers have multiple CPUs, so you can imagine this model being replicated multiple times within a computer. A typical single CPU computer processes information as shown in the diagram 2.1. Problems are solved by obtaining some kind of user input (e.g., keyboard/mouse information or game control movements), then processing the input and producing some kind of output (e.g., images, text, sound). Sometimes the incoming and outgoing data may also involve hard drives or network devices. ## 2.2 Computer as a Model of Computation Regarding problem-solving, we will apply the model in Figure 2-1 and assume that we are given some input information that we need to work with to produce the desired output as a solution. However, the model is quite simplified. For larger and more complex problems, we need to iterate (i.e., repeat) the input/process/output stages multiple times in sequence, producing intermediate results along the way that solve part of our problem, but not necessarily the whole problem. For simple computations, the simplified model is sufficient. Problem solving is the step-by-step process of looking at information about a situation and coming up with the right solutions. In solving a problem, there are some well-defined steps to be followed. For example, consider how the input/process/output works on a simple problem: **Example:** Calculate the average grade for all students in a class. **Input:** Get all the grades, possibly by typing them in via the keyboard or by reading them from a USB flash drive or hard disk. **Process:** Add them all up and compute the average grade. **Output:** Output the answer to either the monitor, printer, USB flash drive, or hard disk, or a combination of any of these devices. It’s clear that the problem can be easily solved by obtaining input, performing computations, and generating output. Now, let’s delve into the steps involved in problem-solving within the context of the example above. ## 2.3 Understanding the Problem Initial step in solving any problem is ensuring a clear understanding of the problem itself. This involves knowing: 1. What input data/information is available? 2. What does the data/information represent? 3. In what format is the data/information? 4. What is missing in the data provided? 5. Does the person solving the problem have everything needed? 6. What output information needs to be produced? 7. In what format should the result be: text, picture, graph? 8. What are the other requirements needed for computation? In the example provided, we understand that the input consists of grades. However, it’s essential to comprehend the format of these grades. Each grade could be: - A number ranging from 0 to 100. - A letter grade from A to F. If grades are represented as numbers: - They could be whole integers (e.g., 73). - They might also be real numbers (e.g., 73.42). Understanding the specific format of the grades is crucial for accurately solving the problem. We also need to consider how to handle missing grades. For example, if some students were absent during the test and we do not have their grades, should they be included in our average calculation (perhaps as a 0), or should we exclude them entirely from computing the average? Additionally, understanding the desired output format is crucial. Should the output be: - A whole number or a real number representing the average grade? - A letter grade instead of a numerical average? - A visual representation like a pie chart depicting the average grade distribution? The formatting choices for the output depend on the specific requirements and preferences for presenting the results. Finally, it’s crucial to understand the type of processing required for the data. This understanding guides the next step in the problem-solving process. ## 2.4 Formulating a Model The next step is to create a method for solving the problem. This method, or formula, is necessary to calculate the average of a set of numbers. If no existing formula exists, one must be created. To develop a formula, it’s important to fully understand the information provided. Assuming the input consists of integers or real numbers x1,x2, Xn representing grade percentages, the following computational method may be used: ``` Average1 = (x1 + x2 +---- Xn) / n ``` where the result will be a number from 0 to 100. That's quite straightforward, assuming we already know the formula for calculating the average of numerical grades. However, this approach doesn't work when the input data consists of letter grades like B+, C, A+, F, D, etc., because these letters can't be added or divided. This problem-solving step needs to find a method to calculate an average from such letter grades. It requires creative thinking. After considering it, we might choose to assign integer values to the incoming letters as follows: | Grade | value assigned | |-------------|-----------------| | S | 10 | | A+ | 9 | | A | 8 | | B+ | 7 | | B | 6 | | C+ | 5 | | C | 4 | | D+ | 3 | | D | 2 | | P | 1 | | F | 0 | Now, we can calculate the average by taking the mean of the assigned numerical values for each grade. If we assume the newly assigned grade numbers are y1, y2, yn, then the following computational model can be used: ``` Average2 = (y1 + y2 +-- - - yn) / n ``` where the result will be a number between 0 and 10. For the output, if you want a percentage, you can use Average1 directly or use (Average2/10), depending on the original input. If you want a letter grade, you can use (Average1/100 * 10) or Average2 and then use a “lookup table” to find the letter grade for a number from 0 to 10. The main idea in this step of problem-solving is to understand how to use the available data to find the answer. ## 2.5 Developing an Algorithm After understanding the problem and formulating a model, the next step is to develop a precise plan detailing the computer’s expected tasks. An algorithm is a precise sequence of instructions designed to solve a problem. To develop an algorithm, the instructions must be represented in a way that is understandable to someone trying to figure out the steps involved. Developing an algorithm in the context of problem-solving involves a systematic approach. First, you need to thoroughly understand the problem by identifying what is being asked, the inputs required, and the expected outputs. Once the problem is clear, you can begin to plan the algorithm by breaking it down into smaller, manageable steps. This involves outlining the necessary actions and deciding on the best strategy to achieve the desired outcome. After planning, you move on to writing pseudocode, which provides a detailed blueprint for your algorithm. This pseudocode helps in translating the steps into actual code during implementation. Once the algorithm is coded, it must be tested rigorously with various inputs to ensure it functions correctly and efficiently. Two commonly used representations for an algorithm are (1) pseudocode (2) flowcharts. One real life example is shown below in figure 2.2 to get a clear understanding. The scenario involves washing hands. First, turn on the tap and wet your hands. Then, apply soap and scrub your hands for 20 seconds. Afterward, rinse your hands thoroughly and turn off the tap. Finally, dry your hands. Similarly, algorithms can be structured in numerous real-life examples encountered in everyday situations. Following a recipe to cook a meal is a practical example of an algorithm in real life. The process begins with gathering all the necessary ingredients, ensuring everything is on hand before starting. Next, the ingredients are prepared, such as chopping vegetables and measuring spices, to have everything ready for cooking. The cooking instructions are then followed step by step, which might include heating oil, sautéing onions, or other specific techniques. After that, the ingredients are combined in the correct order as specified by the recipe. The dish is then cooked for the designated amount of time to ensure it’s perfectly done. Finally, the meal is served, completing the algorithmic process of cooking. After the implementation and testing phases, it is important to evaluate the algorithm’s performance. This includes analyzing its efficiency and refining it if necessary. Proper documentation should be provided to explain how the algorithm works, including descriptions of the inputs, outputs, and any specific assumptions. Finally, the algorithm should be reviewed, possibly by others, to catch any potential issues and to gather feedback for further improvement. By following this methodical approach, you ensure that the algorithm is well-designed, efficient, and effective in solving the given problem. Consider the following example for solving the problem of washing hands, first as a flowchart and then in pseudocode. ## 2.6 Writing the Program Writing a program involves translating an algorithm or a set of instructions into a language that a computer can execute. This process typically begins with creating pseudocode, a high-level representation of the program that uses plain English to outline the logic and steps required. Pseudocode is beneficial because it allows programmers to plan and visualize the structure of their code before diving into the specific syntax of a programming language. For instance, consider the problem of finding the largest of three numbers. Here’s how the pseudocode and the corresponding Python program might look: The source code can vary depending on the programming language used. Learning a programming language may seem challenging at first, but it becomes easier with practice. The computer requires precise instructions to understand what it is being asked to do. For instance, omitting a semicolon (;) from the code will confuse the computer, as the semicolon signifies the end of an instruction. Leaving one out will cause the program to generate a compile-time error. Compiling is the process of converting a program into machine-readable code. Computers can only understand Os and 1s, known as machine instructions. Therefore, any code we write must be translated into this binary language. The compiler’s duty is to convert high-level languages like C and Python into machine language composed of Os and 1s Additionally, the compiler checks the syntax of the programming language and reports any errors that are found. All compile-time errors must be fixed before running the program. ## 2.7 Testing the Program Running a program involves instructing the computer to execute the compiled code. When the program runs correctly, it should produce the expected output. However, a program might work properly for some input data but fail for others. Incorrect output may indicate that the algorithm was not correctly translated into code or that the initial algorithm did not account for all possible scenarios. Issues like these, where instructions are executed out of order or certain cases are not handled, are referred to as bugs. Bugs are errors with a program that cause it to stop working or produce incorrect or undesirable results. The programmer is responsible for fixing all bugs in a program. To find bugs effectively, test the program with many test cases. This collection of test cases is called a test suite. It is also helpful to have others test the program. They may think of scenarios or input data that the original programmer did not consider. Bugs require debugging to identify and correct the errors. Writing effective and efficient code is an iterative process, often involving multiple cycles of writing, testing, and debugging to ensure that the program handles all possible scenarios correctly. Debugging is the process of finding and fixing errors in program code. Debugging can be a time-consuming task for programmers. However, following set of general strategies should significantly reduce the number of bugs in a program, making debugging much easier. The following steps are fundamental practices in the process of debugging software. Each step involves different techniques and approaches to identify and fix bugs efficiently. 1. Reproducing the Problem: Ensuring that the issue or bug can be consistently reproduced under specific conditions or inputs. 2. Reviewing the Code: Thoroughly examining the code to understand its logic and flow. 3. Using Debugging Tools: Employing tools like debuggers, logging, or breakpoints to identify and trace the source of the bug. ## 2.8 Evaluating the Solution Evaluating the solution is a critical step in the problem-solving process, ensuring that the proposed solution effectively addresses the initial problem or challenge. Once potential solutions have been generated, they must be carefully assessed based on predefined criteria and objectives. This evaluation phase involves analyzing the feasibility, practicality, and effectiveness of each solution. Factors such as cost, time, resources required, and potential impact on stakeholders are considered to determine the most viable option. Additionally, the solution’s ability to meet specific technical requirements or constraints is evaluated to ensure compatibility with existing systems or frameworks. After a thorough evaluation, the selected solution undergoes further scrutiny through testing and validation processes. This step verifies whether the solution performs as expected under different conditions and scenarios. Testing may involve simulations, prototypes, or pilot implementations to gather empirical data and feedback. Stakeholders, including end-users and domain experts, often play a crucial role in providing insights and perspectives during this evaluation phase. Their input helps refine and optimize the solution before final implementation. Ultimately, a well-executed evaluation process ensures that the chosen solution not only solves the initial problem effectively but also aligns with broader organizational goals and strategic objectives. **Evaluating the Solution: A Real-Life Scenario** Imagine you’re tasked with improving the efficiency of a delivery service for a local bakery. The initial problem is that deliveries are often delayed, leading to customer dissatisfaction. To address this, you brainstorm several solutions: optimizing delivery routes, upgrading delivery vehicles, and implementing a new tracking system for orders. 1. **Optimizing Delivery Routes:** You propose using a GPS-based route planning software to minimize travel time and fuel costs. To evaluate this solution, you consider factors like the cost of the software, training for drivers, and potential savings in fuel and time. You also assess whether the new routes can handle peak delivery times and accommodate changes in customer orders. 2. **Upgrading Delivery Vehicles:** Another solution is to invest in electric vehicles that are eco-friendly and potentially more reliable. You evaluate the cost of purchasing and maintaining electric vehicles compared to conventional ones. Additionally, you assess their range, charging infrastructure availability, and the impact on delivery times and customer satisfaction. 3. **Implementing a New Tracking System:** A third solution involves introducing a customer-facing tracking system where customers can monitor their order status in real-time. You evaluate the cost of developing the system, integrating it with existing platforms, and training staff and customers to use it effectively. The solution’s potential to reduce customer inquiries and improve transparency in delivery times is also considered. After evaluating these solutions, you might decide to pilot test the route optimization software due to its immediate cost-effectiveness and potential to streamline operations. This real-life scenario illustrates how evaluating solutions involves weighing various factors to determine the most effective approach to solving a specific problem while considering practical constraints and potential benefits. This chapter introduces the problem-solving process in computer programming, beginning with the concept of the computer as a model of computation, which underscores its role in solving complex problems. It then emphasizes the importance of thoroughly understanding the problem at hand before moving on to formulating a model that represents the problem abstractly. The chapter details the development of an algorithm as a crucial step in outlining a structured approach to the solution. Following this, it covers the translation of the algorithm into a functional program through coding. The process continues with testing the program to identify and correct errors, ensuring the solution works as intended. Finally, the chapter concludes with evaluating the solution’s effectiveness, considering potential optimizations to enhance performance and efficiency.