© Peter Andreae CS4HS Algorithms Searching for an item in a list Sorting a list Searching for a word in text Analysing Networks.

Slides:



Advertisements
Similar presentations
Graph Theory Arnold Mesa. Basic Concepts n A graph G = (V,E) is defined by a set of vertices and edges v3 v1 v2Vertex (v1) Edge (e1) A Graph with 3 vertices.
Advertisements

Networks Prim’s Algorithm
DIJKSTRA’s Algorithm. Definition fwd search Find the shortest paths from a given SOURCE node to ALL other nodes, by developing the paths in order of increasing.
1 Discrete Structures & Algorithms Graphs and Trees: III EECE 320.
Greed is good. (Some of the time)
Chen, Lu Mentor: Zhou, Jian Shanghai University, School of Management Chen213.shu.edu.cn.
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture10.
Chapter 4 The Greedy Approach. Minimum Spanning Tree A tree is an acyclic, connected, undirected graph. A spanning tree for a given graph G=, where E.
CSE 380 – Computer Game Programming Pathfinding AI
Chapter 3 The Greedy Method 3.
Discussion #36 Spanning Trees
3 -1 Chapter 3 The Greedy Method 3 -2 The greedy method Suppose that a problem can be solved by a sequence of decisions. The greedy method has that each.
Chapter 9: Greedy Algorithms The Design and Analysis of Algorithms.
Graphs & Graph Algorithms 2 Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
Minimum Spanning Trees CIS 606 Spring Problem A town has a set of houses and a set of roads. A road connects 2 and only 2 houses. A road connecting.
More Graph Algorithms Weiss ch Exercise: MST idea from yesterday Alternative minimum spanning tree algorithm idea Idea: Look at smallest edge not.
CPSC 411, Fall 2008: Set 4 1 CPSC 411 Design and Analysis of Algorithms Set 4: Greedy Algorithms Prof. Jennifer Welch Fall 2008.
Minimum Spanning Trees
Minimum Spanning Trees What is a MST (Minimum Spanning Tree) and how to find it with Prim’s algorithm and Kruskal’s algorithm.
Instructor: Dr. Sahar Shabanah Fall Lectures ST, 9:30 pm-11:00 pm Text book: M. T. Goodrich and R. Tamassia, “Data Structures and Algorithms in.
Data Structures and Algorithms Graphs Minimum Spanning Tree PLSD210.
Minimal Spanning Trees What is a minimal spanning tree (MST) and how to find one.
Shortest Path Algorithms. Kruskal’s Algorithm We construct a set of edges A satisfying the following invariant:  A is a subset of some MST We start with.
Lecture 23. Greedy Algorithms
© The McGraw-Hill Companies, Inc., Chapter 3 The Greedy Method.
Chapter 9 – Graphs A graph G=(V,E) – vertices and edges
Minimum Spanning Trees
Spring 2015 Lecture 11: Minimum Spanning Trees
Minimum Spanning Trees CSE 2320 – Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington 1.
Module 5 – Networks and Decision Mathematics Chapter 23 – Undirected Graphs.
CPSC 320: Intermediate Algorithm Design & Analysis Greedy Algorithms and Graphs Steve Wolfman 1.
Prim's Algorithm This algorithm starts with one node. It then, one by one, adds a node that is unconnected to the new graph to the new graph, each time.
Chapter 18: Searching and Sorting Algorithms. Objectives In this chapter, you will: Learn the various search algorithms Implement sequential and binary.
Michael Walker. From Maps to Graphs  Make Intersections Vertices  Make Roads Edges  Result is Weighted Directed Graph  Weights: Speed Limit Length.
Runtime O(VE), for +/- edges, Detects existence of neg. loops
Graphs A ‘Graph’ is a diagram that shows how things are connected together. It makes no attempt to draw actual paths or routes and scale is generally inconsequential.
Queues, Stacks and Heaps. Queue List structure using the FIFO process Nodes are removed form the front and added to the back ABDC FrontBack.
Graphs. Graphs Similar to the graphs you’ve known since the 5 th grade: line graphs, bar graphs, etc., but more general. Those mathematical graphs are.
CSC2100B Tutorial 10 Graph Jianye Hao.
CSCI2100 Data Structures Tutorial 12
Decision Maths 1 Shortest path algorithm Dijkstra’s Algorithm A V Ali :
Graph Revisited Fei Chen CSCI2100B Data Structures Tutorial 12 1.
Spanning Trees Dijkstra (Unit 10) SOL: DM.2 Classwork worksheet Homework (day 70) Worksheet Quiz next block.
Minimum Spanning Trees CSE 2320 – Algorithms and Data Structures Vassilis Athitsos and Alexandra Stefan University of Texas at Arlington These slides are.
Proof of correctness of Dijkstra’s algorithm: Basically, we need to prove two claims. (1)Let S be the set of vertices for which the shortest path from.
COMP 261 Lecture 17 Test Revision.
Minimum Spanning Trees
Greedy Technique.
Minimum Spanning Trees
Lesson Objectives Aims Understand the following “standard algorithms”:
C.Eng 213 Data Structures Graphs Fall Section 3.
CS 3343: Analysis of Algorithms
I206: Lecture 15: Graphs Marti Hearst Spring 2012.
Topological Sort (topological order)
Comp 245 Data Structures Graphs.
Graph Algorithm.
i206: Lecture 14: Heaps, Graphs intro.
Minimum Spanning Tree.
Minimum Spanning Trees
Minimum Spanning Tree.
Shortest Path.
Graphs.
CSE332: Data Abstractions Lecture 18: Minimum Spanning Trees
Chapter 15 Graphs © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
CSCI2100 Data Structures Tutorial
CSE 373: Data Structures and Algorithms
Networks Prim’s Algorithm
Graphs.
Minimum spanning trees
Prim’s algorithm for minimum spanning trees
Presentation transcript:

© Peter Andreae CS4HS Algorithms Searching for an item in a list Sorting a list Searching for a word in text Analysing Networks.

© Peter Andreae CS4HS Searching in a list. “Find the name ‘Stevens, D’ in the list” What algorithm should you use? Linear Search for target item from position 1 to position 300 if item at the position is target, exit with “found” exit with “not found” Binary Search lower ← 1, upper ← 300, while (lower ≤ upper) position ← (upper + lower)/2 if target is at position: exit with “found” if target < item at position: upper = position-1 if target > item at position: lower = position + 1 exit with “not found”

© Peter Andreae CS4HS Searching in a list. Interpolation Search for target item lower ← 1, upper ← 300, while (lower ≤ upper) position ← compute estimate of position of target based on items at lower and upper if target = item at position: exit with “found” if target < item at position: upper = position-1 if target > item at position: lower = position + 1 exit with “not found” fraction ← (target – – position ← lower + fraction ∗ (upper-lower)

© Peter Andreae CS4HS Sorting a list of items? Which algorithm did you use? Insertion Sort insert each item in turn into its right place in the growing list Selection Sort Repeatedly find the smallest (or largest) and put it next in the sorted list Radix Sort Put items in piles based on the first letter Sort each pile Quick Sort Separate into lists of the smaller items and larger items, (by comparing each item to the first item – “pivot”) Sort each list Merge Sort Lay out items as a sequence of of one item lists Repeatedly merge adjacent lists into larger lists.

© Peter Andreae CS4HS Does it matter which you use?

© Peter Andreae CS4HS Searching for a string in text Find the string “T A N D W H A” in the text. Remember, the computer can only look at one character in the text at a time! How did you do it? Can we do it faster? Simplified Boyer-Moore Algorithm: Key idea: search from the END of the string if there is a mismatch, you can jump ahead Doesn’t even look at every character in the text once! Needs a “jump” table to say how far to move

© Peter Andreae CS4HS Simplified Boyer-Moore Algorithm Find the string “T A N D W H A” in the text. W H E N A L I C E H A D A H A T A N D W H A T A H A T T A N D W H A

© Peter Andreae CS4HS Simplified Boyer-Moore Algorithm Make a “jump” table: “T A N D W H A” textpos ← 7 (length of string) stringpos ← 0 while textpos ≤ end of text jump ← look up character at textpos in the table while stringpos < length of string if text char at (textpos – stringpos) = string char at stringpos stringpos ← stringpos + 1 else stringpos ← 0 textpos ← textpos + jump go back to outer loop exit with “found” exit with “not found” A: 5 D: 3 H: 1 N: 4 T: 6 W: 2 else:

© Peter Andreae CS4HS Analysing Networks Minimum “Spanning Trees” How could I connect all these towns by fibre optic cables at the minimum cost! (cost might depend on distance, terrain, and land ownership) Shortest Path from here to there How does Google maps find the shortest path in the network of roads? How do the NPC’s in games work out where to go? Lots more “graph” algorithms Articulation Points critical nodes that would disconnect the network Maximum Flow given a network of railways/pipes/… with maximum capacities, what is the maximum amount of freight/oil/… that can be pushed through the network from A to B.

© Peter Andreae CS4HS Find Minimum Spanning Tree

© Peter Andreae CS4HS Minimum Spanning Tree How did you do it? Prim’s Algorithm: Build connected subset outwards, always adding the smallest edge to an unconnected node Kruskal’s Algorithm: Add the next smallest edge that doesn’t make a loop (have to keep track of the connected subsets)

© Peter Andreae CS4HS Find shortest path in graph Start End 3 7

© Peter Andreae CS4HS Shortest Path How did you do it? Dijkstra’s Algorithm: Build connected subset outwards, always adding the edge for the shortest PATH to unconnected node Stop when you reach the goal A* search Algorithm: Same as Dijkstra, but have heuristic look ahead to aim towards goal.