<< Chapter < Page Chapter >> Page >

A flowchart is a visual representation of an algorithm's control flow. That representation illustrates statements that need to execute, decisions that need to be made, logic flow (for iteration and other purposes), and terminals that indicate start and end points.

To present that visual representation, a flowchart uses various symbols, which Figure 3.5.shows.

Flowchart symbol for statements, decisions, logic flows, etc.

This review was essential because we will be using these building blocks quite often today.

3. In pseudocode

Pseudocode (derived from pseudo and code) is a compact and informal high-level description of a computer programming algorithm that uses the structural conventions of programming languages, but omits detailed subroutines, variable declarations or language-specific syntax. The programming language is augmented with natural language descriptions of the details, where convenient, or with compact mathematical notation.

Example

Present the algorithm of converting an integer from decimal to binary

a. By words

Step 1: Let x is the decimal integer you want to convert and let k=1

Step 2 : Divide x by 2, saving the quotient as Q, and the remainder (in binary) as R k

Step 3 : If Q is not zero, let X=Q, and go back to step 2. Otherwise go to step 4.

Step 4 : Assume step 1-3 were repeated n times. Arrange the remainders as string for digit R n R n 1 ... R 3 R 2 R 1 .

b. As a flowchart

Flowchart of the algorithm of converting an integer from decimal to binary

c. By pseudocode

BEGIN input x.y=”” remainder=0,while (x>0) beginquotient=x/2 remainder=x mod 2y=conc(remainder,y) x=quotientend print yEND.

Example

Bubble Sort

Bubble sort is a simple sorting algorithm. It works by repeatedly stepping through the list to be sorted, comparing two items at a time and swapping them if they are in the wrong order. The pass through the list is repeated until no swaps are needed, which indicates that the list is sorted.

5 1 4 2 8 - unsorted array

1 4 2 5 8 - after one pass

1 2 4 5 8 - sorted array

The algorithm gets its name from the way smaller elements "bubble" to the top (i.e. the beginning) of the list via the swaps.Because it only uses comparisons to operate on elements, it is a comparison sort. This is the easiest comparison sort to implement.

Here are the presentations of bubble sort algorithm

a. By words

Step 1: Get the length of the list : N and the list: list[1],list[2],…,list[N]

Step 2: M ← N.

Step 3: If M<2 then print the list, stop.

Step 4: M ← M – 1, i ← 0.

Step 5: Increase i by 1

Step 6: If i>M then go to step 3.

Step 7: If list[i]>list[i+1] swap list[i]and list[i+1]

Step 8: Go to step 5.

b. As a flow chart

Flowchart of bubble sort algorithm

c. In pseudocode

A simple way to express bubble sort in pseudocode is as follows:

BEGIN get length (list) and list’s elements for each M in length(list) down to 2 do:for each i in 1 to M-1 do: if list[ i]>list[ i+1 ] thenswap( list[i+1], list[ i ]) end ifend for end forend procedure

Comparing the three methods,especially pseudocode and flowchart we realized :

Questions & Answers

what is biology
Hajah Reply
the study of living organisms and their interactions with one another and their environments
AI-Robot
what is biology
Victoria Reply
HOW CAN MAN ORGAN FUNCTION
Alfred Reply
the diagram of the digestive system
Assiatu Reply
allimentary cannel
Ogenrwot
How does twins formed
William Reply
They formed in two ways first when one sperm and one egg are splited by mitosis or two sperm and two eggs join together
Oluwatobi
what is genetics
Josephine Reply
Genetics is the study of heredity
Misack
how does twins formed?
Misack
What is manual
Hassan Reply
discuss biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles
Joseph Reply
what is biology
Yousuf Reply
the study of living organisms and their interactions with one another and their environment.
Wine
discuss the biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles in an essay form
Joseph Reply
what is the blood cells
Shaker Reply
list any five characteristics of the blood cells
Shaker
lack electricity and its more savely than electronic microscope because its naturally by using of light
Abdullahi Reply
advantage of electronic microscope is easily and clearly while disadvantage is dangerous because its electronic. advantage of light microscope is savely and naturally by sun while disadvantage is not easily,means its not sharp and not clear
Abdullahi
cell theory state that every organisms composed of one or more cell,cell is the basic unit of life
Abdullahi
is like gone fail us
DENG
cells is the basic structure and functions of all living things
Ramadan
What is classification
ISCONT Reply
is organisms that are similar into groups called tara
Yamosa
in what situation (s) would be the use of a scanning electron microscope be ideal and why?
Kenna Reply
A scanning electron microscope (SEM) is ideal for situations requiring high-resolution imaging of surfaces. It is commonly used in materials science, biology, and geology to examine the topography and composition of samples at a nanoscale level. SEM is particularly useful for studying fine details,
Hilary
cell is the building block of life.
Condoleezza Reply
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Introduction to computer science. OpenStax CNX. Jul 29, 2009 Download for free at http://cnx.org/content/col10776/1.1
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Introduction to computer science' conversation and receive update notifications?

Ask