SDA
SDA
SDA
• Why analysis?
To determine:
its time requirement
its space requirement
its bandwidth requirement
power consumption //if the problem is to develop system programs
• Properties of algorithms
– Briefly and correctly explain.
Q. There are some algorithms that do not terminate for certain inputs.//true or false?
Algorithm…
Q. Given the growth functions:
n!,2n,2n2,5nlogn,20n,10n,2n,2n^2,5nlogn,20n,10n, what is the valueof n for
which the growth function 20n is the most efficient of the six?
A. 1
B. 5
C. 11
D. None //you cannot find such value
Q2. Arrange the above growth functions in increasing order.
Q3. Arrange the following growth functions in increasing order.
2log3 n, log2n, nloglogn, 2logn
Asymptotic notations
• Big-oh: O
• Big omega: Ω
• Theta: Ѳ
• Give formal(mathematical) definition of each.
• Their implications (interpretations)
Proving big-oh,omega and theta
• Determine i) the time complexity(derive some polynomial function) and ii) big-
oh,O for the following code fragments. Assume all variables are of type int.
• Example1
Void f(int n)
{
int i,j,k,count=0;………………………1…………….c1
for(i=n/2,i<=n;i++)……………………n+1………..c2(n+1)
for(j=1;j+n/2<=n;j++)……..n*n+1)……c3(n*(n+1))
for(k=1;k<=n;k*2)…..n^2logn…c4(n^2logn))
count++;……1*n^2logn….c5(n^2logn)
}
After adding and multiplying c’s with the terms, u will get some polynomial of degree
2 of an^2logn +bn^2 + cn+d ~the time complexity .
Therefore, the asymptotic time complexity(big-oh is O(n^2logn)
Finding time complexity using step(frequency) count method)….
createSLL();
display();
return 0;
}
And also be aware of the following…
• create(): O(n)
• Traverse(): O(n)
• insertatBeg(x): O(1)
• insertAtPos(x): O(n/2) ~O(n)
• insertatEnd(x): O(n) //need to traverse to get there
• deletefromBeg(x): O(n)
• deletefromPos(x): O(n/2)~ O(n)
• deletefromEnd(x): O(n)
• display(): O(n)
struct Node
{
int data;
Node* next;
};
Assume ,based on the node structure definition above, the following sequence of
operations were performed on the above singly linked list.
Node* P. //P is a pointer.
1. P=First->next->next
2. P->next->next->next = First
3. P=P->next->next
4. cout<<p->data
The cout statement outputs____________.//the answer is a – analyze how
a. E
b. D
c. C
d. B
struct Node
{
int data;
Node* next;
};