Algorithm (FP)

0.0(0)
Studied by 0 people
call kaiCall Kai
Locked
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/20

flashcard set

Earn XP

Last updated 6:48 PM on 8/5/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

21 Terms

1
New cards

What is an algorithm

Set of rules to obtain the expected output from the given input.

2
New cards

Algorithmic Programming

  • its all about writing a set of rules with a finite number of steps that instruct the computer how to perform a task

  • a computer program is essentially an algorithm that tells the computer what specific steps to execute, in what order, in order to carry out a specific task.

  • algorithms are written using particular syntax, depending on the programming language being used

3
New cards

Rules of an algorithm

  1. The sequence must have a starting point. This is the first step to be completed.

  2. Each step (action) must lead to another step or complete the algorithm. This means you cant have hanging blocks that don’t go anywhere.

  3. The task must be completed in a finite number of actions

4
New cards

Characteristics of an algorithm

  • Clear and Unambiguous: The algorithm should be clear and unambiguous. Each of its steps should be clear in all aspects and must lead to only one meaning

  • Well defined inputs: if an algorithm says to take inputs, it should be well defined inputs

  • well defined outputs: the algorithm must clearly define what output will be yielded and it should be well defined as well

  • finite-ness: the algorithm must be finite, ie, it should terminate after a finite time

  • feasible: the algorithm must be simple, generic, and practical, such that it can be executed with the available resources. It must not contain some future technology

  • language independent: the algorithm designed must be language independent it must be just plain instructions that can be implemented in any language, and yet the output will be the same, as expected

5
New cards

Parts of an Algorithm

  1. Input - the values that are put into the algorithm

  2. Process - what happens in the algorithm

  3. Output - the value (or print out) that the algorithm produces

6
New cards

Ways to specify an Algorithm

  1. Natural language

  2. Pseudocode

  3. Flowchart

7
New cards

Natural Language

  • it is very simple and easy to specify an algorithm using natural language, but many times, the specification of an algorithm by using natural language is not clear and thereby we get brief specification

  • such specification creates difficulty while actually implementing it. Hence, many programmers prefer to have specification of algorithm by means of pseudocode

8
New cards

Example of Natural Language

an algorithm to perform addition of 2 numbers

  1. read the first number, say a

  2. read the first number, say b

  3. add the above 2 numbers and store the result in c

  4. display the result from c

9
New cards

Pseudo-Code

  • pseudo code means fake code. It is a mixture of a natural language an programming language constructs.

  • it is text that is written pragmatically but designed to be read by humans and not a machine

  • there is no standard convention on what pseudo code should look like

  • the advantage of pseudocode is that anyone can read it regardless of which languages they are able to code in

  • it is usually more precise than natural language

  • for assignment operation left arrow “←”, for comments two slashes “//”, if conditions, for, while loops are used

10
New cards

Pseudo code for addition of two numbers

Algorithm sum (a,b)

//Problem Desc: This algorithm performs addition of 2 numbers

//Input: Two integers a and b

//Output: Addition of two integers

c ← a+b

return c

This specification is more useful for implementation of any language

Another way:

  1. Read a, b

  2. Add two numbers

  3. Sum a+b;

  4. Result Sum “the sum is”;

  5. End

11
New cards

Write an algorithm to find the sum of 4 numbers

  1. Start

  2. Sum=0 and Count=0

  3. Read the number n

  4. Now, Sum = Sum+n and then the counter will be incremented by 1

  5. count = count+1

  6. Now check whether the count is less than 4 or not. If count is less than 4, then go to step 3. Otherwise, write “the sum is”

  7. Stop

12
New cards

Write an algorithm to find out the largest of three numbers

  1. Start

  2. Read three numbers p,q,r

  3. If p>q, go to step 5

  4. If q>r, then write q is the largest number, else, write is the largest number

  5. If p>r then write p is the largest number else write r is the largest number

  6. stop

13
New cards

Write n algorithm to calculate the result when a number is given. If the number is greater than 50, then number must be increased 5 times. Otherwise, the number is decreased by 10

1) Start

2) Read number P

3) If P>50 then,

write P=P+5

else

write P-10

4) Write P

5) Stop

14
New cards

Flowcharts

  • Flowcharts are a graphical way of displaying an algorithm

  • it is a graphical representation of the logical flow of data

  • it uses the standard graphical symbols to narrate the sequential process of a specific module. The steps must be followed while designing the whole program.

  • Flowcharts are very effective in understanding how a process works

  • Flowcharts are also known as process maps that can be used to identify: (a) Flow of info, (b) Number of steps in a process, c) Branches in a process, (d) Interdependent operations

15
New cards

Flowchart symbols:

start/stop

every flowchart has a starting point and a terminating point. The symbol that is used is a rounded rectangle for representation. It is called a terminal

16
New cards

Input/Output

Every time you take an input from a user and rather an output to the user, an input/output symbol is used in the flowchart. The symbol that is used for better input/output related actions is a parallelogram

17
New cards

Process

if you are running instruction, you need to use a rectangular box in the flowchart

18
New cards

Decision Symbol

in a flowchart, a decision symbol as shown below is used for answering questions in the form of either true or false or yes or no. Note that each answer can lead you to a different path in the flowchart

19
New cards

Flow Lines

they depict the direction of a flow in a flowchart. There are 4 lines

20
New cards

Connector

It connects different steps in s flowchart hat are on different pages and gives a sense of continuation. Overall, it is use in extremely complex flowcharts and is denoted by a small circle

21
New cards

Guidelines for drawing a Flowchart

  1. describe the process to be charted

  2. start with a trigger event. Eg: count your money for starting the process of counting

  3. 3. usually, direction of flow of a process if from left to right or top to bottom

  4. please note that only one flow line should come out of a process symbol

  5. also, only on flow line should enter a decision symbol. However, two or three flow lines can leave the same decision symbol

  6. only one flow line is used in conjunction with terminal symbol

  7. it is important to ensure that a flowchart has a start and end

  8. a flowchart can have only one start terminal. However, it can sometimes lead to more than one terminal symbol

  9. it is also important to stop a flowchart at a logical conclusion