Professional Documents
Culture Documents
Prepared by:
kashafAd-Dooja
2
Course Objectives
Reinforce the concept that costs and benefits exist for every data structure.
Following contents will be covered throughout the semester in week wise lectures:
Abstract data types, complexity analysis, Big Oh notation, Stacks (linked lists and array
implementations), Recursion and analyzing recursive algorithms, divide and conquer
algorithms, Sorting algorithms (selection, insertion, merge, quick, bubble, heap, shell, radix,
bucket), queue, dequeuer, priority queues (linked and array implementations of queues),
linked list & its various types, sorted linked list, searching an unsorted array, binary search for
sorted arrays, hashing and indexing, open addressing and chaining, trees and tree traversals,
binary search trees, heaps, M-way tress, balanced trees, graphs, breadth-first and depth-first
traversal, topological order, shortest path, adjacency matrix and adjacency list
implementations, memory management and garbage collection.
Consider the expression A+B: we think of applying the operator “+” to the
operands A and B.
Writing the sum as A+B is called the infix form of the expression.
76
Prefix, Infix, Postfix
+ A B prefix
A B + postfix
Conversion to postfix
(A + B ) * C infix form
(AB + ) * C convert addition
(AB + ) C * convert multiplication
AB + C * postfix form
19
Precedence of Operators
A B C means A ( B C )
21
Infix to Postfix
Infix Postfix
A+B AB+
12 + 60 – 23 12 60 + 23 –
(A + B)*(C – D ) AB+CD–*
A B * C – D + E/F A B C*D – E F/+
22
Infix to Postfix
Stack s;
while( not end of input ) {
e = get next element of input
if( e is an operand )
s.push( e );
else {
op2 = s.pop();
op1 = s.pop();
value = result of applying operator ‘e’ to op1 and op2;
s.push( value );
}
}
finalresult = s.pop();
25
Evaluating Postfix
Evaluate 6 2 3 + - 3 8 2 / + * 2 3 +
Input op1 op2 value stack
6 6
26
Evaluating Postfix
Evaluate 6 2 3 + - 3 8 2 / + * 2 3 +
Input op1 op2 value stack
6 6
2 6,2
27
Evaluating Postfix
Evaluate 6 2 3 + - 3 8 2 / + * 2 3 +
Input op1 op2 value stack
6 6
2 6,2
3 6,2,3
28
Evaluating Postfix
Evaluate 6 2 3 + - 3 8 2 / + * 2 3 +
Input op1 op2 value stack
6 6
2 6,2
3 6,2,3
+ 2 3 5 6,5
29
Evaluating Postfix
Evaluate 6 2 3 + - 3 8 2 / + * 2 3 +
Input op1 op2 value stack
6 6
2 6,2
3 6,2,3
+ 2 3 5 6,5
- 6 5 1 1
30
Evaluating Postfix
Evaluate 6 2 3 + - 3 8 2 / + * 2 3 +
Input op1 op2 value stack
6 6
2 6,2
3 6,2,3
+ 2 3 5 6,5
- 6 5 1 1
3 6 5 1 1,3
31
Evaluating Postfix
Evaluate 6 2 3 + - 3 8 2 / + * 2 3 +
Input op1 op2 value stack
6 6
2 6,2
3 6,2,3
+ 2 3 5 6,5
- 6 5 1 1
3 6 5 1 1,3
8 6 5 1 1,3,8
32
Evaluating Postfix
Evaluate 6 2 3 + - 3 8 2 / + * 2 3 +
Input op1 op2 value stack
6 6
2 6,2
3 6,2,3
+ 2 3 5 6,5
- 6 5 1 1
3 6 5 1 1,3
8 6 5 1 1,3,8
2 6 5 1 1,3,8,2
33
Evaluating Postfix
Evaluate 6 2 3 + - 3 8 2 / + * 2 3 +
Input op1 op2 value stack
6 6
2 6,2
3 6,2,3
+ 2 3 5 6,5
- 6 5 1 1
3 6 5 1 1,3
8 6 5 1 1,3,8
2 6 5 1 1,3,8,2
8 2 4 1,3,4
34
Evaluating Postfix
Evaluate 6 2 3 + - 3 8 2 / + * 2 3 +
Input op1 op2 value stack
6 6
2 6,2
3 6,2,3
+ 2 3 5 6,5
- 6 5 1 1
3 6 5 1 1,3
8 6 5 1 1,3,8
2 6 5 1 1,3,8,2
/ 8 2 4 1,3,4
+ 3 4 7 1,7
35
Evaluating Postfix
Evaluate 6 2 3 + - 3 8 2 / + * 2 3 +
Input op1 op2 value stack
6 6
2 6,2
3 6,2,3
+ 2 3 5 6,5
- 6 5 1 1
3 6 5 1 1,3
8 6 5 1 1,3,8
2 6 5 1 1,3,8,2
/ 8 2 4 1,3,4
+ 3 4 7 1,7
* 1 7 7 7
36
Evaluating Postfix
Evaluate 6 2 3 + - 3 8 2 / + * 2 3 +
Input op1 op2 value stack
6 6
2 6,2
3 6,2,3
+ 2 3 5 6,5
- 6 5 1 1
3 6 5 1 1,3
8 6 5 1 1,3,8
2 6 5 1 1,3,8,2
/ 8 2 4 1,3,4
+ 3 4 7 1,7
* 1 7 7 7
2 1 7 7 7,2
37
Evaluating Postfix
Evaluate 6 2 3 + - 3 8 2 / + * 2 3 +
Input op1 op2 value stack
6 6
2 6,2
3 6,2,3
+ 2 3 5 6,5
- 6 5 1 1
3 6 5 1 1,3
8 6 5 1 1,3,8
2 6 5 1 1,3,8,2
/ 8 2 4 1,3,4
+ 3 4 7 1,7
* 1 7 7 7
2 1 7 7 7,2
7 2 49 49
38
Evaluating Postfix
Evaluate 6 2 3 + - 3 8 2 / + * 2 3 +
Input op1 op2 value stack
6 6
2 6,2
3 6,2,3
+ 2 3 5 6,5
- 6 5 1 1
3 6 5 1 1,3
8 6 5 1 1,3,8
2 6 5 1 1,3,8,2
/ 8 2 4 1,3,4
+ 3 4 7 1,7
* 1 7 7 7
2 1 7 7 7,2
7 2 49 49
3 7 2 49 49,3
39
Evaluating Postfix
Evaluate 6 2 3 + - 3 8 2 / + * 2 3 +
Input op1 op2 value stack
6 6
2 6,2
3 6,2,3
+ 2 3 5 6,5
- 6 5 1 1
3 6 5 1 1,3
8 6 5 1 1,3,8
2 6 5 1 1,3,8,2
/ 8 2 4 1,3,4
+ 3 4 7 1,7
* 1 7 7 7
2 1 7 7 7,2
7 2 49 49
3 7 2 49 49,3
+ 49 3 52 52
40
Evaluating Postfix
Evaluate 6 2 3 + - 3 8 2 / + * 2 3 +
Input op1 op2 value stack
6 6
2 6,2
3 6,2,3
+ 2 3 5 6,5
- 6 5 1 1
3 6 5 1 1,3
8 6 5 1 1,3,8
2 6 5 1 1,3,8,2
/ 8 2 4 1,3,4
+ 3 4 7 1,7
* 1 7 7 7
2 1 7 7 7,2
7 2 49 49
3 7 2 49 49,3
+ 49 3 52 52
32
Q &A
Please feel free to ask any thing related to topic covered in these slides.
Text Book:
Nell Dale : C++ Plus Data Structures, Latest Edition, Jones & Bartlett
Reference Text Books:
Data Structure using C/C++ by Mark Alan.
Yadidyah Langsam, Moshe J. Augenstein, Aaron M. Tenenbaum: Data Structures
using C and C++.
Handouts:
Dr. Sohail Aslam: Data Structures Handouts.