April 20 2018 42018 CompSci 201 Spring 2018 Graphs 1 Y is for Y2K Bits are cheap Yahoo The importance of browsing YAML YACC Yet another Yaos minimax principle Randomized algorithms amp their limits ID: 760430
Download Presentation The PPT/PDF document "CompSci 201 Bacon Jeff Forbes" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.
Slide1
CompSci 201Bacon
Jeff ForbesApril 20, 2018
4/20/18
CompSci 201, Spring 2018, Graphs
1
Slide2Y is for …
Y2KBits are cheap?Yahoo!The importance of browsingYAML, YACCYet anotherYao’s minimax principleRandomized algorithms & their limits
4/20/18
CompSci 201, Spring 2018, Graphs
2
Slide3Data Representation
IMDB via the Sedgewick and Wayne book siteMovie title, followed by a list of actors and actresses that appeared in that movie, delimited by /.
4/20/18
CompSci 201, Spring 2018, Graphs
3
FileDescriptionMoviesActorsinput8.txtsample data815cast-06.txtmovies released in 2006 8,780 84,236 cast-mpaa.txtmovies rated by MPAA 21,861 280,624 cast-rated.txtpopular movies 4,527 122,406 cast-all.txtover 250,000 movies 285,462 933,864
Movie 0/Bacon, Kevin/A Movie 1/A/B/C Movie 2/D/E/A/B Movie 3/E/F/G Movie 4/F/G/H Movie 5/H/I/J/K Movie 6/J/L/M/N Movie 7/A/B/C/D
Who has the highest bacon degree?
Slide4Actor-Actor Representation
Vertices:
Actors or actressesEdges: Two actors are adjacent if and only if they appeared in the same moviepublic void createActorGraph() { for (Actor a : myActors.values()) for (Actor b : a.coStars().keySet()) myG.addEdge(a.getName(), b.getName());}
Movie 0/Bacon, Kevin/A Movie 1/A/B/C Movie 2/D/E/A/B Movie 3/E/F/G Movie 4/F/G/H Movie 5/H/I/J/K Movie 6/J/L/M/N Movie 7/A/B/C/D
CompSci 201, Spring 2018, Graphs
4
Slide5Movie-Movie Representation
Vertices: MoviesEdges: Two movies are adjacent iff they share a cast memberpublic void createMovieGraph() { for (Movie m : myMovies.values()) for (Actor a : m.getActors()) for (Movie otherMoov : a.getMovies()) if (otherMoov != m) myG.addEdge(m.name, otherMoov.name);}
CompSci 201, Spring 2018, Graphs
5
Slide6Actor-Movie Representation
Vertices:
Actors, actresses, and moviesEdges: An Actor is connected to a Movie iff he or she appeared in that moviepublic void createActorMovieGraph() { for (Movie m : myMovies.values()) for (Actor a : m.getActors()) myG.addEdge(m.name, a.name);}
CompSci 201, Spring 2018, Graphs
6
Slide7Bacon Questions
Compare and contrast representations for the problem:Actor-ActorMovie-MovieActor-Movie Which graph will be have the most vertices or edges? Which one will be easiest to implement?
7
CompSci 201, Spring 2018, Graphs
Slide8Center of the Hollywood Universe?
2,331,812 people can be connected to BaconIs he the center of the Hollywood Universe?Who are other good centers?What makes them good centers?CentralityCloseness: the inverse average distance of a node to all other nodesDegree: the degree of a nodeBetweenness: a measure of how much a vertex is between other nodesName someone who is 4 degrees or more away from Kevin Bacon
CompSci 201, Spring 2018, Graphs
8
Slide9More Graph problems
cart
care
tart
dart
dare
dirt
dire
Circuits
What is the the longest path in a directed acyclic graph?
Word Ladders
How many ladders from cart to dire as shown?
CompSci 201, Spring 2018, Graphs
9
Slide10Sorting: In 2 Slides
Why do people study sorting?Because we have toBecause sorting is beautifulExample of algorithm analysis in a simple, useful settingThere are n sorting algorithms, how many should we study?O(n), O(log n), …Why do we study more than one algorithm?Some are good, some are bad, some are very, very sadParadigms of trade-offs and algorithmic designWhich sorting algorithm is best?Which sort should you call from code you write?
CompSci 201, Spring 2018, Graphs
10
Slide11Sorting out sorts
Simple, O(n2) sorts --- for sorting n elementsSelection sort --- n2 comparisons, n swaps, easy to codeInsertion sort --- n2 comparisons, n2 moves, stable, fastBubble sort --- n2 everything, slow, slower, and uglyDivide and conquer faster sorts: O(n log n) for n elementsQuick sort: fast in practice, O(n2) worst caseMerge sort: good worst case, great for linked lists, uses extra storage for vectors/arraysOther sorts:Heap sort, basically priority queue sorting, Big-Oh?Radix sort: doesnt compare keys, uses digits/characters O(dn+kd)Shell sort: quasi-insertion, fast in practice, non-recursive O(n1.5)
https://www.youtube.com/watch?v=kPRA0W1kECg
CompSci 201, Spring 2018, Graphs
11