Week 2
Week 2
Another card ?
And card NOT
FOUND
NO - STOP
.
. STOP THE ITERATION WHEN CARD FOUND :
.
CONDITIONALLY TERMINATING AN ITERATION
CORRECT YES FOUND = TRUE NO MORE STEPS WILL BE IMPLEMENTED
CARD ?
NO
.
.
.
Max. in single iteration (also doing filteration at the same time) initialize the var. max. = 0 … and store the
highest value you found while iterating through dataset
TYPES OF NODES :
?
START END TERMINAL NODES
Max. = 0, card-id = -1
More cards in
no
pile-1? END
false
MARKS>max.?
true
Structured code/function
Pseudocode
• It is the textual representation of a code/program
• Step 0 – START
• Step-1 count = 0
• Step-2 if no cards in pile 1 go to step-5
• Step-3 pick a card from pile-1 Textual representation of code
• Step-3 put it in another pile
• Step-4 increment count
• Step-5 END
Start
Count = 0
While(if more cards in pile-1) {
Pick a card from pile-1
THIS IS HOW A CONDITION
Put card in pile-2
‘WHILE’ WORKS – do something
while happening something
Increment count
}
end
• PSEUDOCODE FOR ITERATION WITH FILTERING :
• SUM = 0
• While(more cards in pile-1) {
• Pick a card from pile-1
• Move card to pile-2
• If(card-gender == M){ Conditional execution
• SUM = SUM + card’s marks}
• }
Equality == , assignment =
• For student(girl and boy seperately) having maximum sum of marks in maths : start
Mathboy = 0
• Mathboy = 0
• Mathgirl = 0 Mathgirl = 0
• While(pile-1 has more cards) {
no
• Pick a card from pile-1 More cards? end
• If (card is of boy){ yes
Pick a CARD FROM PILE 1
• Mathboy = mathboy + cardmarks
• } Mathgirl = mathgirl+card no boy’s card?
marks
• Else{
Mathboy =
• Mathgirl = mathgirl + cardmarks mathboy+card marks
• }
• }
• Fcount = 0
• Mcount = 0
• While(pile -1 has more cards){
• Pick a card from pile-1 and read it
et
• If(X.towncity == “madurai” AND X.gender == female){ ta s
da
• Fcount = Fcount + 1 ores
sc
• } i in
d ura
• Else{ Ma
m
• Mcount = Mcount+1 t fro
un
• } e co
l
fe ma
• Move X to pile-2 for
ode
• } c
u do
e
Ps
PROBLEMS