Page 119 - Computer science 868 Class 12
P. 119

3.  An algorithm ………………… the cost of design.
                    4.  ………………… notation is the measurement of the growth rate of an algorithm.
                    5.  In ………………… case complexity, the function takes the maximum time or the maximum number of steps required for execution.

                   Answers
                      1.  Pseudocode   2.  FIFO   3.  reduces     4.  Big O       5.  worst

                 C.  Answer the following questions:
                    1.  Differentiate between algorithm and flowchart.
                   Ans.                  Algorithm                                    Flowchart

                       a.  Algorithms are represented in human language.  a.  Flowcharts are represented in symbols.
                       b.  There are no specific rules for writing an algorithm.  b.  In flowchart, the symbols represent specific instruction.

                    2.  Differentiate between algorithm and pseudocode.
                   Ans.                  Algorithm                                   Pseudocode

                       a. It is a step-wise representation to solve a problem.  a.  It is a method of developing an algorithm.
                       b. It uses human language to design the steps.  b.  It is a simpler  version  of coding in  a programming
                                                                       language.

                    3.  Write two characteristics of a good algorithm.
                   Ans.  a.  Accuracy: A good algorithm must provide the correct solution to a given problem in an unambiguous manner.
                        b.  Finiteness: A good algorithm must produce the correct output after a finite number of steps and terminate after that.
                    4.  Write two advantages of an algorithm.
                   Ans.  a.  Every step in an algorithm follows a logical sequence, so it helps in program development and debugging.
                        b.  The algorithm provides a proper understanding of the input requirement, output and flow of the process.
                    5.  Write two disadvantages of an algorithm.
                   Ans.  a.  Developing an algorithm is a time-consuming process.
                        b.  Complex algorithms are very difficult to design and understand.
                    6.  Write an algorithm to print the lowest common multiple of two numbers.
                   Ans.  Step 1:   Start.
                       Step 2:   Initialise variables lcm and i to 1.
                       Step 3:   Input two numbers num1 and num2.
                       Step 4:   Repeat Step 5 to Step 6 while i<=num1 × num2.
                       Step 5:   If lcm% num1=0 && lcm % num2 =0 then assign lcm=i, go to Step 7.
                       Step 6:   Increment variable lcm by 1.
                       Step 7:   Print lcm.
                       Step 8:   Stop.
                    7.  Write an algorithm to check if a number is a deficient number or not. A deficient number is a number that is less than the sum
                       of its factors excluding itself.
                        For example, all prime numbers are deficient numbers.
                   Ans.  Step 1:   Start.
                       Step 2:   Initialise variable sum to 0.
                       Step 3:  Accept number num.
                       Step 4:   Repeat Step 5 to Step 7 while i<num.
                       Step 5:  If num is divisible by i then Go to Step 6, else go to Step 8.
                       Step 6:  Add i to the sum.
                       Step 7:  Increment i by 1.


                                                                                                                       117
                                                                            Implementation of Algorithms to Solve Problems  117
   114   115   116   117   118   119   120   121   122   123   124