Tut_7 - out without looking back at the notes for the...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Programming & Data Structures Tutorial 7 Q1. Determine the complexity function f(n) for the following methods. What is the order O(g(n)) of f(n) ? (i) void meth1(char s[], int n) { int i, j; for (int i = 0; i<n; i++) if(s[i] > ‘A’ && s[i] < ’Z’) s[i] = ‘x’; } (ii) void meth2(int x) { int i = 1; while (i < 1000) { System.out.print(x); i = i * 2; } } (iii) void meth3(int x) { for(int i = 0; i< x; i++) { for(int j =0; j < i; j++) { System.out.print(‘*’); } System.out.println(); } } (iv) void meth4(int x) { for(int i = 0; i < x; i++) func2(i); // calling method 2 from part (ii) }
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Q 2. What is the order O(f(n)) of the following algorithms? Try to work it
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: out without looking back at the notes for the answer. - linear search - binary search - bubble sort - insertion sort - selection sort Q3. Show that 2 n 2 + 4 +3 is O(n 2 ) Q4. Now show that the above complexity function is also (n 2 ) Q5. Solve the following recurrence relations and give the big O complexity of each. (a) T(1) = 1 for N = 1 T(N) = T(N-1) + N for N 2 (b) T(1) = 1 for N = 1 T(N) = T(N/2) + 1 for N 2 (c) T(1) = 0 for N = 1 T(N) = T(N/2) + N for N 2 (d) T(1) = 0 for N = 1 T(N) = 2T(N/2) + N for N 2...
View Full Document

Page1 / 2

Tut_7 - out without looking back at the notes for the...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online