Page 121 - Computer science 868 Class 12
P. 121

11.  Write an algorithm to accept a word in upper case and check whether it is a unique word or not. A unique word is a word which
                       has no repeating alphabets like SUN, LIGHT, RAY, PROTEIN,  WATER, etc.
                   Ans.  Step 1:  Start.
                        Step 2:  Accept the word in variable word.
                        Step 3:  Initialise i to 65.
                        Step 4:   Repeat Step 5  to Step 10 while i<=90.
                        Step 5:  Initialise count and j to 0.
                        Step 6:  Repeat Step 7 to Step 9 while j<wordlength.
                        Step 7:  Extract character ch from index j.
                        Step 8:  If ch=(char)i then increment the count by 1.
                        Step 9:  Increment j by 1.
                        Step 10: Increment i by 1.
                        Step 11: If count=length of word, then Go to Step 12, else Go to Step 13.
                        Step 12: Display the word “is a unique word”, Go to Step 14.
                        Step 13: Display the word “is not a unique word”.
                        Step 14: Stop.
                    12.  Write an algorithm to print the sum of the elements of a linked list.
                   Ans.  Step 1:   Start.
                       Step 2:   Initialise node ptr = start and sum = 0.
                       Step 3:   Repeat Steps 4 and 5 while ptr != null.
                       Step 4:   Add ptr → data to sum.
                       Step 5:   Set ptr as ptr → link.
                       Step 6:   Display sum.
                       Step 7:   Stop.
                    13.  Write an algorithm to delete a node in position ‘p’ of a linked list where p is not the first or last node.
                   Ans.  Step 1:  Start.
                        Step 2:  Initialise node prev = start, pres=start and c=1.
                        Step 3:  Repeat Steps 4 and 5 while c<=p.
                        Step 4:  If c=p, then Go to Step 5, else Go to Step 7.
                        Step 5:  Set prev → link = pres → link.
                        Step 6:  Set pres → link=null, Go to Step 10.
                        Step 7:  Set pres=prev.
                        Step 8:  Set pres=pres → link.
                        Step 9:  Increase c by 1.
                        Step 10: Stop.
                 D.  Assertion and Reasoning Based Question.
                    Assertion: Flowchart is a pictorial representation of an algorithm using standard symbols.
                    Reason:  There are several symbols in a flowchart namely the start/stop box, input/output box, processing box, decision box, flow
                           lines, connectors, etc.
                    (a)  Both Assertion and Reason are true, and Reason is the correct explanation for Assertion.
                    (b)  Both Assertion and Reason are true, but Reason is not the correct explanation for Assertion.
                    (c)  Assertion is true and Reason is false.
                    (d)  Assertion is false and Reason is true.
                   Ans.  A flowchart is a pictorial representation of an algorithm using standard symbols. In a flowchart, each step is represented using
                       symbols.









                                                                                                                       119
                                                                            Implementation of Algorithms to Solve Problems  119
   116   117   118   119   120   121   122   123   124   125   126