Dr. Elfeky.pdf
Document Details
Uploaded by EntrancedAmaranth3409
Related
- PCSII Depression/Anxiety/Strong Emotions 2024 Document
- A Concise History of the World: A New World of Connections (1500-1800)
- Human Bio Test PDF
- Vertebrate Pest Management PDF
- Lg 5 International Environmental Laws, Treaties, Protocols, and Conventions
- Fármacos Anticoncepcionais e Disfunção Erétil PDF
Full Transcript
# Intelligence and Problem Solving ## 1.1 Introduction Intelligence is one of the key characteristics which differentiate a human being from other living creatures on the earth. Basic intelligence covers day-to-day problem-solving and making strategies to handle different situations that constantl...
# Intelligence and Problem Solving ## 1.1 Introduction Intelligence is one of the key characteristics which differentiate a human being from other living creatures on the earth. Basic intelligence covers day-to-day problem-solving and making strategies to handle different situations that constantly arise in day-to-day life. For example, one person goes to the Bank to withdraw money. After knowing the balance in their account, they decide to withdraw the entire amount. However, they need to leave a minimum balance in their account. Here, deciding how much to withdraw is an example of basic intelligence. During the process of solving any problem, one tries to find the necessary steps to be taken sequentially. In this Unit, you will develop your understanding of problem-solving and approaches. ## 1.2 Problem Solving Can you think of a day in your life that doesn't involve problem-solving? The answer, of course, is no. In our lives, we are bound to solve problems. Our daily activities such as purchasing something from a general store, making payments, depositing fees in school, or withdrawing money from a bank account all involve some form of problem-solving. It can be said that whatever activity a human being or machine does to achieve a specified objective comes under problem-solving. To make this clearer, here are some other examples: ## 1.3 Algorithm An algorithm can be defined as: *a sequence of activities to be processed for getting desired output from a given input.* Webopedia defines an algorithm as: *a formula or set of steps for solving a particular problem.* To be considered an algorithm, a set of rules must be unambiguous and have a clear stopping point. There may be more than one way to solve a problem, so there may be more than one algorithm for a problem. Now, taking the definition of an algorithm as *a sequence of activities to be processed for getting desired output from a given input.* We can say that: 1. Getting specified output is essential after the algorithm is executed. 2. One will get output only if the algorithm stops after a finite time. 3. Activities in an algorithm must be clearly defined so that they are unambiguous. Before writing an algorithm for a problem, you need to identify the inputs and the expected output after running the algorithm. Consider these exercises for learning to develop an algorithm for some simple problems: - '**+**' for Addition - '**-**' for Subtraction - '**\***' for Multiplication - '**/**' for Division and - '**arrow**' for assignment (for example, A **arrow** X\*3 means A will have a value of X\*3) ### 1.3.1 Example of Algorithm **Problem 1:** Find the area of a circle of radius r. **Input to the algorithm:** Radius r of the Circle **Algorithm:** 1. Read/Input the Radius r of the Circle. 2. Area **arrow** Pi\*r\*r // calculation of area. 3. Print Area. ### 1.3.2 Property of Algorithm Donald Ervin Knuth has identified five necessary properties for algorithms: 1. **Finiteness:** An algorithm must always terminate after a finite number of steps. This means that after every step, it gets closer to the solution of the problem until after a finite number of steps, the algorithm reaches an end point. 2. **Definiteness:** Each step of an algorithm must be precisely defined. This is done using well-thought-out actions to be performed at each step of the algorithm. Also, the actions are defined unambiguously for each activity within the algorithm. 3. **Input:** Any operation you perform needs some beginning value/quantities associated with different activities within the operations. So, the values/quantities are provided to the algorithm before it begins. 4. **Output:** One expects output/results, (expected values/quantities) in terms of output from an algorithm. The results may be obtained at different stages of the algorithm. However, a result obtained from an intermediate stage of the operation is known as an intermediate result and the result obtained at the end of the algorithm is known as the end result. The expected values/quantities always have a specified relation to the inputs. 5. **Effectiveness:** Algorithms to be developed/written using basic operations. Actually, operations should be basic, so that a person, even using paper and pencil only, can perform them exactly and in a finite amount of time. ## 1.4 Flowchart A flowchart is a diagram that visually presents the flow of data through processing systems. By viewing a flowchart, you can understand the operations performed, and the sequence of those operations in a system. Algorithms are essentially a sequence of steps for solving problems. Therefore, a flowchart can be used to represent an algorithm. A flowchart describes the operations involved in a specific sequence, which are required to solve a problem. Think of a flowchart as a blueprint for a design, which you have made for solving a problem. For example, if you are going on a picnic with your friends, you plan for the activities that you will be doing there. If you have a plan, you know exactly when you will do each activity. Similarly, when you need to write a computer program to solve a problem, drawing a flowchart before you start coding can be helpful. A flowchart is sketched according to defined rules. ### 1.4.1 Flowchart symbols There are six basic symbols commonly used when flowcharting assembly-language programs: terminal, process, input/output, decision, connector, and predefined process. This is not a complete list of all the possible flowcharting symbols, but they are the ones most often used in assembly-language programming. | Symbol | Name | Function | |---|---|---| | | Process | Indicates any type of internal operation inside the Processor or Memory. | | | Input/Output | Used for any Input/Output (I/O) operation. Indicates that the computer is to obtain data or output results. | | | Decision | Used to ask a question that can be answered in a binary format (Yes/No, True/False). | | | Connector | Allows the flowchart to be drawn without intersecting lines or without a reverse flow. | | | Predefined Process | Used to invoke a subroutine or an interrupt program. | ### 1.4.2 General rules for flowcharting 1. All boxes within a flowchart are connected using arrows, not lines. 2. Each flowchart symbol has an entry point at the top of the symbol and no other entry points. The exit point for all flowchart symbols is at the bottom except for the decision symbol. 3. The decision symbol has two exit points. These can be on the sides or on one side and the bottom. 4. Generally, a flowchart flows from top to bottom. However, an upward flow can be included as long as it does not exceed three symbols. 5. Connectors are used to connect breaks in the flowchart. Here are some examples: * From one page to another page. * From the bottom of a page to the top of the same page. * An upward flow of more than three symbols. 6. Subroutines and interrupt programs have their own and independent flowcharts. 7. All flowcharts begin with a terminal or predefined process (for interrupt programs or subroutines) symbol. 8. All flowcharts end with a terminal or a contentious loop. Flowcharting uses symbols that have been in use for a number of years to represent the type of operations and/or processes being performed. The standardized format provides a common method for people to visualize problems together in the same manner. The use of standardized symbols makes flowcharts easier to create, but standardizing symbols is not as important as the sequence of activities that make up the process. ### 1.4.4 Some examples of flowcharts Here are some examples of flowcharts. These examples will help you to understand the flowcharting technique. This will help you in the program development process in the next unit of this block. **Problem 1:** Find the area of a circle of radius r. [Insert flowchart for problem 1] **Problem 2:** Convert temperature Fahrenheit to Celsius. [Insert flowchart for problem 2] **Problem 3:** Flowchart for an algorithm which gets two numbers and prints the sum of their values. [Insert flowchart for problem 3] **Problem 4:** Design an algorithm with a natural number, n, as its input which calculates the following formula and writes the result in the standard output. ``` S=1½+1/4+...+1/n ``` [Insert flowchart for problem 4] **Problem 5:** Algorithm for finding the greater number between two numbers. [Insert flowchart for problem 5] **Problem 6:** Flowchart for the problem of printing even numbers between 9 and 100. [Insert flowchart for problem 6] **Problem 7:** Flowchart for the problem of printing odd numbers less than a given number. It should also calculate their sum and count. [Insert flowchart for problem 7] **Problem 8:** Flowchart for calculating the average of 25 exam scores. [Insert flowchart for problem 8] ### I-4.5 Advantages of using flowcharts As we have discussed, flowcharts are used for visually representing algorithms. This pictorial representation of a solution/system has many advantages: * **Clear visual representation:** Flowcharts provide a visual representation of the algorithm, helping to understand the flow of logic and making it easier to grasp complex algorithms, especially when the algorithm involves several steps or a complex control flow. * **Documentation:** Flowcharts serve as documentation for the program, making it easier to understand and maintain the code. * **Communication tool:** Flowcharts are excellent tools for communicating the logic of a program to other developers, stakeholders, or clients. * **Problem-solving aid:** Flowcharts can help identify potential problems or bottlenecks in the logic of a program before it is implemented, saving time and effort during the debugging process. * **Efficiency:** They can help in simplifying code development by breaking complex tasks into smaller, manageable steps.