how to write algorithm

10
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: (https://twitter.com /guideforschool) (http://www.facebook.com /guideforschool) (http://www.guideforschool.com /feed/) Number (http://www.guideforschool.com/category/number-related-programs/) String (http://www.guideforschool.com/category/string-related-programs/) Array (http://www.guideforschool.com/category/array-related-programs/) Date (http://www.guideforschool.com/category/date-related-programs/) Recursion (http://www.guideforschool.com/category/recursion-related-programs/) Inheritance (http://www.guideforschool.com/category/inheritance-related- programs/) Advice on How to write Algorithm in ISC Computer Practical | Guide ... http://www.guideforschool.com/1611744-advice-on-how-to-write-algor... 1 of 10 15-02-2015 19:41

Upload: uttamsaxena

Post on 17-Nov-2015

277 views

Category:

Documents


12 download

DESCRIPTION

How to Write Algorithm

TRANSCRIPT

  • 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 isnt 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 havent written anything in pen yet.

    Example 1:

    (https://twitter.com/guideforschool)

    (http://www.facebook.com/guideforschool)

    (http://www.guideforschool.com/feed/)

    Number (http://www.guideforschool.com/category/number-related-programs/)

    String (http://www.guideforschool.com/category/string-related-programs/)

    Array (http://www.guideforschool.com/category/array-related-programs/)

    Date (http://www.guideforschool.com/category/date-related-programs/)

    Recursion (http://www.guideforschool.com/category/recursion-related-programs/)

    Inheritance (http://www.guideforschool.com/category/inheritance-related-

    programs/)

    Advice on How to write Algorithm in ISC Computer Practical | Guide ... http://www.guideforschool.com/1611744-advice-on-how-to-write-algor...

    1 of 10 15-02-2015 19:41

  • 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/

    (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

  • 13LikeLike Tweet 0

    Tweet 0

    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 isnt a big deal to write algorithms now. You can easily get a 10/10

    in the algorithm part now. Smile.

    Share this:

    Related

    Top 5 Advice regarding ISC

    Computer Practical

    (http://www.guideforschool.com

    /1330124-top-5-advice-regarding-

    isc-computer-practical/)

    ISC 2010 Computer Science

    Solution and Examiner's

    Comments - From the Council

    (http://www.guideforschool.com

    /1947206-isc-2010-computer-

    science-solution-and-examiners-

    comments-from-the-council/)

    Some Operations on Linked List

    using Java

    (http://www.guideforschool.com

    /1137558-some-operations-

    on-linked-list-using-java/)

    www.guideforschool.com | Designed By -

    MZA Designs

    LATEST ICSE 2014 Computer Applications Paper Solved (http://www.guideforschool.com/1923453-icse-2014-compu

    (http://www.guideforschool.com)

    Advice on How to write Algorithm in ISC Computer Practical | Guide ... http://www.guideforschool.com/1611744-advice-on-how-to-write-algor...

    3 of 10 15-02-2015 19:41

  • February 19, 2014 - 1:26 am Class 12 (http://www.guideforschool.com/category/class-12/), Important Lessons

    (http://www.guideforschool.com/category/important-lessons/), Important Tips (http://www.guideforschool.com/category/important-tips/),

    ISC Important Notes (http://www.guideforschool.com/category/isc-important-notes/) 242 views

    (http://www.guideforschool.com

    /author/guidefs/)

    MZA (http://www.guideforschool.com/author/guidefs/)

    A teacher whose aim is to make Java a fun to learn experience for the school students by

    striving to build clear fundamentals of every concepts and helping students to develop their

    ability to reason and logically analyze any given programs.

    VISHAL TIWARI

    February 12, 2015 at 9:08 pm (http://www.guideforschool.com/1611744-advice-on-how-to-write-algorithm-in-isc-computer-

    practical/#comment-1335) - Reply (/1611744-advice-on-how-to-write-algorithm-in-isc-computer-practical

    /?replytocom=1335#respond)

    MZA

    February 12, 2015 at 9:36 pm (http://www.guideforschool.com/1611744-advice-on-how-to-write-

    algorithm-in-isc-computer-practical/#comment-1337) - Reply (/1611744-advice-on-how-to-write-

    algorithm-in-isc-computer-practical/?replytocom=1337#respond)

    Moon

    June 17, 2014 at 9:41 pm (http://www.guideforschool.com/1611744-advice-on-how-to-write-algorithm-in-isc-computer-

    practical/#comment-648) - Reply (/1611744-advice-on-how-to-write-algorithm-in-isc-computer-practical

    /?replytocom=648#respond)

    Java For School (http://www.guideforschool.com/)

    July 10, 2014 at 12:15 am (http://www.guideforschool.com/1611744-advice-on-how-to-write-

    algorithm-in-isc-computer-practical/#comment-649) - Reply (/1611744-advice-on-how-to-write-

    algorithm-in-isc-computer-practical/?replytocom=649#respond)

    will i get full marks by writing this type of algo

    Yes.

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

    See a sample program: http://www.guideforschool.com/417291-question-11-inheritance-

    isc-2013-theory-paper-solved/ (http://www.guideforschool.com/417291-question-

    11-inheritance-isc-2013-theory-paper-solved/)

    www.guideforschool.com | Designed By -

    MZA Designs

    LATEST ICSE 2014 Computer Applications Paper Solved (http://www.guideforschool.com/1923453-icse-2014-compu

    (http://www.guideforschool.com)

    Advice on How to write Algorithm in ISC Computer Practical | Guide ... http://www.guideforschool.com/1611744-advice-on-how-to-write-algor...

    4 of 10 15-02-2015 19:41

  • Joseph

    February 19, 2014 at 10:02 pm (http://www.guideforschool.com/1611744-advice-on-how-to-write-algorithm-in-isc-computer-

    practical/#comment-646) - Reply (/1611744-advice-on-how-to-write-algorithm-in-isc-computer-practical

    /?replytocom=646#respond)

    Java For School (http://www.guideforschool.com)

    February 19, 2014 at 10:08 pm (http://www.guideforschool.com/1611744-advice-on-how-to-write-

    algorithm-in-isc-computer-practical/#comment-647) - Reply (/1611744-advice-on-how-to-write-

    algorithm-in-isc-computer-practical/?replytocom=647#respond)

    dipanjan

    February 19, 2014 at 9:05 pm (http://www.guideforschool.com/1611744-advice-on-how-to-write-algorithm-in-isc-computer-

    practical/#comment-644) - Reply (/1611744-advice-on-how-to-write-algorithm-in-isc-computer-practical

    /?replytocom=644#respond)

    Java For School (http://www.guideforschool.com)

    February 19, 2014 at 9:11 pm (http://www.guideforschool.com/1611744-advice-on-how-to-write-

    algorithm-in-isc-computer-practical/#comment-645) - Reply (/1611744-advice-on-how-to-write-

    algorithm-in-isc-computer-practical/?replytocom=645#respond)

    megha

    February 19, 2014 at 6:19 pm (http://www.guideforschool.com/1611744-advice-on-how-to-write-algorithm-in-isc-computer-

    practical/#comment-640) - Reply (/1611744-advice-on-how-to-write-algorithm-in-isc-computer-practical

    /?replytocom=640#respond)

    Java For School (http://www.guideforschool.com)

    February 19, 2014 at 6:25 pm (http://www.guideforschool.com/1611744-advice-on-how-to-write-

    algorithm-in-isc-computer-practical/#comment-641) - Reply (/1611744-advice-on-how-to-write-

    algorithm-in-isc-computer-practical/?replytocom=641#respond)

    megha

    February 19, 2014 at 6:41 pm (http://www.guideforschool.com/1611744-

    advice-on-how-to-write-algorithm-in-isc-computer-practical/#comment-642) -

    Reply (/1611744-advice-on-how-to-write-algorithm-in-isc-computer-practical

    /?replytocom=642#respond)

    Java For School

    (http://www.guideforschool.com)

    February 19, 2014 at 7:07 pm

    (http://www.guideforschool.com/1611744-advice-

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

    Yes brief comments.

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

    No, you can do it without using StringTokenizer also.

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

    asap sir.

    Do write the comments also. Just 7-8 comments will do.

    u mean just a few comments for the main logic of the program will do?

    www.guideforschool.com | Designed By -

    MZA Designs

    LATEST ICSE 2014 Computer Applications Paper Solved (http://www.guideforschool.com/1923453-icse-2014-compu

    (http://www.guideforschool.com)

    Advice on How to write Algorithm in ISC Computer Practical | Guide ... http://www.guideforschool.com/1611744-advice-on-how-to-write-algor...

    5 of 10 15-02-2015 19:41

  • on-how-to-write-algorithm-in-isc-computer-practical/#comment-643) - Reply (/1611744-advice-on-how-to-write-algorithm-in-isc-

    computer-practical/?replytocom=643#respond)

    Anna

    February 19, 2014 at 5:33 pm (http://www.guideforschool.com/1611744-advice-on-how-to-write-algorithm-in-isc-computer-

    practical/#comment-636) - Reply (/1611744-advice-on-how-to-write-algorithm-in-isc-computer-practical

    /?replytocom=636#respond)

    Java For School (http://www.guideforschool.com)

    February 19, 2014 at 5:39 pm (http://www.guideforschool.com/1611744-advice-on-how-to-write-

    algorithm-in-isc-computer-practical/#comment-637) - Reply (/1611744-advice-on-how-to-write-

    algorithm-in-isc-computer-practical/?replytocom=637#respond)

    Anna

    February 19, 2014 at 2:30 pm (http://www.guideforschool.com/1611744-advice-on-how-to-write-algorithm-in-isc-computer-

    practical/#comment-631) - Reply (/1611744-advice-on-how-to-write-algorithm-in-isc-computer-practical

    /?replytocom=631#respond)

    Java For School (http://www.guideforschool.com)

    February 19, 2014 at 4:10 pm (http://www.guideforschool.com/1611744-advice-on-how-to-write-

    algorithm-in-isc-computer-practical/#comment-632) - Reply (/1611744-advice-on-how-to-write-

    algorithm-in-isc-computer-practical/?replytocom=632#respond)

    Yes

    we dont have to write flowchart , sir??

    No.

    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:

    Data Description:

    Identifier Name Data Type Purpose

    12345678910111213

    void isPrime(int n){ int c = 0; for(int i = 1; i