260 likes | 384 Views
Review. David Kauchak cs161 Summer 2009. Administrative. $ hw6 solution out soon Remote final Check grades on coursework. java.util.ArrayList. Extensible array implementation, i.e supports any arbitrary number of “add” operations Supports:
E N D
Review David Kauchak cs161 Summer 2009
Administrative • $ • hw6 solution out soon • Remote final • Check grades on coursework
java.util.ArrayList • Extensible array implementation, i.e supports any arbitrary number of “add” operations • Supports: • SetIndex(k, x) – set element at index k to x • GetIndex(k) – get the element at index k • Add(x) – append the element to the end of the array • They claim constant time for all these operations
Implementation? • Build on top of a basic array • Initially, array is of a fixed size, say n • When an “add” happens • If number of elements < n • just add the new element • If number of elements = n • Create a new array of size 2n • Copy the initial n elements over • add the new element
Run time • SetIndex(k, x) • O(1) • GetIndex(k) • O(1) • Add(x) • O(n) – worst case we have to create a new array and copy all n elements over
Amortized analysis • The time required to perform a sequence of operations is average over all of the operations performed • What is the overall cost of n+1 Add operations? • n+1 adds • n copies • 2n allocating memory (depending on the implementation) • 4n+1 operations • Amortized cost of n+1 adds? • 4n+1/n+1 = O(1)
Sorting • Algorithms • Mergesort • Insertion sort • Selection sort • Bubblesort • Quicksort (randomized quicksort) • Heapsort
Sorting • Algorithm features (in place, stable) • Runtime • Randomized quicksort analysis • How they operate • Decision tree model • Lower bound on comparison based sorting • Divide and conquer
Big O • O, Θ, Ω • Proving bounds • Proving bounds don’t hold • Estimating bounds from real world data • Comparing/ranking functions • rules of thumb
Recurrences • Solving recurrences • recursion-tree method • substitution method • master method • Defining recurrences from algorithms
Search trees • Trees • Binary search trees (BSTs) • B-trees • Definitions • Tree types/characteristics • balanced • full • complete • … • What are they good for • Operations • Runtime
Data structures • Basic • linked lists • stacks • queues • Binary heaps (i.e. priority queues) • Definitions/characteristics • what they’re good for • operations/how they operate • heapify • building a heap • runtime
Hashtables • Hash functions, what makes a valid hash function • Collision by chaining • Open addressing • linear probing • quadratic probing • double hashing • What they’re good for • operations • how they operate • collision analysis • runtime
Graphs • Types of graphs • directed • undirected • weighted • trees • dags • complete • bipartite • cyclic • connected
Graphs • Representation • adjacency list • adjacency matrix • benefits/drawbacks • Algorithms • BFS • DFS • Topological sort
Graphs • Algorithms • Single source shortest paths • Dijkstra’s – positive weights • Bellman-Ford – general graphs • Minimum spanning tress (MSTs) • minimum cut property • Kruskal’s algorithm • Prim’s algorithm • how they operate • when to apply • runtimes • Developing new algorithms • Runtime analysis (in terms of both |V| and |E|)
Greedy algorithms • What makes for a greedy problem/solution? • Identifying greedy problems • proving greedy problems are optimal • “stays ahead” argument • Examples • Interval scheduling • horn formulas • Fractional knapsack problem • Huffman coding algorithms
Dynamic programming • Identifying and solving dynamic programming problems • Defining recursive definition • Identifying repeated problems • Bottom-up approach • Examples • Fibonacci • Counting binary search trees • Longest commons subsequence • Longest increasing subsequence • Memoization • Greedy vs. DP problems
String algorithms • Edit distance • String operations • String matching • Naïve approach • FSA • building an FSA from a pattern • FSA operations • Rabin-Karp algorithm • How they operate • Runtimes
LPs • Definition of an LP • Normal form • Graphical representation of constraints • Creating LPs from word problems • Solving LPs • What makes a program solvable • Simplex method • finding neighbors • determining if we’re at the max • runtime analysis
Problem solving techniques • Divide and conquer • Dynamic programming • Greedy
Material covered • Slides - >1300 • Notes pages - 97 • Comments – 458 posts on the discussion board
How far have we come… • Describe the algorithm for a depth first search traversal • Write a function f(a, b) which takes two character string arguments and returns a string containing only the characters found in both strings in the order of a. Write a version which is order N-squared and one which is order N. • You're given an array containing both positive and negative integers and required to find the sub-array with the largest sum in O(n) time. Write a routine in C for the above. • Reverse a linked list • Insert in a sorted linked list • Write a function to find the depth of a binary tree
General exam taking practices • T/F • require an explanation! • Read the questions carefully! • Make sure you answer everything the question asked • Read over all of the questions • Solve the easy ones first • Don’t spend too much time on any given problem • Think about how you might be able to reuse an existing algorithm/approach
Contact info • [first_name_initial][last_name]@gmail.com