Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 10: Class Review Dr John Levine 52236 Algorithms and Complexity March 13th 2006.

Similar presentations


Presentation on theme: "Lecture 10: Class Review Dr John Levine 52236 Algorithms and Complexity March 13th 2006."— Presentation transcript:

1 Lecture 10: Class Review Dr John Levine 52236 Algorithms and Complexity March 13th 2006

2 Today’s Lecture More notes on Practical 1: some example graphs Syllabus review for this class Topics covered by this class and which topics are examinable Topics remaining to be covered: Abstract data types, hash tables, graph algorithms, NP-hard problems Abstract data types and an example Hash tables (from Mark Dunlop’s slides)

3 More Notes on Practical 1 public class Test7 { public static void main (String[] args) { int sum = 0; int n = (int)Double.parseDouble(args[0]); long startTime = System.currentTimeMillis(); for (int i=0; i<n; i++) for (int j=0; j<i*i; j++) if (j%i == 0) for (int k=0; k<j; k++) sum++; long endTime = System.currentTimeMillis(); }

4 How to do it Find a value of n that gives a small, but non-zero time (e.g. around 50-100 milliseconds) Find a value of n that gives a fairly large time (depends how long you can bear to wait – about 5-10 seconds) Sample values of n between these two values Try fitting various trend lines: linear, polynomial, etc. Look for a high R 2 value showing goodness of fit If you analysis says (for example) O(n 3 ), try plotting your time values against n 3 and look for a straight line

5 Learning Outcomes On completion of the class, a student should be able: to implement a number of fundamental algorithms, including in particular the fundamental algorithms of searching and sorting to make a critical assessment of different implementations of algorithms and abstract data types to carry out a number of empirical studies of the performance of algorithms and abstract data types to appreciate a number of fundamental computational problems, and be aware of real world instances of those problems

6 Syllabus: Algorithmic Complexity Introduction to Algorithmic Complexity: basic algorithmic classification, with examples; the order notation (Big-oh); elementary complexity and estimation of run times; the tyranny of growth. Covered in specifically in Lectures 1 and 2 and Practical 1, also covered throughout the course Examinable Typical exam question: say what Big-oh is, give an analysis of some code fragments

7 Syllabus: Searching and Sorting Searching and Sorting: the complexity of a range of techniques, including the divide and conquer approach; the relative complexity of searching and sorting algorithms; the sorting algorithms covered will include bubble sort, insertion sort, merge sort and quick sort; searching, including sequential search and the binary chop; hashing. Partially covered by Lectures 3 and 4 We’ll do a quick recap of the four sorting algorithms We’ll look at hash tables today Examinable

8 Syllabus: Binary Trees Binary Trees revisited: implementations by array; expression trees; binary tree implementation of sorted list; access times; algorithms covered include traversal, searching, balancing and deletion. Already covered in Programming Techniques We did state space search and game trees instead Game trees, minimax search and alpha-beta pruning are examinable, the rest is not (because last year’s students didn’t do it) Typical exam question: map out a simple game tree and say what move the computer should make next

9 Syllabus: Graph Algorithms Graphs revisited: directed and undirected graphs; representations of graphs; basic graph algorithms; applications of graphs to real world problems (for example telecommunications, transportation systems, dependencies between objects). To be covered next week Representation of graphs, Dijkstra’s algorithm Application to the tube map problem Examinable Typical exam question: show application of Dijkstra’s algorithm to a real world problem

10 Syllabus: NP-Hard Problems Permutations and Combinations: branch and bound; greedy algorithms; backtracking search; typical problems, for example the TSP and related problems, the knapsack problem. Mostly covered by our consideration of state space search and games, and also in Topics 1 and 2 I will touch briefly on this area in my summary and revision lecture in Week 10 Not directly examinable – see the Week 10 lecture for what you need to know in this area

11 Abstract Data Types Definition: a set of data values and operations on those data values which are precisely specified and independent of any particular implementation Example: a stack makeNewStack() returns an empty stack push(item,stack) puts item onto the top of stack top(stack) returns the top element of stack pop(stack) returns the top item and removes it The external user of the ADT only sees the interface, not the internal workings (representation, algorithms)

12 Example ADT: Lookup Table I want to create a lookup table to hold the names of my students (keys) and their birthdays (values) Operations: add(key,value) adds a new key-value pair lookup(key) returns the value associated with key delete(key) deletes both key and its value inOrder() show all key-value pairs in order of keys Example: add(“John”, 2nd December) adds John’s birthday lookup(“Fred”) returns Fred’s birthday delete(“Eric”) deletes Eric’s birthday from the table

13 Lookup Table: Implementation I can implement my lookup table in various ways: which of them is best? Linked list: add new items on to the front of the list, search through the list to perform lookup and deletion, sort the list to show the table in order Binary search tree: add new items to the tree, search the tree to perform lookup and deletion, traverse the tree to show the table in order Hash table: use a ‘magic function’ to map the key onto an integer and store the value at a location in memory directly computable from that integer

14 Lookup Table: Complexity Exercise: what is the complexity of the lookup table operations for the three implementations given? You can assume the hash function is O(1). Linked ListBinary treeHash table add(key,value) lookup(key) delete(key) inOrder()

15 Lookup Table: Complexity Exercise: what is the complexity of the lookup table operations for the three implementations given? You can assume the hash function is O(1). Linked ListBinary treeHash table add(key,value)O(1) lookup(key)O(n) delete(key)O(n) inOrder()O(n log n)

16 Lookup Table: Complexity Exercise: what is the complexity of the lookup table operations for the three implementations given? You can assume the hash function is O(1). Linked ListBinary treeHash table add(key,value)O(1)O(log n) lookup(key)O(n)O(log n) delete(key)O(n)O(log n) inOrder()O(n log n)O(n)

17 Lookup Table: Complexity Exercise: what is the complexity of the lookup table operations for the three implementations given? You can assume the hash function is O(1). Linked ListBinary treeHash table add(key,value)O(1)O(log n)O(1) lookup(key)O(n)O(log n)O(1) delete(key)O(n)O(log n)O(1) inOrder()O(n log n)O(n)

18 Lookup Table: Complexity Exercise: what is the complexity of the lookup table operations for the three implementations given? You can assume the hash function is O(1). Linked ListBinary treeHash table add(key,value)O(1)O(log n)O(1) lookup(key)O(n)O(log n)O(1) delete(key)O(n)O(log n)O(1) inOrder()O(n log n)O(n)O(k+n log n)

19 Lookup Table: Evaluation So which implementation is best? Linked list: simple implementation, efficient only for adding items, works even when no ordering can be defined on the keys Binary search tree: more involved implementation, reasonably efficient in all operations, can iterate over all keys and find a “nearest match” for a given key Hash table: best for adding, lookup and deletion, great for huge data sets, fairly easy to implement, but finding a good hash function can be difficult, iterating over all keys is hard as hash tables don’t preserve ordering


Download ppt "Lecture 10: Class Review Dr John Levine 52236 Algorithms and Complexity March 13th 2006."

Similar presentations


Ads by Google