Lec01-Introduction and Overview
Lec01-Introduction and Overview
and
Analysis of
Algorithms
Reference Books
• Algorithm Design by Jon Kleinberg and Éva Tardos. Addison-Wesley, 2005.
• Some of the lecture slides are based on material from the following books:
• Introduction to Algorithms by Thomas Cormen, Charles Leiserson, Ronald Rivest, and Clifford Stein. MIT Press, 2009.
• Algorithms by Sanjoy Dasgupta, Christos Papadimitriou, and Umesh Vazirani. McGraw Hill, 2006.
• The Design and Analysis of Algorithms by Dexter Kozen. Springer, 1992.
• Data Structures and Network Algorithms by Robert Tarjan. Society for Industrial and Applied Mathematics, 1987.
• Linear Programming by Vašek Chvátal. W. H. Freeman, 1983.
Grading
• Programming Assignments: 20%
• Midterm: 30%
• Final Exam: 50%
Tentative Course Outline
1. Introduction
2. Algorithms
3. Course Curriculum Overview
1. Introduction
The objective of the course is to learn practices for efficient problem solving and computing.
ü Problem Solving
- How to write a step by step procedure to solve a given problem
- What are the various paradigms of problem solving in computing à Divide and Conquer, Dynamic Programming, Greedy.
- When to choose which alternative strategy of problem solving
ü Efificiency
- How to evaluate the worst case behavior of an algorithm
- What are the various mathematical tools of algorithm analysis àAsymptotic notations, recurrance relations
- How to decide which algorithm is better
There are many, but we named a few. We’ll learn these data structures in great detail!
Array
Linked List
Queue Stack
Graph Tree
1. Introduction
Types
of
Data Structures
1. Introduction
Array
• Linear arrays are called one-dimensional arrays because each element in such an
array is referenced by one subscript.
• A two dimensional array is a collection of similar data elements where each
element is referenced by two subscripts.
1. Introduction
Stack
Stack Applications:
• Back and forward buttons in a web browser
• UNDO/REDO functionality in text editors and image editing software
• Implementing recursion in programming
• Delimiter checking
1. Introduction
fact(n) = n * fact(n-1)
n=5
5! = 120
1. Introduction
Quene
Queue (First in first out – FIFO – system) is a linear list in which
• Deletions can take place only at one end of the list, the ‘front’ of the list,
• Insertions can take place only at the other end of the list, the ‘rear’ of the list.
Quene applications
• Cashier line in a store
• A car wash line
• One way exits
1. Introduction
Tree
The data structure which reflects a hierarchical relationship between various elements, a rooted tree graph.
Employee
+ ↑
* y - 3
2 X a *
7 b
1. Introduction
Graph
Pairs of data have relationship other than hierarchy.
Example: Airline flights
1. Introduction
Both graphs and trees are structures used to represent relationships between elements,
• Trees are a specific type of acyclic graph with a hierarchical structure, a designated root, and no cycles,
• Graphs are more general and can have cycles and various types of connections.
The particular data structure that one chooses for a given situation depends largely on the frequency with which
specific operations are performed. Most frequently used operations:
• Traversing: Accessing each record exactly once so that certain items in the record may be processed.
(This accessing an processing is sometimes referred as ‘visiting’ the record.)
• Searching: Finding the location of the record with a given key value, or finding the locations of all the
records which satisfy one or more conditions.
• Inserting: Adding a new record to the structure.
• Deleting: Removing a record from the structure.
Concrete
representation. One poblem can
have many
algorithms.
2. Algorithms
Very similar problems can have very different complexity. Recall: Complexity
Class Characteristic feature
• P: class of problems solvable in polynomial time. O(nk) for P Easily solvable in polynomial time.
some constant k.
- Shortest paths in a graph can be found in O(V2) for example. NP Yes, answers can be checked in polynomial time.
- Merge Sort
Co-NP No, answers can be checked in polynomial time.
• NP: class of problems verifiable in polynomial time.
- Hamiltonian cycle in a directed graph G(V,E) is a simple NP-hard All NP-hard problems are not in NP and it takes a
long time to check them.
cycle that contains each vertex in V .
- Determining whether a graph has a hamiltonian cycle is NP- NP-complete A problem that is NP and NP-hard is NP-complete.
complete but verifying that a cycle is hamiltonian is easy.
- Graph coloring.
2. Algorithms
Party!
Project
2. Algorithms
Conflicts:
No conflicts:
j
2. Algorithms
Choose i in R
Add i to S
Remove i from R
Return S*= S
2. Algorithms
Choose i in R
Add i to S
Remove i from R
Return S*= S
2. Algorithms
Associate a
Task 1 value v(i)
with task i
Return S*= S
2. Algorithms
Task 4 Task 5
Return S*= S
2. Algorithms
Task 4 Task 5
v(i) = s(i)
Earliest time first? Task 3 Task 2
Task 1
Return S*= S
2. Algorithms
Task 4 Task 5
Not so fast….
Earliest time first? Task 3 Task 2
Task 1
Task 6
Return S*= S
2. Algorithms
Task 3 Task 2
Task 1
Task 6
Task 7
Data Structures
• Linear
ü Array
ü List
ü Stack
ü Quene
• Nonlinear
ü Graph
ü Tree
ü Heap
3. Course Curriculum Overview
Asymptotic Notations
• Big O, Big Omega, and Big Theta
• Problems on Big O
• Algorithmic Complexity with Asymptotic Notations
Recursion
• Linear Search, Greatest Common Divisor
• Factorial, Tail Recursion
• Recurrence Relations, Substitution Method
• Hanoi Towers
Dynamic Programming
• Fibonacci Numbers
• Rod Cutting
• Matrix Chain Multiplication
• Longest Common Subsequence
Greedy Algorithms
• Knapsack Problem
• Minimum Spanning Tree: Kruskal Algorithm
• Job Sequencing with Deadlines
• Heap Shortest Path Algorithms
• Heap Sort • Dijkstra’s Algorithm
• Priority Quene • Bellman Ford Algorithm
• Minimum Spanning Tree: Prim’s Algorithm • Topological Sort
• Huffman’s Codes • Shortest Path by Topological Sort
• Floyd Warshall Algorithm
3. Course Curriculum Overview
String Matching
• Brute Force Matcher
• String Matching with Finite Automaton
• Pattern Pre-Processing
• The Knuth Morris Pratt Algorithm
Backtracking
• Rat in Maze
• N-Queens Algorithm
• Graph Coloring
• Hamiltonian Cycles
NP Completeness
Approximation Algorithms
Algorithms
and
Analysis of
Algorithms