W3 Lec2
W3 Lec2
20/10/2020 www.iefr.edu.pk
Today’s Agenda
• Review: Last Lecture
• Stack Application: Reverse Polish Notation (RPN)
• Circular Queue
20/10/2020 www.iefr.edu.pk
Algorithm Complexity-Rview
• Asymptomatic Notation: Mathematical representation of time
complexity
• Prior-analysis of algorithm (without execution)
• Lower Bound, Upper Bound, Best Case, Worst Case, Average Case, Exact
Time, etc.
• No. of times a function is called/statement executes/statements
• Notations: Big oh (O), Big omega (Ω), Big theta (θ)
• Example: last lecture (kx2, x, x+x2 etc. )
20/10/2020 www.iefr.edu.pk
Array-Review
• Contiguous area of memory / Consecutive memory locations
• Consisting of equal-size elements
• Indexed by contiguous integers
• Previously learned, times for operations: Access any element, Add, Remove
Type Arr_Name[]=
Arr_Index 1 2 3 4 5 6 7 8 9 10
20/10/2020 www.iefr.edu.pk
Examples-Review
• Write a program to print table of input number?
• Write a program of input range of length 10 to print tables of each
number. Hint: input 11-20 (print tables of 11, 12, 13….20) ?
20/10/2020 www.iefr.edu.pk
Stack Application
Precedence
Infix to RPN
A+B * ( C – D )
A B C D - *+
-
(
*
+
Stack
20/10/2020 www.iefr.edu.pk
RPN: Practice
• F=a*c k / p-q*g (h-b)
Operands:F a c k * p q / g h b - *-=
Operators’ Stack:
F=5*23 / 8-6*4(5-3)
20/10/2020 www.iefr.edu.pk
Circular Queue
Type Arr_Name[]=
Arr_Index 1 2 3 4 5 6 7 8 9 10
P1 P2
P2=Push ()
• Over write P1=Pop()
• Re-initialize P1=P2=> ARRAY EMPTY
• No overflow
• No underflow
20/10/2020 www.iefr.edu.pk
Discussion and Question
20/10/2020 www.iefr.edu.pk
Assignment
• Write a program for bank where, a queue of 15 people is formed. The
service requires at least two time visit at counter. You need to make a
automated announcer to call the applicants on counter.
20/10/2020 www.iefr.edu.pk