# Lecture25 - Engineering Analysis ENG 3420 Fall 2009 Dan C...

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

1 Engineering Analysis ENG 3420 Fall 2009 Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 11:00-12:00

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

View Full Document
2 2 Lecture 25 Lecture 25 Attention: The last homework HW5 and the last project are due on Tuesday November 24!! Last time: Cubic splines Today Searching and sorting Numerical integration (chapter 17) Next Time Numerical integration of functions (chapter 18).
3 Search algorithms Find an element of a set based upon some search criteria. Linear search : Compare each element of the set with the “target” Requires O(n) operations if the set of n elements is not sorted Binary search : Can be done only when the list is sorted. Requires O(log(n)) comparisons. Algorithm: Check the middle element. If the middle element is equal to the sought value, then the position has been found; Otherwise, the upper half or lower half is chosen for search based on whether the element is greater than or less than the middle element.

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

View Full Document
4 Sorting algorithms Algorithms that puts elements of a list in a certain order, e.g., numerical order and lexicographical order. Input: a list of n unsorted elements. Output: the list sorted in increasing order. Bubble sort complexity: average O(n 2 ); )); worst case O(n 2 ). Compare each pair of elements; swap them if they are in the wrong order. Go again through the list until no swaps are necessary. Quick sort complexity: average O(n log(n)); worst case O(n 2 ). Pick an element, called a pivot , from the list. Reorder the list so that all elements which are less than the pivot come before the pivot and all elements greater than the pivot come after it (equal values can go either way). After this partitioning, the pivot is in its final position. Recursively sort the sub-list of lesser elements and the sub-list of greater elements.
5 Sorting algorithms (cont’d) Merge sort – invented by John von Neumann: 1. Complexity: average O(n log(n)); worst case O(n log(n)); 2. If the list is of length 0 or 1, then it is already sorted. Otherwise: 3. Divide the unsorted list into two sublists of about half the size. 4. Sort each sublist recursively by re-applying merge sort. 5. Merge the two sublists back into one sorted list. Tournament sort : Complexity: average O(n log(n)); worst case O(n log(n)); It imitates conducting a tournament in which two players play with each other. Compare numbers in pairs, then form a temporary array with the winning elements. Repeat this process until you get the greatest or smallest element based on your choice.

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

View Full Document
6 Integration Integration: is the total value, or summation, of f ( x ) dx over the range from a to b : I = f x (29 a b dx
7 Newton-Cotes formulas The most common numerical integration schemes. Based on replacing a complicated function or tabulated data with a

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

### Page1 / 31

Lecture25 - Engineering Analysis ENG 3420 Fall 2009 Dan C...

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

View Full Document
Ask a homework question - tutors are online