CH 1 - PROBLEM SOLVING (Module 1) Flashcards
5 steps of problem solvin cycle
- analyzin the problem
i. understand the problem well
ii. amalyze the problem - developin an alorithm
i. think of possible solutions
ii. follow a modular approavh
iii. identify operations for solutions - codin
i. code program using appropriate control structures - testin and debuin
i. test and debu
ii. complete your documentation - maintaining and implementin
i. implement your code
ii. maintain your proram
what is codin
codin is the technical word fro writin a proram. thji step is to translate the aloritm into a prora,min lanuae
testin
estin is the process of findin errors in the proram
debuin
the process of correctin errors found durin the testin process
documentation
it is intended to allow another person or prorammer to understand the proram at a later date
miht also conain a adetrailedx description of what the proram does and how to use the proram
maintainin a aproram
involves modifiyin the prorams to emove previuouly undetected errors, to enhance the proram with different features or functionality, keepin the proram up to date with ivernment reukationso rcompany policies
decomposition
the process of breakin down a bi or complex problems into a set of smaller sub processes to allow us to describe, understand or execute the problem better
2. breakin a lare problem into more manaeable sub problems
what does decomposition involve
- dividin a task into a sequence of subtasks
2. identifyin elemts or parts of a complex system
what is the need of decomposition
lare problems are disproportionately harder to solve than smaller problems
algorithm
the set of rules that define how a particular problem can be solved in finite number of steps
-contains finite steps each of which may require one or more operations
constraints on type of operations an alorithm van include
- each operation must be DEFINITE
- must be clearly defined what should be done
- cant say add 3 and a, since the operation is not defined - each operation must be EFFECTIVE
- each step should also be able to be done by pen and paper in finite amount of time
- arithmetic operators on interes are effective but on real numbers, its not effective
since vales come in infinitely lon decimal expansions - each operation must be FINITE
- the alorithm should terminate after a finite number of operations
characteristics of a good algorithm
- PRECISION - steps should be precisely define
- UNIQUENESS - every step should uniquely contribute to the algorithm
- result of a step is unique and depends on input and the results of the previous steps before it ONLY - FINITENESS - must be finite and should terminate
- INPUT - algorithm requires specific input to work on
- OUTPUT - algorithm produces output as per input received and stated objectivities
- OUTPUT -
components of an algorithm
- INPUT - provoided by user or elf obtained like readin from a file
- PROCESSIN -
- OUTPUT - the objective of the algorithm
program and algorithm relation
a program is the expression of an algorithm in a prorammin lanuae
algorithm can be expressed in what ways
- FLOWCHART
2. PSEUDO - CODE
FLOWCHART
functions of flowcharts
- pictorially depicts the sequence in which instructions are carried out in an algorithm
- used as an aid in developing algorithms
flowchart symbol - OVAL
start and stop
flowchart symbol - PARALLELORAM
input and output
flowchart symbol - RECTANLE
processin
flowchart symbol - DIAMOND
decision box
flowchart symbol - CIRCLE
connector ???
—–>—- and upward arrow
flow of control symbol
_
I
———-
I_
annotation
pseudo code
it is an informal lanuae
- helps programmers describe steps of a proram’s solution without usin any prorammin lanuae syntax
- it is a text based detail alorihmic dein tool
- creates an outline or rouh draftof a proram that ives the idea od how the alorithm works and how conrol flows from one step to another
notes of pseudo code
- there are NO STANDARD RULES o write a pseudocode
2. TOTALLY INFORMAL WAY of representin an alortihm
advantages of a pseudo code
- uses elish - easy to understand
- hih;hts the seuqnce of instructions
- structure of alorithm is clealry visible
- for ex: selection and repetition blocks - can be easily modified sinc no dependncies
disadvantes of pseudo cod
- not a visual tool like flowchart
- no standardization - varies from coder to coder
- can only be tested on paper, no program to test it
- informal representation of an algorithm
verifyin an alorithm means?
to ensure that the alorithm is workin as intended
- we should test an alorithm eith sample inputs for which we know the outputs
DRY RUN
process of a prorammer manually workin throuh their code to trace the value of variables. no software involved in this process
how is dry run done
- print out of code
- coder uses pen and paper and manually follow the value of a variable to check that it was used and updated as expected
- if works incorrect, cder finds out error
characteristics of a dry run
- carried out durin desin, implementation, testin or maintennace
- used to identify the logic error in a code
- cannot find the execution error in a code
trace tables
used in dry run of code
- each line of codeis seen on the values of variables of the alorithm
comparin alorithms main factor
to decde which alorithm to choose over, EFFICIENCY is the main factor
major factors that overn the efficiency of an alorithm are
- th etime it takes to find the solution
2. the resources which are consumed in the process
two type of efficiences that are decidin factors for chosin alorithms
- SPACE WISE EFFICIENCY - how much amt of memory the algorithm will take before it terminates
- thus we consider the amt of data the alo uses when runnin - TIME WISE EFFICIENCY - how muchtime alo takes to complete
- this factor depends on:
i. RAM available ii. prorammin lanuae iii. hardware platform etc