



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




An algorithm is a set of instructions, sometimes called a procedure or a function that is used to perform a certain task. This can be a simple process, such as adding two numbers together, or a complex function, such as adding effects to an image. For example, in order to sharpen a digital photo, the algorithm would need to process each pixel in the image and determine which ones to change and how much to change them in order to make the image look sharper. Most computer programmers spend a large percentage of their time creating algorithms. (The rest of their time is spent debugging the algorithms that don’t work properly.) The goal is to create efficient algorithms that do not waste more computer resources (such as RAM and CPU time) than necessary. This can be difficult, because an algorithm that performs well on one set of data may perform poorly on other data. As you might guess, poorly written algorithms can cause programs to run slowly and even crash. Therefore, software updates are often introduced, touting “improved stability and performance”. While this sounds impressive, it also means that the algorithms in the previous versions of the software were not written as well as they could have been. 3.1.1 Operation of algorithm An algorithm generally takes some input, carries out a number of effective steps in a finite Given a list of numbers, you can easily order them from largest to smallest with the simple instruction “Sort these numbers.” A computer, however, needs more detail to sort numbers. It must be told to search for the smallest number, how to find the smallest number, how to compare numbers together, etc. The operation “Sort these numbers” is ambiguous to a computer because the computer has no basic operations for sorting. Basic operations used for writing algorithms are known as primitive operations or primitives. When an algorithm is written in computer primitives, then the algorithm is unambiguous and the computer can execute it. 3.1.2 Algorithms produce a result In our simple definition of an algorithm, we stated that an algorithm is a set of instructions for solving a problem. Unless an algorithm produces some result, we can never be certain whether our solution is correct. Have you ever given a command to a computer and discovered that nothing changed? What was your response? You probably thought that the computer was
malfunctioning because your command did not produce any type of result. Without some visible change, you have no way of determining the effect of your command. The same is true with algorithms. Only algorithms which produce results can be verified as either right or wrong.
A flow chart, or flow diagram, is a graphical representation of a process or system that details the sequencing of steps required to create output. A typical flow chart uses a set of basic symbols to represent various functions, and shows the sequence and interconnection of functions with lines and arrows. Flow charts can be used to document virtually any type of business system, from the movement of materials through machinery in a manufacturing operation to the flow of applicant information through the hiring process in a human resources department. Each flow chart is concerned with one particular process or system. It begins with the input of data or materials into the system and traces all the procedures needed to convert the input into its final output form. Specialized flow chart symbols show the processes that take place, the actions that are performed in each step, and the relationship between various steps. Flow charts can include different levels of detail as needed, from a highlevel overview of an entire system to a detailed diagram of one component process within a larger system. In any case, the flow chart shows the overall structure of the process or system, traces the flow of information and work through it, and highlights key processing and decision points. Flow charts are an important tool for the improvement of processes. By providing a graphical representation, they help project teams to identify the different elements of a process and understand the interrelationships among the various steps. Flow charts may also be used to gather information and data about a process as an aid to decisionmaking or performance evaluation. For example, the owner of a small advertising agency who hopes to reduce the time involved in creating a print ad might be able to use a flow chart of the process to identify and eliminate unnecessary steps. Though flow charts are relatively old design tools, they remain popular among computer programmers working on systems analysis and design. In recent years, many software programs have been developed to assist businesspeople in creating flow charts. 3.2.1 Constructing Flowcharts Flow charts typically utilize specialized symbols. Some of the main symbols that are used to construct flow charts include:
Example 1: Write an algorithm and draw a flow chart to calculate 2^4. Algorithm: Step 1: Input Base (2), Power (4) Step 2: Product= Base Step 3: Product = Product * Base Step 4: Product = Product * Base Step 5: Product = Product * Base Step 6: Print Product Flowchart: Example 2: Write an algorithm and draw a flow chart to calculate 2^4 using a loop approach? Algorithm: Step 1: Input Base (2), Power (4) Step 2: Product = Base Step 3: Counter = 1 Step 4: While (Counter < Power) Repeat steps 4 through 6 Question: What happens if you want to calculate 2 to the power of 1000 (2^1000 )? Answer: Use a LOOP (repeated execution of the same set of instructions)
Step 5: Product = Product * Base Step 6: Counter = Counter + 1 Step 7: Print Product Flowchart: Example 3: Write an algorithm and draw the flowchart to find the average of two numbers. Algorithm: Steps 1: Input x, Input y Steps 2: Sum = x + y Steps 3: Average = Sum / Steps 4: Print Average Flowchart: START Input x Input y Sum = x + y Average = sum/ Print Average STOP
Step 6: Counter = Counter + 1 Step 7: Print (N, Factor)