Algorithms: Depth First Search, Greedy, Dynamic Programming, Network Flows, Summaries of Algorithms and Programming

[Week 13] Summary -- Summary slides from Weeks 1 to 12

Typology: Summaries

2018/2019

Uploaded on 06/15/2019

kefart
kefart 🇺🇸

4.4

(11)

55 documents

1 / 72

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
The University of Sydney Page 1
COMP9007 - Algorithms
Summary of course contents
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48

Partial preview of the text

Download Algorithms: Depth First Search, Greedy, Dynamic Programming, Network Flows and more Summaries Algorithms and Programming in PDF only on Docsity!

COMP9007 - Algorithms

Summary of course contents

The University of Sydney Page 2 2

Progressive Marks - 40% Quizzes 20% Assignments 20%

Final Exam - 60% (minimum 40% required to pass)

One-2-One Helpdesk Next Friday 5-7pm ..? (SCS Building J12 level 2)

Assessment Summary

The University of Sydney Page 4 4

  • 6 questions of 10 marks each
  • Q1 will have 4 sub-questions comprising topics on stable matching and

running time

  • Pay attention to all sub questions asked like describe/explain, write

pseudocode, running time, justifying running time, etc.

  • Advice for lower and upper bound students

Exam Questions Overview

Content overview

1. Basic knowledge, concepts, notations,…

a) Asymptotic notations

b) Data structures

c) Graphs

2. Five techniques

a) Stable Matching

b) Greedy

c) Divide & Conquer

d) Dynamic Programming

e) Flow Networks

3. Advance Topics: P & NP and Coping with Hardness

Given functions f ( n ) and g ( n ), we say that f ( n ) is O ( g ( n )) if there are positive constants c and n 0 such that

f ( n ) ≤ cg ( n ) for nn 0

Example: 2 n + 10 is O ( n )

2 n + 10 ≤ cn ( c − 2) n ≥ 10 n ≥ 10/( c − 2) Pick c = 3 and n 0 = 10

Asymptotic Order of Growth

Data Structures

› Queues

  • Enqueue, dequeue, first and size operations in O(1) time.

› Stacks

  • Push, pop, top and size operations in O(1) time

› Balanced binary trees (e.g. AVL trees)

  • Insert, delete and find operations in O(log n) time
  • Recursion
  • The Master Theorem
  • Mergesort

Graph Representation: Adjacency Matrix

Adjacency matrix. n-by-n matrix with Auv = 1 if (u, v) is an edge.

  • Two representations of each edge.
  • Space proportional to n 2.
  • Checking if (u, v) is an edge takes Θ(1) time.
  • Identifying all edges takes Θ(n 2 ) time.

1 2 3 4 5 6 7 8 1 0 1 1 0 0 0 0 0 2 1 0 1 1 1 0 0 0 3 1 1 0 0 1 0 1 1 4 0 1 0 0 1 0 0 0 5 0 1 1 1 0 1 0 0 6 0 0 0 0 1 0 0 0 7 0 0 1 0 0 0 0 1 8 0 0 1 0 0 0 1 0

Graph Representation: Adjacency List

Adjacency list. Node indexed array of lists.

  • Two representations of each edge.
  • Space proportional to m + n.
  • Checking if (u, v) is an edge takes O(deg(u)) time.
  • Identifying all edges takes Θ(m + n) time.

1 2 3 2 3 4 2 5 5 6 7 3 8 8

1 3 4 5 1 2 5 7 8

2 3 4 6 5

3 7

DFS – Depth first search

  • Pick a starting vertex, follow outgoing edges that lead to new

vertices, and backtrack whenever “stuck”.

Technique 1: Greedy algorithms

A greedy algorithm is an algorithm that follows the

problem solving heuristic of making the locally optimal

choice at each stage with the hope of finding a global

optimum.

Interval Scheduling

  • Interval scheduling.
    • Input: Set of n jobs. Each job i starts at time s (^) j and finishes at time f (^) j.
    • Two jobs are compatible if they don't overlap in time.
    • Goal: find maximum subset of mutually compatible jobs.

0 1 2 3 4 5 6 7 8 9 10 11 Time

f g h

e

a b c d

Interval Scheduling

  • Interval scheduling.
    • Input: Set of n jobs. Each job i starts at time s (^) j and finishes at time f (^) j.
    • Two jobs are compatible if they don't overlap in time.
    • Goal: find maximum subset of mutually compatible jobs.

0 1 2 3 4 5 6 7 8 9 10 11 Time

f g h

e

a b c d

...

Interval Scheduling: Analysis

  • Theorem: Greedy algorithm [Earliest finish time] is optimal.
  • Proof: (by contradiction)
    • Assume greedy is not optimal, and let's see what happens.
    • Let i 1 , i 2 , ... i (^) k denote the set of jobs selected by greedy.
    • Let J 1 , J 2 , ... J (^) m denote the set of jobs in an optimal solution with i 1 = J 1 , i 2 = J 2 , ..., i (^) r = Jr for the largest possible value of r.

J 1 J 2 J (^) r

i 1 i 1 i (^) r i (^) r+

...

Greedy:

OPT: Jr+

Why not replace job J (^) r+ with job i (^) r+1?

job i (^) r+1 finishes before J (^) r+

Interval Partitioning

  • Interval partitioning.
    • Lecture i starts at s (^) i and finishes at f (^) i.
    • Goal: find minimum number of classrooms to schedule all lectures so that no two occur at the same time in the same room.
  • Ex: This schedule uses 4 classrooms to schedule 10 lectures.

9 9:30 10 10:30 11 11:30 12 12:30 1 1:30 2 2:30 Time

h

c b a

e

d g

f i

j

3 3:30 4 4: