Lecture#3
Power Set:
- [denoted by P(s)]
Power set is the set of ALL subsets in S
e.g. S1 = {a, b} and P (S1) + {Ǿ, {a}, {b}, {a, b}}
S2= {a, b, c} P (S2) =?
|S| = the number of elements in S.
If |S| = x, then |P(S)|=2n (Why?)
Proof: - (by induction)
S= {} P(S) = {{}} |S|=0 |P(S)|=20=1
S= {1} P(S) = {Ǿ, {1} |S|=1 |P(S)|=21=2
We assume that if |S|=n
then |P(S)|=2n
Now if we add another element (K) to S (call it S1) |S|=n+1
Since SCS1 therefore P(S) c P(S) [we have 2 elements in P(S)]
Now if we add K to all these subsets, we get the remaining subsets.
These new subsets are also 2n in number.
The total number of subsets we have =2n + 2n = 2.2n=2n+1 (proved).
Alphabet:-
Consider Σ = {a, b, c, d, e x, y, z} [Alphabets in the English language]
Dictionary: - (Σ+) A dictionary is a set of consisting of all strings of letters from Σ e.g. cat, Mickey mouse ..
If Σ ={0,1} , Σ+={0,1,00,01,10,11,000,010 .}
A= [WΣ+} [A is the set containing words taken from Σ+ OR AC Σ+}
A= {WΣ+}: length of w =4} [A contains words from Σ + such that length of w=4]
A= {0000,0001,0010,0011,0100,0101,0110,0111,1000,1010,1010,1100,1101,1110,1111}
|A| = 19 = 2 4
Size of Σ+ is infinite.
Is A a function?
To define a function, we need two sets.
We need a set A1 {Domain of the functionf1}
We need a set B1 {co-domain of the function f1}
R1=A* B may be a function.
A= {1, 2, 3, 4, 5} B= {a, b, c}
R1={1,a) , (2,b) , (3,c) , (4,c) , (5,c)}
Or f1(1)=a f1(2)=b f1(3)=c F1(4)=c F1(5)=c
Q: Draw a graph of this function.
a) Is this one-to-one?
b) Is this onto?
c) Is this a function?
Range of f1 = {a, b, c}
Range is the sum (or UNION) of all the images.
A function is ONTO if and only if ragne = co-domain.
B2 = {a, b, c, d}
f1: A1 ΰ B1
f1: A1 ΰ B2 What type of functions are these?
f1: A2 ΰ B1
This means that A1 has images on B1 as defined by f1.
Length
Function
All words in the dictionary are as follows:
Length (Sadaf) = 4
Length (Fahd) = 5
Length (Fawad)= 7
What is the domain?
What is the range?
Is this a function?
Is this one to one?
Is this onto?
Q) Write down the following four types of functions:
a) 1-1 and onto
b) 1-1 but not onto
c) not 1-1 but onto
d) neither 1-1 nor onto
----------------------------------------
Insertion Sort
No of steps required: O(n2)
Merge Sort
No of steps required: O(nlogn)
-----------------------------------------
Technology will affect the constants of run time. Fast / Slow machines may also affect these. Compiler, programmer will also have some impact.
Two interesting scenarios are as follows:
1) Fast Computer
Smart Programmer
K=2
2n2 instructions
109 instructions / second
2) Slow Comuter
Stupid programmers
K=50
50 n log n instructions
107 instructions / second
Time to sort 106 instructions = ? (The constant of proportionality is simply redundant or irrelevant?)
Q: Draw the graphs for n, n2, log n.
![]()


Q: Find the maximum out of n elements:
1) problem statement
2) Input [n elements]
3) Output [maximum out of n numbers]
4) Basic idea (in plain English)
5) Pseudo code
6) Analysis
[Neither plane language nor java code. This should be more mathematical with lots of comments] .Usually run time analysis.
( n^2 is the easier to type version of n2 J )
An algorithm should terminate after performing steps polynomial in the size of n. e.g. O(n), O(n^2), O(n^3), O(log n) .
If it is exponential, e.g. O(2^n) then it is not an algorithm.
Correctness Issues:
The algorithm should be exact e.g. in the problem to find the maximum in x elements, the answer must be the maximum element and not the second or third largest element.
Q) Why an algorithm should be polynomial in n?
A) If it isnt then it will take centuries to solve the problem for a reasonable amount of n.
Q)
a) Can we reduce the complexity of finding the maximum element?
b) Can it be less than O(n)?
c) Do we have to look at all the numbers?