| 1. |
Explain the Basic Building Blocks of Algorithms. |
|
Answer» Data: Algorithms take input data, process the data, and produce output data. Computers provide instructions to perform operations on data. For example, there are instructions for doing arithmetic operations on numbers, such as add, subtract, multiply and divide. There are different kinds of data such as numbers and text. Variables: Variables are named boxes for storing data. When we do operations on data, We need to store the results in variables. The data stored in a variable is also known as the value of the variable. We can store a value in a variable or change the value of variable, using an assignment statement. Control flow: An algorithm is a sequence of statements. However, after executing a statement, the next statement executed need not be the next statement in the algorithm. The statement to be executed next may depend on the state of the process. Thus, the order in which the statements are executed may differ from the order in which they are written in the algorithm. This order of execution of statements is known as the control flow. There are three important control flow statements to alter the control flow depending on the state. 1. In sequential control flow, a sequence of statements are executed one after another in the same order as they are written. 2. In alternative control flow, a condition of the state is tested, and if the condition is true, one statement is executed; if the condition is false, an alternative statement is executed. 3. In iterative control flow, a condition of the state is tested, and if the condition is true, a statement is executed. The two steps of testing the condition and executing the statement are repeated until the condition becomes false. Functions: The parts of an algorithm are known as functions. A function is like a sub algorithm. It takes an input, and produces an output, satisfying a desired input output relation. |
|