Monday , 16 January 2017
Home » Class 12 » Advice on How to write Algorithm in ISC Computer Practical

Advice on How to write Algorithm in ISC Computer Practical

I have been getting many queries requesting me to upload tutorials on how to write algorithms for a program in the ISC Computer Science Practical Examination.

Teaching how to write algorithms by writing an article on it is not that effective, but I decided to put down algorithms of two different programs which would serve as examples on how you should proceed with writing algorithms of your program.

Note: There are various ways in which you can write algorithms. I am putting down the easiest form of writing algorithm. This style is completely acceptable in ISC Computer Science Practical Examination and really easy to understand. All you need to do in order to understand the algorithms and write them, is by having in front of yourself, the program whose algorithm is given below. Go through the program and the algorithm and you will get an idea on how to write algorithms.

After all, writing algorithms isn’t a mammoth task as we see it to be. They are just logical steps written in order in an easy to understand language which when put together in a programming language will result in the solution.

Also Note: Before writing your program in your answer sheet, you need to write the algorithm for it. Now what I would suggest you to do is, when you get your answer sheet, solve the program you have selected using pencil at the end of your paper (last 2-3 pages). Write “Rough” above the pages.

Once you are done with writing the program in pencil, begin writing your answers in fair from the front page. Begin by writing the algorithm by seeing the rough program you wrote at the back.

Then Write the program in fair using pen, just after your algorithm. Then erase what you wrote in pencil at the last pages of your answer sheet.

I know you have to write the program twice but it has its own advantages like:

1) You can easily write the algorithm by seeing the program
2) Your final program in fair will be neat as you will just be copying it from the back pages.
3) If you started a program with pencil and after 10 minutes you realize that you should choose other program, you can do so as you haven’t written anything in pen yet.

Example 1:

Example of Algorithm of a program which contains only main() method

First see this program: http://www.guideforschool.com/1260759-java-program-to-print-circular-spiral-matrix/

Step 1   :               Start of algotithm

Step 2   :               Input the size of circular matrix and store it in integer variable ‘n’

Step 3   :               Create an integer square array of size ‘n*n’ which will be the circular matrix

Step 4   :               Declare and initialize variables k = 0 (for filling the matrix), c1 = 0 (for storing index of first column), c2 = n-1 (for storing index of last column), r1 = 0 (for storing index of first row), r2 = n-1 (for storing index of last row)

Step 5   :               Start a while loop till k<=n*n and repeat steps 6 to 10

Step 6   :

(a)          Start a for loop from i = c1 to c2, where ‘i’ increases by 1 every time and perform step (b)
(b)          Store the natural numbers in the first row using A[r1][i] = k++

Step 7   :

(a)          Start a for loop from j = r1+1 to r2, where ‘j’ increases by 1 every time and perform step (b)
(b)          Store the natural numbers in the last column using A[j][c2] = k++

Step 8   :

(a)          Start a for loop from i = c2-1 to c1, where ‘i’ decreases by 1 every time and perform step (b)

(b)          Store the natural numbers in the last row using A[r2][i] = k++

Step 9   :

(a)          Start a for loop from j = r2-1 to r1+1, where ‘j’ decreases by 1 every time and perform step (b)

(b)          Store the natural numbers in the first column using A[j][c1] = k++

Step 10 :               Update the variables c1, c2, r1 and r2

Step 11 :               Display the circular matrix A[ ]

Step 12 :               End of Algorithm

Example 2:

Example of Algorithm of a program which contains other methods along with the main() method

First see this program: http://www.guideforschool.com/358-isc-2013-question-3-practical-paper-solved/

Note: In such cases, start with first writing the algorithm for the main() method and then the algorithm for the other methods.

Algorithm for main() method :

Step 1   :               Start of algotithm

Step 2   :               Input the sentence and store it in a String variable ‘s’

Step 3   :               Convert the sentence into upper case

Step 4   :               Create a StringTokenizer object ‘str’ to extract tokens (words) from the sentence using space and other the punctuation marks namely ‘.’, ‘?’, ‘!’

Step 5   :               Count the number of tokens (words) and store it in an integer variable ‘c’. Also create a String array word[ ] of size ‘c’

Step 6   :               Start a for loop from i = 0 to less than ‘c’ and store the tokens of the sentence into the word [ ] array

Step 7   :               Declare an integer variable ‘count’ and initialize it with 0

Step 8   :               Start a for loop from i = 0 to less than ‘c’ and repeat step 9

Step 9   :               Call the function isPalin() as : ob.isPalin(word[i]). If the returned value is ‘true’ then increase the count variable and print the word.

Step 10 :               If count of palindromic words is not equal to zero, then print the value stored in the variable ‘count’

Step 11 :               End of algorithm for main() method

Algorithm for function boolean isPalin(String s) :

Step 1   :               Start of algorithm for function isPalin()

Step 2   :               Find the length of the String ‘s and store it in an integer variable ‘l’

Step 3   :               Declare and initialize a String variable rev=”” for storing the reverse of the String ‘s’

Step 4   :               Start a reverse for loop from i = l-1 to 0 and repeat step 5

Step 5   :               Extract characters from the end of the original string and add them to the variable ‘rev’

Step 6   :               If the reverse word obtained (rev) is equal to the original String (s), then return true, otherwise return false.

Step 7   :               End of algorithm for the function isPalin().

Similarly if you have more functions, then just write their algorithms in a similar fashion one after the other.

This is how you can write algorithms in your ISC Practical Examination. So, as you see, this is nothing but step wise solution to the given program in English language. So just relax! It isn’t a big deal to write algorithms now. You can easily get a 10/10 in the algorithm part now. Smile.

Check Also

ISC 2016 Computer Science Solution + Examiner’s Comments – From the Council

Solution of ISC 2016 Computer science Paper as provided by the Council for the Indian School Certificate Examinations.

39 comments

  1. System.out.print("Enter any sentence : ");
    String s = br.readLine();
    int l = s.length();
    int pos=0;
    String w;
    for(int i=0;i<l;i++)
    {
    if(s.charAt(i)==’ ‘)
    {
    w = n.substring(pos,i);

    /* Write the operation you want to perform with ‘w’ here.
    * You can also send ‘w’ to any function by calling it here
    */

    pos=i+1;
    }
    }
    Sir , in the above code for extracting words from a sentence you used the statement “i<” in the for loop condition which I could not understand. So I request you to kindly explain me the purpose of using this statement.
    Thank you.

  2. It is a lovely article which you wrote. Thanks a lot sir. I will follow your method in my exam tommorow

  3. Thank you so much sir. This is the best site ever!

  4. Thank u sir very helpful

  5. Sir please upload some questions on outputs of yheory paper.
    Thank you for creating such a wonderful website for us students

  6. Thanks a lot sir….could see the pains that you have taken to compile such valuable articles as i read it…..that will be really helpful to all the students across India……..

    Sir and a question
    do we have to document the written program?

    And variable discription should be given as a table or will it do if I describe it along with its declaration as a part of documentation?

    Sir please reply as soon as you can because 17 is our practical exam…..

  7. sir i am your fan
    its really very helpful

  8. I’d love just a few more algorithm examples but these are really helpful! Thanks so much!

  9. is it needed to do variable listing in ISC theory paper of programs attempted.

  10. will i get full marks by writing this type of algo

  11. how to run a program of inheritance in bluej?? plzzz help

  12. sir,should we write comments in the algorithm if we are writing in pseudo code…

  13. is it must we have to use tokeniser in the 3rd string program?

  14. is it necessary to write comments in the program? or is it okay if we just write the variable description? please reply asap sir.

  15. we don’t have to write flowchart , sir??

  16. how to write documentation , please help??

    • The 3rd Instruction in the practical question paper is referred to as the documentation:
      “3. Document the program using mnemonic names / comments, identifying and clearly describing the choice of data types and meaning of variables.”

      In this you need to write comments in your program and after you have finished writing your program, write the Data Description Table for it which consists of mostly 3 columns – Identifier/Variable Name, Data Type and Purpose.

      For example: The data description table for the below given code would be:

      Code:

      void isPrime(int n)
      {
         int c = 0;
         for(int i = 1; i<=n; i++)
         {
           if(n%i == 0)
              c++;
         }
         if(c == 2)
           System.out.println("The number is Prime");
         else
           System.out.println("The number is Not Prime");
      }
      

      Data Description:

      Identifier Name Data Type Purpose
      n int variable to store the number
      c int variable to count the number of factors of n
      i int loop control variable

      Hope this helps.
      Regards,
      guideforschool

  17. sir can u  post a simpler code for extracting a word from a sentence.pls.

     

    • Yes Gopika, there are alternative codes for extracting words from a sentence. It is up to you to judge which is simpler and which is not. 🙂
      Here is a code which extracts words from a sentence and saves it in a String variable w.

      System.out.print("Enter any sentence : ");
      String s = br.readLine();
      int l = s.length();
      int pos=0;
      String w;
      for(int i=0;i<l;i++)
              {
                  if(s.charAt(i)==' ')
                  {
                      w = n.substring(pos,i);
      
                      /* Write the operation you want to perform with 'w' here. 
                       * You can also send 'w' to any function by calling it here
                       */
      
                      pos=i+1;
                  }
              }
      
    • String a1=”Hello world this is jackass”
      String[] a2=a1.split(” “); // if you know words are separated by space , it will put all it in array 😉

      • Thank you Anna.
        Yes, this is another way which we have used in some programs. It is the easiest way when you have to save the words of a sentence in an array.
        Just note: If there are 2 spaces in between any words or a fullstop followed by a space as in “Java is Fun. Said none”, the above code needs to be modified otherwise it will store null strings also in the array.
        Just use this syntax: String word[]=s.split(“[. ]+”); where ‘s’ is the sentence. Similarly you can use other punctuation marks by putting them inside like this “[?!,;. ]+”

  18. Thank You 😉 Thank You very much, it helped a lot 😉

  19. is it not okay if in fair itself we first write the program and then the algorithm? does the order matter?

  20. I always faced a problem in writing algorithms. But this post is really helpful. Thankyou.

Leave a Reply to Moon Cancel reply

Your email address will not be published. Required fields are marked *