Course Review - PowerPoint PPT Presentation

About This Presentation
Title:

Course Review

Description:

Title: Lecture 1 - S03 Author: Ananda Guna Last modified by: Ananda Guna Created Date: 8/26/2000 8:39:18 PM Document presentation format: On-screen Show – PowerPoint PPT presentation

Number of Views:103
Avg rating:3.0/5.0
Slides: 59
Provided by: anand70
Learn more at: http://www.cs.cmu.edu
Category:
Tags: course | queues | review | stacks

less

Transcript and Presenter's Notes

Title: Course Review


1
Course Review
  • 15-211 Fundamental Structures of Computer
    Science

Ananda Guna May 04, 2006
2
This course was about
  • How to solve computing problems using
  • Problem analysis, to abstract away details and
    divide into smaller subproblems.
  • Mathematical foundations for precise formulations
    of problems and solutions.
  • Data structures and algorithms to solve problems
    correctly and efficiently.
  • Java programming and modular software
    construction for good implementations.

3
Data Structures/Algorithms
  • -Complexity
  • big-O, little-O, Omega etc..
  • Lists
  • linked, doubly, singly, multi-linked
  • Trees
  • general, B-trees, BST, splay, AVL, etc.
  • Stacks and Queues
  • operations, analysis
  • Heaps
  • binary, binomial
  • Hash Tables
  • collisions, implementation
  • Graphs
  • traversals, shortest paths
  • FSM
  • regular expressions, KMP
  • String Matching
  • KMP, Boyer-Moore, Rabin-Karp

.
4
Data Structures/Algorithms
  • Dynamic Programming
  • table(bottom-up), recursion(top-down)
  • memoization
  • Game Trees
  • mini-max, alpha-beta, iterative deepening
  • - Sorting
  • bubble, quick, insertion, selection
  • Algorithms
  • findMax, findMedian, reverse, MST, compression
  • Traversals, shortest path

5
Java Programming
Object oriented programming. Correctness (loop
invariants, induction). Time and space
complexity. Debugging (test harness).
6
Studying for the Final Exam
  • Review all material first
  • Lectures, programs, quizzes
  • Do sample finals under time restrictions.
  • Old finals are in blackboard/course material
  • Types and difficulty of problems may be similar
    (some topics not covered)

7
Complexity
8
Complexity
f(n)n2 g(n) n h(n) log n
f(n) is O(g(n)) iff f(n) is o(g(n)) iff
f(n) is ?(g(n)) iff f(n) is ?(g(n)) iff
9
Complexity
True or False? If true prove it, else give
counter example
10
Space Complexity
  • How much memory is needed to run the program
  • quicksort
  • merge Sort
  • insertion sort
  • Prims
  • Dijkstras

Key Point consider the sizes of the data
structures used
11
Solving Recurrences, Asymptotics
  • Solve T(n) 3 T(n/3) 1
  • Prove the correctness
  • By induction
  • Invariants
  • Hold initially
  • Preserved after each iteration of loop or method
    call
  • Or other methods

12
Complexity
A is an array of integers
13
Complexity of known algorithms
Algorithm Complexity(runtime)
Bubble sort O(n2) average, worst, O(n) best
Insertion sort O(n2) average, worst, O(n) best
Selection sort O(n2) average, worst, best
Find Max, Find min O(n), cannot be done in o(n)
Find Median With sorting O(nlogn) but O(n) using quick select
Quick sort O(nlogn) average best, O(n2) worst
Merge Sort O(nlogn) average, best, worst
Heap Sort O(nlogn) best, worst, average
Build heap O(n)
14
Complexity of known algorithms
Algorithm Complexity
Heap find min O(1)
Heap delete Min O(logn)
Heap -insert O(logn)
Hash insert, find, delete O(1)
Graph - build O(V2) space (adjacency matrix) O(VE) space (adjacency list)
Graph - Traverse O(E)
Graph Topological Sort O(V E)
Graph Dijkstras O((EV) logE)
MST prims O(EV2)
15
Complexity of known algorithms
Algorithm Complexity
MST Kruskals O(E logE) sort the edges O(V logV) find and union operations
Dynamic Programming O(Table size) Linear with memoization
Disjoint sets - union O(logn)
Disjoint sets - find O(logn)
KMP O(nm)




16
Sorting
17
Sorting and lower bounds
Insertion Sort Selection Sort Heapsort Mergesort Q
uicksort Radix Sort
18
Sorting and lower bounds
19
Questions
20
Trees
21
Balanced Binary Trees
22
AVL Trees
  1. Traverse the tree inorder
  2. Do exactly two rotations so that the tree is
    balanced
  • 3. Consider a binary tree of height h
  • What are the max and min number of nodes?
  • What are the max and min number of leaves?
  • 4. Perfect, full, complete trees

23
Splay Trees
24
Full, Complete and Perfect Trees
  • Definitions
  • Full, complete and perfect
  • Ex Show that a full binary tree with n leaves
    has (n-1) internal nodes. (use induction on n)
    Therefore a full binary tree with n leaves has
    (2n-1) nodes
  • Ex Start from the root and do a preorder
    traversal as follows. Write 1 for a node with 2
    children. Visit left child, then right child.
    Write 0 if the node is a leaf. Therefore a full
    binary tree with 3 nodes can be represented by
    bit sequence 100.
  • What is the bit sequence representing a
    full binary tree with 8 leaves?

25
Code Examples
26
Dictionaries
27
Dictionaries
28
Hashing
  • Describe why hashing a string to sum of its
    characters is not a good idea.
  • Assume S a1a2.an is a string
  • Define H(S) ? ai2i-1 (i1..n)
  • Describe a way to efficiently calculate H(S)

29
Heaps
30
Priority Queues and Heaps
  • Suppose you implement a priority queue using
    following
  • Unsorted array
  • Linked list (smallest at front)
  • Heap
  • What is the complexity in each case for
  • deleteMin
  • insert

31
Binary heaps
32
Compression
33
Compression
34
LZW compression
35
Data Compression
  • Encode I AM SAM SAM I AM SAM SAM using
  • Huffman compression
  • LZW
  • In each case calculate the compression ratio
  • Is it possible to apply Huffman after applying
    LZW?
  • If so apply Huffman to output generated by LZW
    above

36
Graphs
37
Graphs
Adjacency lists and matrices Traversal (DFS,
BFS) Reachability (DFS, BFS, Warshall) Shortest
Paths (Dijkstra, Bellman-Ford) MST (Prim,
Kruskal)
38
Graphs
  • What is breadth first traversal(BFS)?
  • What is depth first traversal(DFS)?
  • What data structures can be used to implement
    each one?
  • Reachability
  • Connected components
  • Topological sort

39
Graphs
40
Greedy Algorithms
50
60
60
40
20
50
50
40
60
40
40
10
100
20
30
20
20
50
40
150
Find the Shortest Path from Node 1 to every other
node
41
Dijkstras Algorithm
42
MST
  • Find the MST using
  • a. Prims Algorithm
  • b. Kruskals algorithm

43
Homework
  • A graph G is bipartite if the vertex set V can be
    partitioned into two subsets L and R, such that
    every edge has one vertex in L the other in R.
    Give an example of a bipartite graph.
  • G is a tree if it is connected and acyclic. What
    is the number is edges in a tree with n nodes?
  • 3. Draw all possible connected graphs G on 4
    vertices and 3 edges.
  • 4. Draw all possible connected graphs G on 4
    vertices and 4 edges.
  • 5. Suppose G is not connected. What the maximum
    number of edges in G?
  • 5. Prove or give a counterexample to the
    following claim Any tree is bipartite.

44
Dynamic Programming
45
Dynamic Programming
  • Dependent subproblems, recursive solutions,
    memoizing, explicit tables.
  • Knapsack
  • Longest Common Subsequence
  • Matrix Multiplication

46
(No Transcript)
47
Game Trees
48
Game trees
49
Games
2-person, deterministic, complete information,
... Backtracking MiniMax Alpha-beta
pruning Heuristics, iterative deepening, move
order, tricks, ...
50
Disjoint Sets
51
Union-find
52
Regular Expressions
53
Exercises
54
Homework
  • Write a regular expression of the alphabet a,
    b, c, d that describes all strings consisting of
    either an odd number of a's or an even number of
    b's, followed by any number (and ordering) of c's
    and d's. Zero is an even number and any number of
    x's can be zero x's. Draw a FSM to recognize any
    such string

55
String matching
56
Final Exam
  • Monday, May 8, 800 1100 am
  • Make sure not to be late.

57
Final Exam
  • Closed book, no calculators, cell phones,
    pagers, IM,
  • You can bring 1 (one) page of notes.
  • Bring fluids

58
Conclusion
  • Review all material
  • Do all sample quizzes and finals
  • Good luck!!
Write a Comment
User Comments (0)
About PowerShow.com