Page 437 - Cs_withBlue_J_C11_Flipbook
P. 437

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


                     14.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:



                                                                                                                       435
                                                                            Implementation of Algorithms to Solve Problems  435
   432   433   434   435   436   437   438   439   440   441   442