0% found this document useful (0 votes)
32 views9 pages

Week 2

Uploaded by

Mahesh Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views9 pages

Week 2

Uploaded by

Mahesh Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Conditional termination in iteration :

 Stop the iteration when the desired condition is fulfilled


 # stopping the iteration in between when required work is done
 # suppose we want a student from record dataset who has scored >90 in all subjects
 Found = false

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

 For longest we initialize max to 0


 And for shortest we initialize min to a custom number which is out of range in dataset
 *multiple filtering with one iteration can be done*
• Make every-time a new variable if you want to count / sum new objects

• Initialization of variable  use the integer or text in var. initialization


• Which is not in the given dataset …. Name : none(it doesn’t exist) ,

TYPES OF NODES :

?
START END TERMINAL NODES

PROCESS PROCESS NODE

DECISION DECISION MAKING NODE


START
Finding max. marks with card-id also (in scores dataset)

Max. = 0, card-id = -1

More cards in
no
pile-1? END

PICK A CARD FROM PILE-1

false
MARKS>max.?

true

Max. = marks, card-id =


marks’s card id

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

You might also like