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

Problem 17: Write an algorithm to delete any word from a sentence.
                 Step 1:  Start.
                 Step 2:  Accept sentence in variable sen and delete word in del_word.

                 Step 3:  Add space at the end of sen.
                 Step 4:  Initialise variables word and new_sentence to null.
                 Step 5:  Initialise length as sentence_length.

                 Step 6:  Initialise i to 0.
                 Step 7:  Repeat Step 8 to Step 14 while i < length.
                 Step 8:  Extract each character in ch.
                 Step 9:  If ch is equal to space then go to Step 10 else go to Step 13.

                 Step 10: If word = del_word then go to Step 12.
                 Step 11: Add word to new_sentence and then add space to new_sentence.
                 Step 12: Initialise word to null, go to Step 14.

                 Step 13: Add ch to word.
                 Step 14: Increment i by 1.
                 Step 15: Display new_sentence.
                 Step 16: Stop.


                 13.5.7 Recursive Algorithms
                                                                           b
                 Problem 18: Write a recursive algorithm to find power(a, b) or a .
                 Step 1:  Start.
                 Step 2:  Accept a and b
                 Step 3:  If b = 1 then return 1, else go to Step 3.

                 Step 4:  Return a x power(a, b-1).
                 Step 5:  Stop.
                 Problem 19: Write a recursive algorithm to find the sum of the digits of a number sumofdigit(num).

                 Step 1:  Start.
                 Step 2:  If num = 0 then return 0, else go to Step 3.
                 Step 3:  Return num % 10 + sumofdigit(num/10).
                 Step 4:  Stop.



                                Let’s Revisit


                       ♦ An algorithm is a set of well-defined finite steps or rules to be followed to solve any problem.

                       ♦ Pseudocode is a representation of an algorithm in any standard human readable language and mathematical notations.
                       ♦ Flowchart is a pictorial representation of an algorithm using standard symbols.
                       ♦ Big O notation is the measurement of growth rate of an algorithm with increase in its input size.
                       ♦ A good algorithm should have various properties like accuracy, finiteness, input, output, language independence, and
                      effectiveness.



                                                                                                                       417
                                                                            Implementation of Algorithms to Solve Problems  417
   414   415   416   417   418   419   420   421   422   423   424