Page 410 - computer science (868) class 11
P. 410

Problem 2: Accept any number and check if it is an even number or odd.

              Algorithm:
              Step 1:  Start.

              Step 2:  Accept any number in num.
              Step 3:  If num % 2=0 then go to Step 4, else go to Step 5.
              Step 4:  Display num “is even”, go to Step 6.

              Step 5:  Display num “is odd”.
              Step 6:  Stop.

              Pseudocode:
              Begin
                   Read num
                   If num%2 = 0

                       Display “Even number”
                   Else
                      Display “Odd number”
                   Endif
              End

              Flowchart:
                                                  Start




                                               Accept num




                                                                  No
                                               Is num%2=0                 Display “Odd”

                                                     Yes

                                              Display “Even”




                                                  Stop


                   13.3 COMPUTATIONAL COMPLEXITY AND BIG O NOTATION
              This topic will be covered in detail in the class XII book. In this section, an introductory concept is given to analyse an algorithm.

              We know that there are multiple ways of deriving a solution to a problem. So, the same problem may have different
              algorithms, all giving the correct output. Thus, all the algorithms are effective. However, an efficient algorithm is one
              that produces the correct output in minimum time and utilises less memory space.

              We can thus conclude that for the same size of input, an algorithm that performs the task in the smallest number of
              operations is considered the most efficient one. Besides this, the efficiency of an algorithm depends on the following
              two factors:



                408408  Touchpad Computer Science-XI
   405   406   407   408   409   410   411   412   413   414   415