You are on page 1of 18

Topic Summary

HSC Year 12
Chapter 1- Social and Ethical Issues..........................................................................2
1.1) Right and Responsiilities o! So!t"are #e$elopers...................................2
1.2) So!t"are %iracy and Copyright..................................................................&
1.&) The So!t"are 'ar(et.................................................................................)
1.)) Signi!icant Social and Ethical Issues.........................................................)
Chapter 2- *pplication o! So!t"are #e$elopment *pproaches....................................+
2.2) So!t"are #e$elopment *pproaches..........................................................+
2.&) 'ethods o! Implementation.......................................................................,
2.)) Current Trends in So!t"are #e$elopment.................................................-
2..) /se o! C*SE tools and their application in large systems de$elopment....-
Chapter &- #e!ining and /nderstanding the %rolem.................................................0
&.1) #e!ining the %rolem................................................................................0
&.2) #esign Speci!ications................................................................................0
&.&) 'odelling................................................................................................. 11
&.)) Communication Issues............................................................................11
Chapter )- %lanning and #esign o! So!t"are Solutions............................................1&
).1) #esign %atterns...................................................................................... 1&
).2) #esign Concepts.....................................................................................1&
).&) 'odules and 1unctions...........................................................................1.
).)) *rrays2 3asic Concepts...........................................................................1+
)..) *d$anced Sorting and Searching Techni4ues.........................................1+
).+) String %rocessing....................................................................................1,
1
Chapter 1- Social and Ethical Issues
1.1) Right and Responsibilities of Software Developers
So!t"are de$elopers ha$e the right to e ac(no"ledged as the author o! an
application. So!t"are authors also ha$e responsiilities to"ards the users o! their
so!t"are. These responsiilities include2
o Claiming authorship only o! "hat they ha$e "ritten themsel$es
o Creating reliale so!t"are
o Creating 4uality so!t"are
o Responding to prolems
o 1ollo"ing an ethical code o! conduct
o %re$enting the spread o! $iruses
Authorship
The creati$e process rings "ith it the right o! an author to e ac(no"ledged !or
their "or(
There are t"o responsiilities2
1. to protect his5her interests in the system eing
de$eloped
2. to protect the rights o! other authors "hose modules
are incorporated into the !inal solution
The de$eloper needs to ensure that the sources o! any pre$iously "ritten code
are ac(no"ledged
Reliability
* so!t"are de$eloper has a responsiility to ma(e sure that the program
eing de$eloped is ale to per!orm its tas(s e!!ecti$ely and relialy
Reliability: re!ers to the aility o! the so!t"are to per!orm "ithout !ailure. So!t"are
!ailure occurs "hen the so!t"are per!orms in an unpredictale "ay
Quality
The 4uality o! so!t"are is measured y a numer o! criteria. These include2
Reliability
Ease of Use: is a general term used to descrie the com!ort o!
the user "ith the so!t"are
Consistency: in$ol$es the placement o! similar items in the
same place !rom screen to screen e.g 6/I
Documentation
Adherence to Softare Standards
Response to !roblems
To sol$e a prolem the steps are $irtually the same as de$eloping the
so!t"are2
Identify the problem
Understand the problem
Desi"n and #est a solution to the problem
Implement the solution to the problem
2
Code of Conduct
Social and Ethical issues that con!ront a de$eloper
There are legal re4uirements such as2
Respect !or Copyright
*idance to so!t"are licences
There are also the ethical areas the de$eloper should co$er2
*c(no"ledgement o! the contriutions o! all those "ho ha$e assisted
Clearance to use copyrighted modules or those "ritten y others
%ri$acy o! personal details7 security o! data 8 maintenance o!
usiness secrets
*ppropriate in-program prompts. They should e non-threatening7
non-racial and inclusi$e
$iruses
The so!t"are de$eloper should ensure that $iruses are not spread y means o! the
de$elopment processes. The de$eloper needs to ha$e the capaility to detect and
eradicate the most recent $iruses7 as "ell as ensure that they do not recei$e or
transmit them.
1.2) Software Piracy and Copyright
The author o! a so!t"are title has the right to e ac(no"ledged and re"arded !or his
"or(9 the la"s o! copyright are designed to protect that right. The illegal copying o!
so!t"are :piracy) $iolates these la"s.
Concepts associated ith !iracy and Copyri"ht
Intellectual Property: is a "or( resulting !rom some creati$e acti$ity. The created
o;ect is the result o! a thought :or intellectual) process.
Plagiarism: the process o! claiming authorship o! an intellectual property o"ned y
another person. *n article is considered plagiari<ed i! it is sustantially the same as
one that already e=ists.
Shareware: the so!t"are that is distriuted !ree o! charge7 ut a!ter a trail period o!
use the user is e=pected to ma(e a payment to the author.
Public Domain: this so!t"are is !reely distriuted though this so!t"are does not
re4uire the user to pay a !ee to use the so!t"are. Though the copyright still does
remain "ith the author.
Ownership versus Licensing: "hen a person uys so!t"are they do not o"n it. They
are really uying the license that enales them to use the so!t"are. The only time
that o"nership "ill e purchased is "hen it has customised !or an organi<ation.
Copyright Laws: copyright la"s protect the rights o! the author. The Copyright Act
1!" #Cwlth$ go$erns these la"s in *ustralia.
Reverse%&ac'war( )ngineering: this in$ol$es e=amining an e=isting system to
understand its components and using that understanding to create a similar system.
&
Decompilation: This is the process o! translating e=ecutale machine code into
assemler language so the structure o! the program can e more easily understood.
This may e use!ul "hen the original coding o! a solution has een lost
Licence Con(itions: the conditions o! a so!t"are license spell out e=actly ho" the
so!t"are may e used y the licence purchaser. This is a legally inding contract.
*etwor' +se: The licence "ill state ho" the so!t"are may e used on a net"or(. E.g.
the net"or( licence may e purchased !or a particular numer o! users.
Softare !iracy and Copyri"ht %as
The Copyright Act 1"! at a national le$el ma(es pro$isions !or an *ustralian
Copyright to e recognised internationally. So!t"are The!t :piracy) is the most
common !orm o! copyright reach.
1.3) The Software ar!et
6o$ernment7 usiness and pri$ate indi$iduals ma(e up the so!t"are mar(et.
The so!t"are mar(et is not dri$en ;ust y the needs o! the user. 'any o!
today>s common applications "ere the result o! !or"ard thin(ing.
It is also dri$en y the emergence o! more sophisticated hard"are and
peripherals. *s the capailities o! hard"are increase7 so does the
sophistication o! so!t"are applications.
&aintainin" &ar'et !osition
There are t"o "ays in "hich so!t"are de$elopers can maintain their mar(et
position2
1. Introducing ne" and inno$ati$e so!t"are applications9 or
2. Impro$ing the current applications
'aintenance and support !or an e=isting product is $ery important !or the
sur$i$al o! a so!t"are company.
#he effect on the &ar'etplace
*s de$elopers ring out ne" applications or enhancement to e=isting
so!t"are7 consumers are enticed to update their applications.
* side e!!ect o! increasing comple=ity o! so!t"are is the need !or an increase
in computer po"er to run the application7 as "ell as a need !or larger primary
storage7 larger secondary storage and more po"er!ul output de$ices
1.") Significant Social and #thical $ss%es
So!t"are is used in a large numer o! di!!ering situations7 each in "hich impacts upon
the people. The so!t"are de$eloper has a social and ethical responsiility to ensure
that all people ene!it !rom a ne" system "ithout !oregoing any rights that ha$e een
held up until its introduction
(ational and International le"al action resultin" from softare
de)elopment
Some so!t"are de$elopment may result in con!lict and these are o!ten
resol$ed in the courts.
Copyright is a ma;or area in "hich this occurs
)
!ublic Issues
#ecisions made y so!t"are de$elopers can impact on indi$iduals oth indirectly and
directly9 the !ollo"ing gi$es e=amples o! those2
,he year -... problem: decided to represent the year "ith 2 digits instead o!
!our to sa$e storage. This "as !eared that it "ould read ?@@> !or 2@@@ as 10@@
Computer /iruses: these are malicious attempts to disrupt or destroy
computer systems. These are eing stopped through $irus detection so!t"are
and all round caution.
Reliance on So0tware: people are ecoming to dependent on technology7
!rom "ashing dishes or en;oying a day out. So!t"are !ailure could e minor
e.g. the air conditioning rea(ing do"n9 or it could e ma;or e.g. "hen human
li!e is endangered.
.
Chapter *- Application of Softare De)elopment
Approaches
2.2) Software Develop&ent 'pproaches
There are !our common approaches to so!t"are de$elopment2
1. Structure( approach: this is di$ided into . stages
I. Definin" the !roblem- this included in!ormation collection7 analysis o!
in!ormation7 re4uirement report7 !easiility report "hich includes
Constraints: are the limiting !actors
1inancial: "ill the company pro!it !rom implementation
Operational: is the company capale to handle the
manual processing in$ol$ed
,echnical: "ill the company ha$e the technical
resourcesA
Sche(uling: can the system e implemented y the
deadlineA
Social and Ethical issues also ha$e to e addressed
II. !lannin" the Solution- this in$ol$es choosing the appropriate data
structures and program structure7 planning the characteristics o! the
user inter!ace and designing algorithms.
III. +uildin" the Solution- this is the coding and testing phase. In this step
all o! the algorithms are con$erted into machine code and tested
IB. Chec'in" the Solution- a!ter the !ull program has een assemled and
tested it needs to e chec(ed. %er!ormance is measured against original
speci!ications. /sers can e in$ol$ed at this point.
B. &odifyin" the Solution- this is simply and changes that need to e
made a!ter chec(ing.
This approach is generally used !or large pro;ect7 "hich are eing underta(en y a
team o! de$elopers. The specialists in$ol$ed are usually categorised as system
analysts and programmers. The !irst t"o stages are generally the responsiility o! the
system analyst. %rogrammers per!orm a large amount o! the "or( in the remaining
tas(s.

2. )n(2+ser Development : this in$ol$es the adaptation o! so!t"are tools y
the user. This approach is used !or small-scale solutions and is made usually
y the person "ho "ill use it. Some e=amples include dataases and
spreadsheets
&. Rapi( Application Development: this asically means any approach that
"ill lead to !aster application de$elopment. Some e=amples o! this approach
include2
Re-use o! code
C*SE tools such as Bisual 3asic
/se o! templates
). Prototyping Approach: in$ol$es creating a "or(ing model o! the system.
This can e used to ;ust gather in!ormation or it can actually e de$eloped
into the !inal product. %rototypes are created7 then tested and e$aluated7
modi!ied then tested again.
+
2.3) ethods of $&ple&entation
This simply in$ol$es the con$ersion !rom the e=isting system to the ne" system.
There are !our methods generally used2 #irect cuto$er7 %arallel7 %hased and %ilot
Direct Cut-,)er
This in$ol$es the complete and immediate con$ersion to the ne" system. The old
system is not used !rom the time the ne" system is !irst used. I! the ne" system !ails
the old system is not a$ailale as a ac(up
Cld System De" System
!arallel Con)ersion
This in$ol$es the old and the ne" system "or(ing together !or a period o! time. This
allo"s the ne" system to e !ully tested e!ore it is completely con$erted to. I! the
ne" system !ails the old system can e returned to.

Cld System De" system
!hased Con)ersion
This in$ol$es the gradual implementation o! the ne" system to carry out certain
operations "hile the old system is used !or other operations. This allo" !or operating
modules o! the ne" system to e tested and sta!! trained on. This allo"s !or modules
to e implemented in stages.
!ilot Con)ersion
This in$ol$es the ne" system eing !ully installed ut is used !or only some
operations as the old system is still eing used. E.g. some o! the sta!! in a company
use an old "ord processing system "hile the rest use the old system. It allo"s !or
some memers to e trained in the use o! the ne" system.
,
#ata %rocessed
Time
#ata %rocessed
Time
#ata %rocessed
Time
Cld System De" System
#ata %rocessed
Time
Cld System De" System
2.") C%rrent Trends in Software Develop&ent
,utsourcin"
'any large organi<ations ha$e decided to disand7 or at least reduce the si<e o!7
permanent in!ormation technology sta!!7 contracting outside de$elopers does this.
This is "hat is (no"n as outsourcing.
!opular Approaches
These include such things as "e page editors7 "hich are an e$olutionary
prototyping approach and can e used y end-users. Small end-users o!ten go !or
the o!! the shel! approach "hich can e customised to there needs.
Employment #rends
This includes the option !or usinesses to outsource no". This there!ore ma(es
people in the area o! in!ormation technology e "or(ing mostly under contract or !or
!i=ed term periods rather then permanent placement.
(etor'ed Softare
The de$elopment o! client5ser$er so!t"are in$ol$es !our parts2
#he interface go$erns the interaction et"een the user and the system.
#he application is responsile !or meeting the so!t"are re4uirements o! the
end-user
Database mana"ement is responsile !or the manipulation and management
o! data
(etor' softare pro$ides the means y "hich the communication ta(es
place on the net"or(
2.() )se of C'S# tools and their application in large syste&s
develop&ent
Computer-assisted-so!t"are-engineering :C*SE)
Softare $ersions
*s so!t"are is progressi$ely re$ised7 it ecomes harder to (eep trac( o! the $ersions
in use. * numer o! C*SE tools are a$ailale to help "ith this tas(. There is a
prolem "ith the management o! di!!erent $ersions o! so!t"are7 so numers such as
1.@ are used. The management o! changes to a so!t"are product is (no"n as
softare confi"uration mana"ement -SC&.. To a$oid con!lict all changes made
need to e passed through a central ody.
!roduction of Documentation
This includes such things as dra" programs "hich can e used to create data-!lo"
diagrams etc.
-
Chapter /- Definin" and Understandin" the
!roblem
3.1) Defining the Proble&
Identifyin" the !roblem
The three main sections in identi!ying the prolem are2
1. *ee(s2 the needs o! a system !all under three headings2
i. 0uman (eeds- these are the easiest to identi!y7 as all is needed is
"hat e$ery human "ould "ant. This included oth indirect and
direct users.
ii. User (eeds- the user needs are asically "hat the user "ants out
o! the system
iii. System (eeds- is the need to represent the $arious data items7
the need to store data7 the need to per!orm certain processes7 the
need to output data in a certain "ay.
2. Ob3ectives2 the needs o! the system can e analysed to determine the
"ay in "hich that system must per!orm. In determining o;ecti$es the needs
o! the system are con$erted into a numer o! statements.
&. &oun(aries2 "here outputs lea$e one system and pass to the ne=t are
called oundaries.
Determinin" the feasibility of the solution
The !easiility o! a solution depends on a numer o! !actors. Ehen a system is
de$eloped7 these !actors are e=amined and reported on in a !easiility study. These -
!actors are2
1. Is the Problem worth Solving4
2. Constraints2 these are the limitations that are placed on something. *
constraint may e something li(e a limited udget.
&. &u(getary Consi(erations #0inancial$2 this "ill asically e7 "ill the company
ma(e a pro!it !rom the solution. This "ill e !ound in a cost-ene!it analysis
). Operational consi(erations2 "ill the purpose o! the ne" system meet the
needs o! the organi<ation. Eill the people e ale to use the systemA
.. ,echnical consi(erations2 "ill they ha$e the hard"are5so!t"are neededA
+. Sche(uling2 "ill the solution e !inished y the deadlineA
,. Possible Alternatives2 other solutions that may e !easile
!5 Social an( )thical Consi(erations
3.2) Design Specifications
The design process is entered into once a system has een chosen !rom the options.
This process should not e rushed and the speci!ications co$er a numer o! di!!erent
aspects o! the design process2
o ,he Pro3ect Scope2 pro$ides detail aout ho" the so!t"are !its in "ith the
"hole pro;ect. I%C charts should e included in this aspect. Cther special
processing are also included
o ,he (ata (esign2 "ill identi!y the data o;ects re4uired !or processing and the
resulting data types re4uired !or oth internal and e=ternal use
0
o Overall (esign o0 the program2 the system is represented y a series o!
structure charts "hich represent program modules and the interactions
et"een them.
o Inter0ace Design2 speci!ications are concerned "ith the human-machine
inter!ace and the inter!ace et"een modules.
o Processing2 !or each o! the modules a description o! the processing should e
"ritten. These include algorithms
o Cross2re0erencing2 the re4uirements de!inition to the so!t"are design process
to ensure that all the user>s re4uirements "ill e met
o Implementing an( ,esting2 has the purpose to ma(e sure the so!t"are is
e!!icient and e!!ecti$e in its purpose
#he De)elopers !erspecti)e
The de$eloper o! the solution is !aced "ith con$erting the customer>s "ishes into a
computer program. Thus7 the de$eloper must loo( at the prolem in terms o! data
types7 $ariales and processes.
Data Types
The data types that can e used are2
+oolean- can only hold $alues @ 8 -17 "hich can stand !or true5!alse
+yte- they can only hold one yte :- its)7 integer $alue in range o! @ to 2..
Currency- can hold decimal $alues in a !i=ed-point !ormat
Date- holds date $ariale
Double- holds !loating point $ariale and holds - ytes
Inte"er- can hold "hole numers et"een F&2,+- 8 &2,+,7 holds 2 ytes
%on"- ta(es ) ytes o! memory
Sin"le- they are a simple !loating point
Strin"
*ariables
Bariales !orm part o! the data dictionary o! a pro;ect. There are + considerations !or
each $ariale2
i. Entity G data item :as in #1# or conte=t diagram)
ii. #ata type
iii. Identi!ier name :$ariale name)
i$. *lias :temp rename i! re4uired)
$. %rocesses :in I%C or #1#) "hich use these $ariales
$i. %re set $alues7 restrictions etc
Processes
In order to understand the processes that need to e carried out7 the processes can
e con$erted to algorithms.
#he User1s !erspecti)e
Through the use o! a hierarchical set up the de$eloper gets the user to na$igate
through a program !or"ards and ac("ards to see i! the user ecomes lost. This "ill
help the programmer !ind create consistencies "hich com!orts the user.

1@
3.3) odelling
Representin" a system usin" dia"rams
$np%t+ Process+ ,%tp%t -$P,) diagra&s
This is used to descrie the data elements that "ill enter the system7 the process that
"ill occur and the data elements that "ill lea$e the system. I%C charts can help
determine ho" data is manipulated y the computer system.
Storyboards
These are generally used !or gi$ing and o$er$ie" o! the program. They are use!ul !or
gi$ing and idea o! screen layouts and o! ho" groups or clusters o! screens relate to
each other. They can either e categorised as linear7 hierarchical7 net"or( or hyrid.
Data .low Diagra&s
These sho" the !lo" or path o! data throughout the system. They indicate ho" and
"hen data is entered7 stored7 processed and output.
Syste& .lowcharts
These enale a graphical model o! the physical system to e de$eloped7 indicating
hard"are de$ices7 the storage medium and processing units.
Screen Designs
This "ill address the issue o! the inter!ace et"een the computer and the user. I! a
screen is designed it can e implemented !rom the start instead o! right at the end.
Consideration of the %se of a li&ited prototype
This can e used so in!ormation aout the system itsel! can e gathered.
,ther Syste& representations
These are such things as decision tales and decision trees. Structure diagrams are
used to sho" the relationships et"een the $arious modules o! a program.
3.") Co&&%nication $ss%es
There are three important reasons "hy communication o! the design o! a so!t"are
solution is important to the users2
12 #he need to empoer the user
Changing "or( practices are o!ten cause !or discom!ort7 resentment and !ear.
Though "hen people !eel they ha$e control o$er the situation they !eel more
com!ortale. This "ill gi$e them aility to ma(e decisions that a!!ect their "or(.
*2 #he need to ac'noled"e the user1s perspecti)e
Through communication "ith the user the de$eloper must do e=actly "hat the user
"ants as the user is the most important person in the de$elopment cycle. Though
oth the de$eloper and user are e4ually important in gaining success.
11
/2 Enablin" and Acceptin" feedbac'
Communication "ith the user aout de$elopments5prolems is important as it
enales the user to see e=actly "hat is happening. It also allo"s oth the user and
de$eloper to critically assess each others ideas "ithout eing o!!ended.
12
Chapter 3- !lannin" and Desi"n of Softare
Solutions
".1) Design Patterns
* design pattern is a "ay o! comining programming structures into an easily
identi!ied and highly reusale group.
Sentinel: a sentinel is a special $alue that signi!ies the end o! the data. E.g.
the loc( o! "ood "e put at the end o! our groceries at the chec(out. *n
e=ample o! a sentinel code is elo"

55#esign %attern2 Sentinel-controlled7 pre-test loop
55/sage2 to process a stream o! data "ith a sentinel $alue
read the !irst datum
EHIHE :the datum is DCT the sentinel)
%rocess the datum
Read the ne=t datum
ED#EHIHE
Structured pro"rammin" and functional decomposition
It is possile to "rite an algorithm !rom start to !inish as one continuos !lo" o!
instructions. Though it has se$eral disad$antages2
The algorithm is usually long and ta(es a long time to read7 understand and
deug
There is no easy "ay to get an o$erall $ie" o! "hat the algorithm does
There is little opportunity to ta(e sections out o! the algorithm and use them in
other solutions
Instructions that occur se$eral times at di!!erent places in the algorithm need
to e re-"ritten each time they occur
The "hole solution usually ecomes less roust as it is modi!ied
Ehen algorithms are "ritten li(e this it is commonly called spa"hetti code.
Structured modules usually consist o! a main module7 !ollo"ed y many su-modules
that are acti$ated y the main module to per!orm a "ell-de!ined part o! the "or(. The
techni4ue o! rea(ing do"n a large or comple= !unction do"n into !unctions is called
4unctional decomposition2
".2) Design Concepts
Identification of appropriate modules
Cnce a main module is understood the user can then loo( to the !urther su-modules
to "or( out the rest o! the module. * ?top do"n> approach re!ers to the "ay an
algorithm is "ritten7 it is "ritten !rom the main module do"n7 "hile a ?ottom up> is
"ritten !rom the su-modules up.
1&
Identification of Inputs5 !rocesses and ,utputs
Ee must also e concerned "ith the in!ormation our algorithm processes-data. Ee
need to (no" ho" to manage this data7 "here it comes !rom7 ho" and "here to hold
it7 "here it is allo"ed to e used and ho" to !ormat it !or output.
Consideration of local and "lobal )ariables
Bariales are ;ust short names !or the 4uantities they represent.
The scope of variables
I! you create a $ariale in your main module7 you cannot e=pect to e ale to use that
$ariale throughout your su-modules and $ice $ersa. The o!!icial term in "hich a
$ariale can e used is scope2 The scope o! the $ariale is "here it can e used.
/lobal *ariables
Some programming languages allo" us to create $ariale "hich all modules can use
at the same time "ithout needing to pass their $alues around. The scope is the entire
algorithm.
#horou"h #estin"
To ma(e sure an algorithm "or(s it must e tested. This must e done y pro$iding
sample input data7 running the algorithm using this data and chec( that the output is
correct.
Des! Chec!ing
This is done y "or(ing through the algorithm line y line doing e=actly "hat the
instructions say. *ll $ariales names and $alues should e (ept updated throughout
the procedure.
Trace Tables
This simply "or(s y running through the algorithm as ao$e and entering the
outputted data into a tale. This tale is continually updated throughout the algorithm.
.ield Testing
This is testing done y not only the de$elopers ut also y a representati$e group o!
users so they can try it out under real conditions.
Prototyping
This is a prototype sumitted to a small group o! users so that !eedac( can e
pro$ided to the de$elopers.
#horou"h Documentation
#0ternal Doc%&entation
This is documentation that comes "ith a so!t"are product that enales the user to
learn "hat the product does and "hat they need to do e!ore using it. /sers can also
re!er to the documentation "hene$er they need to clear up any misunderstandings
aout the operation o! the so!t"are.
$nternal Doc%&entation
1)
This is documentation that is "ritten "ithin the algorithm itsel!. This can appear
e!ore the algorithm as a loc( or single lines o! comments that are emedded into
the algorithm.
1isting 'ss%&ptions
This can e a statement loc( at the start o! the code that signi!ies to the user "hat is
in the code and "hat has een purposely omitted.
".3) od%les and .%nctions
* !unction or module is a separate cloc( o! instructions that per!orm a "ell-de!ined
tas(. * "ell-"ritten !unction has clear input and output speci!ications. 1unctions are
the uilding loc(s o! algorithms.
6eneral Issues
Deco&position and Re%sability
Decomposition2 is the rea(ing do"n o! an algorithm into smaller chun(s that
are made into !unctions
Reusability2 once the algorithms ha$e een ro(en do"n i! they are "ritten
correctly they are ale to e ?plugged into> any other algorithm that re4uires
this tas(
.%nction 1ibraries
1unction Library2 is a large collection o! "ell-tested and reusale !unctions.
These can e included7 or ?imported> into any ne" pro;ect.
#he call and return mechanism
In all programming languages and algorithm designs7 !unction are acti$ated y
callin" them9 the algorithm acti$ates a !unction (no"n as the callin" code
:sometimes client code). The called !unction then starts "or(ing and ta(es control o!
all processing. Ehen the !unction has per!ormed its tas( and e$entually terminates7
control re$erts to the algorithm that called it7 "hich then continues on "ith its
remaining instructions.
4unction Anatomy
* correctly "ritten !unction can ha$e up to !our parts2
12 (ame- the name o! the !unction should e short7 readale and rele$ant. It
should indicate "hat the !unction does e.g. !ind3iggest
*2 Input- input to a !unction is the data passed into it y the calling code
/2 ,utput- "e output in!ormation y ?returning it>. E.g. returning ac( "ith a
$alue in a $ariale
32 +loc' of instructions
The name and loc( o! instructions are compulsory.
*nything that a !unction does is included in the body7 et"een the 3E6ID
and ED# statements.
%ocal $ariables are created7 as they are needed7 to assist "ith any
calculations or other processing.
+oolean 4unction is a !unction that returns "ith either a true or !alse $alue.
1.
".") 'rrays2 3asic Concepts
#he array concept
*n array consists o! a collection o! data and is o!!icially called a data structure2 The
array data structure holds se$eral indi$iduals $alues7 each in a separate array cell.
They are arranged in a linear structure similar to hotel rooms "ith each array cell
eing numered or inde7ed.
4a&ing and Creating 'rrays
Bariale are used to store in!ormation7 "ith each $ariale re!erring to ;ust one data
$alue. I! "e "ant to create list o! people this can ecome 4uite e=tensi$e. /sing an
array "e can store the $alues in the Iarray cell>sJ.
'rrays hold a single data type
*rrays can hold many $alues ut all o! the $alues must e o! the same type. E.g. you
cannot store a name o! a company and ho" much it earns in the same array
'rrays are of fi0ed length
The si<e or length o! an array must e speci!ied "hen the array is created. You do
not need to !ill all o! the cells o! an array !or it to "or(.
#ra)ersin" Arrays
#ra)ersin" the Array can e done y using a loop to ?iterate o$er> the entire array7
processing each $alue as its cell is $isited. This is used "hen e$ery $alue in an array
needs to e processed. E.g. !inding the largest numer.
".() 'dvanced Sorting and Searching Techni5%es
%inear Search
E=ample2 search an array !or the $alue o! 1@
'ethod2
1. start at the eginning o! the array
2. proceed along the array
&. chec( each cell>s $alue against the search $alue 1@
). "hen 1@ is !ound the cell>s inde= is the output indicating that the search $alue
has een !ound and "here it is in the array
.. i! the search $alue cannot e !ound some special $alue must e outputted to
indicate this
The linear searches are easy to understand and i! the $alue is at the start o! the array
it "ill e !ound 4uic(ly though i! the search is near the end o! the array7 the linear "ill
need to trans$erse almost all the cells. This is ine!!icient i! the array is long.
+inary Search
1or this search to "or( the $alues must already e in sorted order. The inary search
"or(s y2
1. starting in the middle o! the array
2. !inding i! the $alue is higher7 lo"er then the middle o! the array. Cr i! it is the
$alue
1+
&. it then !inds the middle o! the second hal! o! the area and !inds i! the $alue is
higher or lo"er then the middle o! the second hal!. Cr i! it is the $alue
). I continues li(e this until a $alue is !ound
I! the $alues are in sorted order this is $ery e!!icient as "e can narro" do"n 1@2&
elements to .11 in one comparison7 another "ill e 2.. elements etc. Though i! the
$alues are not in sorted order this is ine!!icient.
Insertion Sort
*n insertion sort is $ery similar to sorting playing cards in your hand in a game o!
cards. It "or(s y2
1. at the start7 the !irst element o! the array is assumed to e the sorted list
2. the second element is then put in its place in the sorted list that then consists
o! the !irst t"o elements in order
&. the third element is then put in its place in the sorted list
). in this "ay the sorted list gro"s and the unsorted part shrin(s.
+ubble Sort
* ule sort "or(s y2
1. eginning at the start o! the array
2. compares the !irst t"o cells and s"apped i! not in sorted order
&. it then compares the ne=t t"o cells :inde= 2 and &) and they are s"apped i!
not in sorted order
). This continues until the largest numer is at the end
.. It "ill then restart !rom the start o! the array again
Selection Sort
* selection sort "or(s y2
1. placing a mar(er at the !irst cell in the array
2. search through the array !rom that point on"ards loo(ing !or the smallest
$alue
&. a!ter it is !ound it is s"apped "ith the mar(ed cells $alue. This naturally
ma(es the smallest numer at the start o! the array
). 'o$e the mar(er to the ne=t cell and repeat the process
.. Ehen the mar(er reaches the last cell it is sorted
".6) String Processing
The "ord strin" means ?a string o! characters>7 one character a!ter another7 !orming
a se4uence. It re!ers to a se4uence o! characters that !orm a "ord7 a sentence7 a
name7 or a message.
Concatenate
Concatenate simply means to ;oin together. * common tas( in programming is to ;oin
t"o "ords together to !orm a single result.
8ords and Sentences
To ;oin ) "ords "e need to concatenate them7 "ith a space et"een each ut no
space at the end.
1,
Standard strin" processin" functions
tri&String
* !unction ?trimString> is used to remo$e all the spaces !orm the !ront and the rear o!
a string- only leading and trailing spaces.
co&pareStrings
This !unction accepts t"o strings and compares them to see "hich one "ould come
!irst in alphaetical listing. I! it returns2
1 2 the !irst string comes a!ter the second
-1 2 the second string comes a!ter the !irst
@ 2 the t"o string are identical
to1owerCase+ to)pperCase
These t"o !unctions con$ert all the characters o! any string into lo"er case or upper
case. They return a string that contains a ne" $alue o! the argument. They are $ery
straight !or"ard.
stringContains
This !unction ta(es t"o string as arguments and chec(s i! the !irst string contains the
second. I! the !irst string does contain the second the !unction returns ?true>7
other"ise it returns ?!alse>
1-

You might also like