algorithmFall09

# algorithmFall09 - Algorithms An algorithm is a sequence of...

This preview shows pages 1–3. Sign up to view the full content.

Algorithms An algorithm is a sequence of computational steps that transform some input into some output. It is a tool for solving a well-defined computational problem. Examples of such problems --- searching, sorting Searching Linear Search Algorithm -- looks sequentially at each element of a given collection of elements until we either come to the end of the sequence of elements or find an item that equals to X (the element that we are searching for). public int linearSearch(int[] A, int x) { constant time to execute times to execute for (int i=0; i<A.length, i++) C1 n+1 times { if (A[i] = = x ) C2 n times return i; C3 0 or 1 time } return (–1); // returns –1 when the element is not found C4 1 or 0 time } The complexity of Linear Search Algorithm is order of n ( O(n) ), where n is the number of elements. The running time T(n) is bounded by C1*(n+1) + C2*n + C3 + C4 = (C1+C2)*n + (C1+C3+C4), it is a linear function of n.

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

View Full Document
O-notation -- upper bound The (worst case) running time of the linear search can be expressed as a function of n, where n is an input size. T(n) = c1 * n + c2 where c1 and c2 are positive constants. Intuitively, we can see that when n, input size, gets larger, the time that takes to execute the linear search grows.
This is the end of the preview. Sign up to access the rest of the 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