Tutorial 09

# Tutorial 09 - /found it if(x< arr[mid return...

This preview shows page 1. Sign up to view the full content.

p q r s t COMP2781, COMP8781, Sem. 1, 2011, Flinders University Tutorial 9 Q1. It takes 18 seconds to complete a task of size 6 for algorithm A when run on computer C. Al- gorithm A is of order n 3 . How much time would it take to complete three times bigger task on the computer C? How long would it take to complete the task on a computer ten times slower than computer C? Q2. Analyse time complexity of the binary search algorithm (implemented in Java). int binsearch(int arr[], int x, int left, int right){ if (left<=right) { int mid=(left+right)/2; if (x==arr[mid]) return mid;
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: //found it if (x < arr[mid]) return binsearch(arr,x,left,mid-1); else return binsearch(arr,x,mid+1,right); } return -1; // Failed to find ’x’ } Note how the recursive version checks to see if we are at ’x’, then it returns, otherwise it calls itself to solve a smaller problem (see also Epp, Sec. 11.5). Observe that, if a n denotes the worst-case run time, then a n = a ⌊ n 2 ⌋ + 1 , and a n ∈ O ( log n ) . Q3. Sec. 10.1, Ex. 19, 20, 33, 43 Q4. Sec. 10.2, Ex. 8, 12, 15, 18 Page 1 Last updated May 18, 2011 by M. Bajger...
View Full Document

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern