Advice on How to write Algorithm in ISC Computer Practical

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Email Address

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 program2) 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 2:

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.

split() function splits a string into tokens (words) and returns the result in the form of a String array.
Example: If String s = “Guide For School”, then String w[]=s.split(” “); will save the words “Guide”, “For” and “School” in the array w[]

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. ‘+’ denotes any possible combinations of the punctuators mentioned in the []. Similarly you can use other punctuation marks by putting them inside like this “[?!,;. ]+”

There are other alternatives as well, you can use StringTokenizer class.

Instead of these lines:

String word[]=s.split("[.?! ]+"); // Saving the words in an array using split()
int c = word.length; // Finding the number of words

/* 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.

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:

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.

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 “[?!,;. ]+”

ICSE | ISC Sample Papers

In this section we will be providing you with the Sample/Guess papers of ICSE (Computer Applications) and ISC (Computer Science) which can be easily downloaded. We hope that the students will benefit from these resources.