Docsity

Techniques for Computational Problem Solving, Lecture notes of Computer Science

Partial preview of the text

Download Techniques for Computational Problem Solving and more Lecture notes Computer Science in PDF only on Docsity!

COS 102 TERM PAPER

Methods of Solving Computing Problems

and

Solvable and Unsolvable Problems

Department of Computer Science

University of Nigeria, Nsukka

Course: COS 102: Introduction to Problem Solving

EZISI EMMANUEL CHIBUIKE

Introduction Computer science, at its core, is the study of problems, the processes needed to solve them, and the systematic methods used to represent those processes so that a machine can carry them out. Before any code is written, a problem must first be understood, planned for, and expressed in a form a computer can follow. This term paper examines two closely related themes in this area of study. Part One: Methods of Solving Computing Problems 1.1 What Is a Computing Problem? A computing problem is any task that can be expressed in terms of inputs, a required process, and a desired output. Examples range from simple tasks, such as finding the average of a set of numbers, to complex ones, such as scheduling flights or securing a network. Solving such a problem with a computer is not just about writing code; it is a structured process that moves from understanding the problem to producing a working, tested solution. 1.2 Stages of Problem Solving Computing problems are generally solved by moving through the following stages:

  1. Problem definition/identification: This imply clearly stating what the problem is, what the input is, and what output is expected.
  2. Analysis: Breaking the problem into smaller, manageable parts and identifying any constraints.
  3. Design of a solution: Planning the logic of the solution using tools such as algorithms, pseudocode, or flowcharts, before any code is written.
  4. Implementation (coding): Translating the designed solution into an actual programming language.
  5. Testing and debugging: Running the program with different inputs, including edge cases, to confirm it produces correct results and fixing any errors found.
  6. Documentation and maintenance: Recording how the solution works and updating it as needed over time. The three most commonly taught design tools for the third stage are: algorithms, pseudocode, and flowcharts. These are the main focus of this section, since they form the bridge between understanding a problem and actually coding it. 1.3 Algorithms An algorithm is a finite, step-by-step, and unambiguous set of instructions designed to solve a specific problem or accomplish a defined task. It is usually written in plain, English-like language rather than any programming syntax. A good algorithm has several defining characteristics:
  • Diamond: Represents a decision point, where the flow branches based on a condition (e.g., Yes/No).
  • Arrow: Shows the direction of flow from one step to the next. Flowcharts are particularly useful for visualising the logic of a solution, especially where there are many decision points or repeated (looping) steps, and they make it easier to communicate a solution to others, including non-programmers. 1.6 Comparing Algorithms, Pseudocode, and Flowcharts Feature Algorithm Pseudocode Flowchart Form Natural (English-like) language Mix of natural language and code- like structures Graphical, using standard symbols Closeness to code Least close Closer to actual code Not code-like; purely visual Best for Quickly stating overall logic Detailed planning before coding Visualising flow and decision points Ease of translation to code Moderate High Moderate 1.7 General Problem-Solving Strategies (Algorithm Design Techniques) Beyond the basic representation tools above, computer scientists also rely on broader strategies for designing the logic of a solution itself. Common ones include:
  • Brute force: Trying all possible solutions systematically and picking the best or correct one.
  • Divide and conquer: Breaking a large problem into smaller sub-problems, solving each independently, and combining their results (e.g., Merge Sort).
  • Greedy method: Making the locally best choice at each step in the hope of reaching a good overall solution (e.g., Dijkstra's shortest path algorithm).
  • Backtracking: Building a solution incrementally and abandoning ('backtracking' from) a path as soon as it is determined that it cannot lead to a valid solution. 1.8 Summary of Part One Solving a computing problem is a structured process, not a single leap from idea to code. Algorithms, pseudocode, and flowcharts each play a complementary role in planning a solution: the algorithm captures the overall logic in plain language, the pseudocode refines that logic into something closer to real code, and the flowchart presents it visually for easier verification and communication. Used together, they reduce errors, save debugging time, and make it easier to translate a plan into a working program in any language.

Part Two: Solvable and Unsolvable Problems 2.1 Introduction to Solvability Not every problem that can be stated can actually be solved by a computer. This is one of the most important discoveries in the theory of computation, established in the 1930s independently by Alonzo Church (using lambda calculus) and Alan Turing (using the concept of the Turing machine). Their work showed that there are precise, well-defined problems for which no algorithm can ever exist โ€” not because of a lack of computing power, but because of a fundamental logical limitation. 2.2 Decidable (Solvable) Problems A problem is said to be decidable, or solvable, if there exists an algorithm that can correctly answer the problem, typically with a definite 'yes' or 'no', for every possible input, and is guaranteed to stop (halt) in a finite amount of time. In terms of a Turing machine, a problem is decidable if there is a Turing machine that halts on every input and gives the correct accept/reject answer. Example: 'Is a given number even?' is decidable, because a simple algorithm (checking whether the number is divisible by two) will always terminate with a correct yes or no answer for any number given to it. 2.3 Undecidable (Unsolvable) Problems A problem is undecidable, or unsolvable, if no algorithm exists that can correctly solve it for all possible inputs. This does not mean the problem is merely hard, or that today's computers are too slow. It means that no computer, however fast or powerful, will ever be built that can solve every instance of that problem correctly. 2.4 The Halting Problem The most famous example of an unsolvable problem is the Halting Problem, proven by Alan Turing in 1936. It asks: given an arbitrary computer program P and an input x, can we determine, in general, whether P will eventually stop running (halt) or continue running forever (loop indefinitely)? Turing proved that no general algorithm can exist that solves this problem for every possible program and input. The proof works by contradiction: 14.Assume, for contradiction, that a program called HALTS(P, x) exists, which correctly reports 'yes' if program P halts on input x, and 'no' otherwise. 15.Construct a new program, call it TROUBLE, that takes a program P as its input, calls HALTS(P, P) to check whether P halts when given itself as input, and then does the opposite of the answer: if HALTS says P halts, TROUBLE loops forever; if HALTS says P does not halt, TROUBLE halts immediately. 16.Now ask what happens when TROUBLE is given itself as input, i.e., run TROUBLE(TROUBLE).

Conclusion Taken together, the two themes of this paper describe the practical and theoretical boundaries of computing. Methods such as algorithms, pseudocode, and flowcharts give programmers a disciplined way to design correct, working solutions to problems that can be solved. The theory of decidability, illustrated most vividly by the unsolvability of the Halting Problem, reminds us that not every problem can be solved by a computer at all, regardless of how well it is designed or planned for. Understanding both how to solve solvable problems well, and why some problems can never be solved is essential to a proper foundation in computer science.

References

Britannica. (n.d.). Halting problem. Encyclopaedia Britannica. Retrieved from https://www.britannica.com/technology/halting-problem GeeksforGeeks. (2024). Decidable and undecidable problems in theory of computation. Retrieved from https://www.geeksforgeeks.org/theory-of- computation/decidable-and-undecidable-problems-in-theory-of-computation/ Njoroge, D. Algorithmic problem solving: Using pseudo-codes and flowcharts to represent algorithms. Engineering LibreTexts. Retrieved from https://eng.libretexts.org/ Old Dominion University. Unsolvable problems. Retrieved from https://www.cs.odu.edu/~toida/nerzic/390teched/computability/unsolv-1.html Turing, A. M. (1936/1937). On computable numbers, with an application to the Entscheidungsproblem. Proceedings of the London Mathematical Society, Series 2, Volume 42, pp. 230โ€“265. Codecademy. Pseudocode and flowchart: A complete beginner's guide. Retrieved from https://www.codecademy.com/article/pseudocode-and-flowchart-complete- beginners-guide