1 / 26

Review

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:

xena
Télécharger la présentation

Review

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Review David Kauchak cs161 Summer 2009

  2. Administrative • $  • hw6 solution out soon • Remote final • Check grades on coursework

  3. 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

  4. 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

  5. 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

  6. 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)

  7. java.util.ArrayList

  8. Sorting • Algorithms • Mergesort • Insertion sort • Selection sort • Bubblesort • Quicksort (randomized quicksort) • Heapsort

  9. 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

  10. Big O • O, Θ, Ω • Proving bounds • Proving bounds don’t hold • Estimating bounds from real world data • Comparing/ranking functions • rules of thumb

  11. Recurrences • Solving recurrences • recursion-tree method • substitution method • master method • Defining recurrences from algorithms

  12. Search trees • Trees • Binary search trees (BSTs) • B-trees • Definitions • Tree types/characteristics • balanced • full • complete • … • What are they good for • Operations • Runtime

  13. 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

  14. 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

  15. Graphs • Types of graphs • directed • undirected • weighted • trees • dags • complete • bipartite • cyclic • connected

  16. Graphs • Representation • adjacency list • adjacency matrix • benefits/drawbacks • Algorithms • BFS • DFS • Topological sort

  17. 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|)

  18. 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

  19. 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

  20. 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

  21. 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

  22. Problem solving techniques • Divide and conquer • Dynamic programming • Greedy

  23. Material covered • Slides - >1300 • Notes pages - 97 • Comments – 458 posts on the discussion board

  24. 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

  25. 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

  26. Contact info • [first_name_initial][last_name]@gmail.com

More Related