15 views

Uploaded by Kunal Arora

assignment

save

You are on page 1of 3

ASSIGNMENT-1

1. Rank the following Functions

7n

3

+3n

4n

2

n

12log(n)/log(n)

1/n

2

+18n

5

n

8

621909

e

n log log

2

n 3

6nlogn

n!

2. f(n)=7n+8 and g(n)=n. Is f(n)O(g(n)) ?

3. Consider method cal below, the call cal(5) evaluates to 15.

public int cal(int n){

if (n == 0) return 0;

return n + cal(n-1);

}

Write the recurrence relation

Using big-Oh what is the running time of the call cal(n)? Justify your answer.

Using big-Oh what is the value returned by the call cal(n) (note: complexity of

value returned, not running time: use big-Oh)

Using big-Oh what is the running time of the call cal(cal(n)) based on your

answers to the previous Two questions. Justify.

Using big-Oh what is the value returned by the call cal(cal(n)) (again, based on

previous answers, justify).

4. What is the value returned by the call ada(802) where the method ada is below.

Justify your answer.

public static int ada(int n){

int sum = 0;

for(int k=1; k <= n; k = k * 2) {

sum += k;

}

return sum;

}

What is the runtime complexity of the call ada(N)? Justify your answer.

What is the runtime complexity of the call ada(N*N*N*N)? Justify your answer.

5. Write an algorithm to count the number of common elements in two one

dimensional arrays A{1…m} and B{1..n}. What is the number of comparisions

made by your algorithm.

6. Calculate Frequency count for time and space for the following

a) ifstream filein;

filein.open("datafile.dat", ios::in);

int a[max];

int j, k=0,h;

filein >> j;

while (filein) {

a[k] = j;

k++;

filein >> j;

}

filein.close( );

b) int b,c,d;

for (int x=0; x<5; x++)

for (int y=0; y<4; y++) {

b = x * y;

cout << b;

}

7. Solve the recurrence

a) T (n) =2T (

n ) + logn

8. Fibonacci series is defined as follows:

f(0) = 0

f(1) = 1

f(n) = f(n-1) + f(n-2)

Find an iterative algorithm and a recursive one for computing element number n

in Fibonacci series, Fibonacci(n).

Analyze the running-time of each algorithm.

9. A list x

1

, x

2

, x

3

, …, x

n

is said to be cyclic sorted if the smallest number in the list

is x

i

for some unknown i, and the list x

i

, x

1 i

,x

n

,x

1

,x

2

,….x

1 i

is sorted. As an

example 4, 5,1,2,3 is a cyclic sorted. Given a cyclic sorted list of n numbers,

design and analyze an algorithm for finding a particular numbers in the list.

10. Explain and verify the analysis of Quick sort in worst and best case.

11. Fibonacci series is defined as follows:

f(0) = 0

f(1) = 1

f(n) = f(n-1) + f(n-2)

Find an iterative algorithm and a recursive one for computing element number n

in Fibonacci series, Fibonacci(n).

Analyze the running-time of each algorithm.

12. Explain significance of Huffman codes. Also explain Prefix codes. Draw code

tree according to Huffman for the following file with symbol's frequencies are as

follows: (A 24), (B 12), (C 10), (D 8), (E 8) .Write code, code length, and total length

for the tree you drawn.

13. Give the proof of Master theorem

14. Solve

- DAAUploaded byabcjohn
- Lower Bound TheoryUploaded byMuzafar Ahmad Bhat
- General Crypto 2010.PsUploaded byAnonymous djehoZ8
- perfect portfolioUploaded byapi-310050973
- MCS-021 December 2014 [WWW.IGNOUASSIGNMENTGURU.COM].PDFUploaded byAshik
- lab13Uploaded byBalls Mahoney
- ReportUploaded bydittos2384
- ited.5.2.25.pdfUploaded byLê Thị Phương Viên
- Hampapur NiUploaded byPradeep Kumar
- Sorting and SearchingUploaded byDavi Teodoro
- Hw 2 SolutionsUploaded bydon504
- Lecture 14 Asymptotic Analysis ContinuedUploaded byArial96
- 79-314-1-PBUploaded byjohnoftheroad
- binary searchUploaded bypetejuan
- hartigan_1979_kmeans.pdfUploaded byHacen Spy
- teunter et al 2006Uploaded byAlbert Wagelmans
- a2 andrew emrazianUploaded byapi-240736473
- Emacs Tutorial ReferenceUploaded byyogeshwani
- Algorithms for computing the min-transitive closure and associated partition tree of a symmetric fuzzy relationUploaded bylacnort
- Michelangelo 3 DOF Sketching RobotUploaded byUttam Grandhi
- Assignment2 SolutionUploaded byTran Trung
- Linear ProgrammingUploaded byaj18_leo
- Polyline to Polygon MatchingUploaded bySoundar Msr
- 10.1.1.107Uploaded byAmol Bengiri
- 1-s2.0-S0305054802000746-mainUploaded bynikhilrane91_7522800
- Latex Cheatsheet TemplateUploaded byHossam Nabil
- 1002.pdfUploaded bycyrcos
- Daa Course File Final 2012Uploaded bygurusodhii
- TimeGlider TutorialUploaded byDidina Ratiu
- CST 370 Final ExamUploaded byJosh Jones

- Compiler FileUploaded byKunal Arora
- Microwave NotesUploaded byKunal Arora
- 1-webUploaded byKunal Arora
- Multimedia Presentation - PC VideoUploaded byKunal Arora
- ex6Uploaded byKunal Arora
- input.txtUploaded byKunal Arora
- EWD1036.PDFUploaded byKunal Arora
- 01 CommunicationUploaded byKunal Arora
- Interval Selection EnglishUploaded byKunal Arora
- lect7Uploaded byKunal Arora
- MultimediaUploaded byKunal Arora
- Virtual reality presentationUploaded byKunal Arora
- Clarkson SolutionsUploaded byKunal Arora
- 1-webUploaded byKunal Arora
- Mirza ThesisUploaded byKunal Arora
- jk-singh-ece-section-1.docUploaded byKunal Arora
- ex1Uploaded byKunal Arora
- ReadmeUploaded byKunal Arora
- Binary TreesUploaded byKunal Arora
- STL Quick Reference 1.29Uploaded byKunal Arora
- Getting Started in Sport of ProgrammingUploaded byKunal Arora
- Lecture 8Uploaded byKunal Arora
- 5566219 100 Great Puzzles to Sharpen Your Brainwith Detailed AnswersUploaded byKunal Arora
- nsit cut-off round 1Uploaded byKunal Arora
- it 4th_newUploaded byKunal Arora
- ex2Uploaded byKunal Arora
- Allotment 1.pdfUploaded byKunal Arora
- Generic Resume TemplateUploaded byKunal Arora
- File_9Uploaded byKunal Arora