Lecture 1 -The Role of Algorithms.ppt

advertisement
The Role of Algorithms
Introduction to Algorithms
Jeff Chastine
Algorithms
• Studying algorithms is about studying
efficiency
• How fast does it run?
• Can I make it run faster?
Jeff Chastine
Algorithms
• An algorithm is any well-defined
computational procedure that takes
some input and produces output
• A sequence of steps
• An algorithm is correct if for all input, it
halts with the correct output
• We say that a correct algorithm solves
the computational problem
• An incorrect algorithm may not halt!
Jeff Chastine
Example: Sorting Problem
• Input: A sequence of n numbers
<a1, a2, …, an>
• Output: A permutation <a'1, a'2, …, a'n> of the
original such that a'1 ≤ a'2 ≤ … ≤ a'n
• Sorting is fundamental to computer science,
so we’ll be studying several different solutions
to it
Jeff Chastine
The Challenge
•
•
•
•
•
•
Suppose we have 1 million numbers to sort
Your computer executes 100 million ips
Mine executes 1 million ips
You have optimized compiler (take hit of 2)
I have crummy compiler (take hit of 50)
You use insertion sort (n2), I use merge sort (n log n)
2 (106)2 instrs
108 instruction/sec
= 20,000 secs ≈ 5.56 hours
50(106lg 106) instrs
106 instruction/sec
= 1,000 secs ≈ 16.67 minutes
Jeff Chastine
Jeff Chastine
Problems to Think About…
• Searching large amounts of information
• Most efficient path from A to B (how many
routes are there?)
• Find a convex hull that contains all points
• Travel to a series of points and return home
• Best way to schedule classes
• Impossible to solve problems?
Jeff Chastine
What you’ll be studying
•
•
•
•
•
•
•
The Design and Analysis of Algorithms
Growth of Functions
Recurrences
Heapsort, Quicksort, Counting Sort…
Medians and Order Statistics
Elementary Data Structures
Hashing
Jeff Chastine
What you’ll be studying
•
•
•
•
•
Binary Search Trees
Dynamic Programming
Greedy Algorithms
Amortized Analysis
Elementary Graph Algorithms
Jeff Chastine
What you’ll be studying
•
•
•
•
•
Minimum Spanning Trees
Single-Source Shortest Paths
All-Pairs Shortest Paths
NP-Completeness
Approximation Algorithms
Jeff Chastine
A Most Excellent Quote
“Having a solid base of algorithmic
knowledge and technique is one
characteristic that separates the truly skilled
programmers from the novices.”
Jeff Chastine
The Proof
(and why you should pay attention)
• http://www.geeksforgeeks.org/
Jeff Chastine
Download