December 4, Algorithms and Data Structures Lecture XV Simonas Šaltenis Aalborg University
December 4, Results of the questionnaire Problematic lectures:
December 4, This Lecture What have we learned? Summary-Pensum Solving exercises Recurrences Graph exercises ADT exercises Dvide and conquer algorithms
December 4, The Course – Pensum Toolbox of algorithmic techniques Divide and Conquer Merge sort, Quicksort, Binary search Dynamic programming Matrix chain multiplication, Longest Common Subsequence – not in exam pensum, except basic understanding of LCS Greedy algorithms Prim’s, Kruskal’s, Dijkstra’s Analysis of algorithms: Correctness of algorithms Loop invariants – not in exam pensum Asymptotic notations Recurrences
December 4, The Course – Pensum (2) Building algorithms - concept of ADT Toolbox of data structures: Simple data structures and ADTs array, all sorts of linked lists, stacks, queues, trees, heaps Dictionaries hash tables binary search trees (unbalanced) red-black trees
December 4, The Course – Pensum (3) Toolbox of algorithms: Sorting insertion sort, selection sort merge sort quick sort heap sort (priority queues) Graphs memory representation graph traversal breadth-first search depth-first search (topological sort) minimum spanning trees (Prim, Kruskal) shortest path (Dijkstra, Bellman-Ford)
December 4, The Exam The exam will be written, you will have three hours. Two parts: Multiple-choice, “quiz”-style part – tests basic knowledge, understanding of the core concepts “Creative exercises” – come up with algorithms, analyze them, argue for your solutions.
December 4, Preparation for the Exam To prepare for the exam: Concentrate on solving the exercises, not studying the textbook (although you have to know the concepts!) Solve exercises from last year exams When solving write your solutions down! On Jan 16, 13:00 come to B2-104 (here) and have your questions answered. Or pass by my office E1-215b! Good news: solutions to hand-in exercises will be posted on the web before Christmas!
December 4, Solving Recurrences Repeated substitution procedure: Substitute, expand, substitute, expand… Observe a pattern and write how your expression looks after the i-th substitution Find out what the value of i (e.g., lgn or n-1) should be to get the base case of the recurrence (e.g., T(1)) Insert the value of T(1) and the expression of i into your expression Compute your recurrence for small values and check if your general solution gives the same results!
December 4, Types of Recurrences Number of substitutions i : If T(n) = …T(n - 1)… and base case T(k) = … then i = n – k If T(n) = …T(n/b)… and base case T(k) = … then i = log b (n/k)
December 4, Types of recurrences II T(n) = aT(n – b) + c T(n) = aT(n/b) + cn + d Geometric series T(n)=T(n – b) + cn + d Arithmetic series Prove it yourself!
December 4, Graph Exercises Types of graph exercises: Decide what are the vertices and what are the edges Un-weighted graphs “Traverse and check(do) something” => use DFS or BFS Find shortest paths => use BFS Schedule or order dependent activities or processes => use Topological sorting
December 4, Graph Exercises Types of graph exercises: Weighted graphs Decide what are the weights Shortest paths, shortest times => use Dijkstra’s Minimum (maximum) spanning tree => use Prim’s or Kruskal’s Finding a critical path in a schedule (longest path in a DAG) => use Topological sorting on a DAG of activities
December 4, Do not forget: Write preconditions (INPUT) and postconditions (OUTPUT) of your algorithms You can only use the ADT operations provided in the exercise !!!