CSE 321-Introduction to Algorithms Homework 1 solution

$24.99

Original Work ?

Download Details:

  • Name: HW1-mkdutj.zip
  • Type: zip
  • Size: 1.72 MB

Category: You will Instantly receive a download link upon Payment||Click Original Work Button for Custom work

Description

5/5 - (3 votes)

1)
For each of the following statements, specify whether it is true or not. Explain your
reasoning for each of them.
a) log2 𝑛
2 + 1 ∈ Ο(𝑛)
b) βˆšπ‘›(𝑛 + 1) πœ– Ξ©(𝑛)
c) 𝑛
π‘›βˆ’1
πœ– πœƒ(𝑛
𝑛)
d) 𝑂(2
𝑛 + 𝑛
3
) βŠ‚ 𝑂(4
𝑛
)
e) 𝑢(2 log3 βˆšπ‘›
3
) βŠ‚ 𝑂(3 log2 𝑛
2
)
f) log2 βˆšπ‘› and (log2 𝑛)
2
are of the same asymptotical order.
2) Order the following functions by growth rate and explain your reasoning for each of them.
𝑛
2
, 𝑛
3
, 𝑛
2
log 𝑛, βˆšπ‘›, log 𝑛, 10𝑛
, 2
𝑛
, 8
log𝑛

3) What is the time complexity of the following programs? Explain by giving details.
a)
void f( int my_array[]){
for(int i=0;i<sizeofArray;i++){
if(my_array[i]<first_element){
second_element=first_element;
first_element=my_array[i];
}
else if(my_array[i]<second_element){
if(my_array[i]!= first_element){
second_element= my_array[i];
}
}
}
}
b)
void f(int n){
int count=0;
for(int i=2;i<=n;i++){
if(i%2==0){
count++;
}
else{
i=(i-1)i;
}
}
}
4 ) Find the complexity classes of the following functions using the integration method.
a) βˆ‘ 𝑖
2
log 𝑖
𝑛
𝑖=1
b) βˆ‘ i
n 3
i=1
c) βˆ‘ 1/(2βˆšπ‘–)
n
i=1
d) βˆ‘ 1/𝑖
n
i=1
5) Find the best case and worst case complexities of linear search with repeated elements,
that is, the elements in the list need not be distinct. Show your analysis.