Title: Intro to Computer Algorithms Lecture 15
1Intro to Computer Algorithms Lecture 15
- Phillip G. Bradford
- Computer Science
- University of Alabama
2Announcements
- Advisory Boards Industrial Talk Series
- http//www.cs.ua.edu/9IndustrialSeries.shtm
- Departmental Colloquium
- 27-Oct, in 110 East Engineering
- Featuring Dr. Gary McGraw
- Building Secure SoftwareWhy the standard
approach to security doesn't work
3CS Story Time
- Prof. Jones research group
- See http//cs.ua.edu/StoryHourSlide.pdf
4Association of Computing Machinery
The First Society in Computing
Meeting Information Session Tuesday, October
21 Time and Place EE 119 at 500
p.m.
Join us on Tuesday for FREE FOOD and good
information Guest Speaker Beth Green,
Wal-Mart ISD Recruiting Who What is Wal-Mart
hiring?
For more info, visit www.studentacm.org
5Outline
- Transform and conquer
- Technique
- Examples
6Transform and Conquer
- Start with a problem instance PI
- Change or transform PI into SI
- Simpler Instance
- So that solving SI solves PI
- Solve the simpler SI
7Transformation in more detail
- Instance Simplification
- Make simpler or more convenient
- Representation Change
- Different representation of the same problem
- Problem Reduction
- Instance of a problem that has already been
solved
8Classic ExamplesElement Uniqueness
- Presorting
- Once a list is sorted, then it is easy to get
some forms of information from it - Element Uniqueness
- Determine if any two elements in a list are the
same - How?
- Sort and then check neighbors
- Cost?
- O(n log n) counting the sort!
9Classic ExamplesMode
- Computing the Mode of a list of elements
- What is the mode?
- Most common occurring element
- How?
- Brute force method
- For each element count how often it occurs
- Track the largest occurring element so far
10Classic ExamplesMode
- The O(n2) solution
- mode_freq ? 0
- mode_value ? 0
- run_value ? 0
- run_length ? 0
- The algorithm at the board
11Classic ExamplesMode
- A better solution using transform and conquer
- Sort first!
- Transforming the challenge into a simpler one
- Algorithm on Page 196
- Cost?
12Classic ExamplesSearching vs. Sorting
- Given the cost of comparison based sorting is O(n
log n) - The cost of searching a sorted list is O(log n)
- How many searches through a length n list do we
have to do to justify a sort?
13Gaussian Elimination
- Classic Transform and conquer
- Transformation uses row operations
- Exchange two rows
- Replace an equation with an non-zero multiple
- Replace an equation with the sum or difference of
itself and another equation - Examples at the board