

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Notes; Professor: Huang; Class: DATA STRUCTR&ALGORITHMS; Subject: Computer Science & Engineering; University: University of South Carolina - Columbia; Term: Spring 2009;
Typology: Study notes
1 / 3
This page cannot be seen from the preview
Don't miss anything!


University of South Carolina
02/04/2009 2
Announcement
Reading assignment: Chapter 3.
Homework 2 due on Monday, February 9 in class
Midterm Exam 1 will be held on Friday, February 13
02/04/2009 3
Computing Fibonacci numbers
nn
for n≥ 1, assuming an efficient way of computing matrix powers.
02/04/2009 4
Another Example
Then analyze its time efficiency Basic operation: a multiplication of two numbers Two choices Nonrecursive algorithm Recursive algorithm Any idea to make it faster, e.g., with a better time efficiency? Bonus: Can we solve this problem in Θ(log^ n ) time?
02/04/2009 5
What’s next
Chapter 3: Brute Force
02/04/2009 7
wide applicability simplicity yields reasonable algorithms for some important problems (e.g., matrix multiplication, sorting, searching, string matching)
rarely yields efficient algorithms some brute-force algorithms are unacceptably slow not as constructive as some other design techniques
02/04/2009 9
and swap it with the first element. Then, starting with the second element, scan the elements to the right of it to find the smallest among them and swap it with the
A[0] ≤... ≤ A[i-1] |A[i],... ,A[min],.. .,A[n-1] in their final positions
02/04/2009 10
02/04/2009 11
Time efficiency: Space efficiency: Stability: Number of key swaps: 02/04/2009 12
exchange them if they are out of order. The first pass “bubbles up” the largest element to last position, the next pass bubbles up the second largest element, until
A[0],... ,A[j]↔ A[j-1].. .,A[n-i-1] |A[n-i] ≤... ≤ A[n-1] in their final positions
?