# Register now to access 7 million high quality study materials (What's Course Hero?) Course Hero is the premier provider of high quality online educational resources. With millions of study documents, online tutors, digital flashcards and free courseware, Course Hero is helping students learn more efficiently and effectively. Whether you're interested in exploring new subjects or mastering key topics for your next exam, Course Hero has the tools you need to achieve your goals.

3 Pages

### apt-graphs-4up

Course: APR 100, Spring 2009
School: Duke
Rating:

Word Count: 524

#### Document Preview

in Pieces GalaxyTrip Start with[&quot;&quot;, &quot;2 3&quot;, &quot;1 4&quot;, &quot;, &quot;2 5&quot; ..] Another piece in GalaxyTrip Supposed we have found all the connected components, accounting for all the vertices and we have these sizes: 1, 3, 5 Machine 1 depends on 2 and 3 What if 2 depends on 1 and 4 And 4 depends on 2 and 5 If we bring machine 1, what other...

Register Now

#### Unformatted Document Excerpt

Coursehero >> North Carolina >> Duke >> APR 100

Course Hero has millions of student submitted documents similar to the one
below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.

Course Hero has millions of student submitted documents similar to the one below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.
in Pieces GalaxyTrip Start with["", "2 3", "1 4", ", "2 5" ..] Another piece in GalaxyTrip Supposed we have found all the connected components, accounting for all the vertices and we have these sizes: 1, 3, 5 Machine 1 depends on 2 and 3 What if 2 depends on 1 and 4 And 4 depends on 2 and 5 If we bring machine 1, what other machines do we need? How big is this machine component? How do we find the chain of dependencies? We can bring one machine, or three, but how can we bring four? Six? Eight? Nine? Bring component 1 and 3 means we bring 4 machines We need to calculate all sums generated by component sizes Once we find this connected component, we dont care about the vertices in it anymore 11.1 Compsci 100, Spring 2008 11.2 Compsci 100, Spring 2008 Simple All Sums All sums continued If we know we can generate these sums using components 0..k (e.g., the first k components) then what changes when we process the k+1st component? 1, 2, 3, 5 We can keep a boolean array, if b[k] == true, we can brink k machines T T 0 1 2 3 4 5 If next component has size 4, then we can generate 5+4, 3+4, 2+4, 1+4 or 9,7,6,5 We can also bring 4 machines, the component itself Have 1 and 2 set so far, what happens with new value of 3? Now will have 5,4, and 3 why? What if instead of 3 we get 2, what values will be true? Compsci 100, Spring 2008 11.3 Compsci 100, Spring 2008 11.4 Why do we have to go backwards? process new value i given we what have so far: for(int k=ok.length-1; k >= 0; k--){ if (ok[k] && i+k < ok.length){ ok[i+k] = true; } ok[i] = true; } Last piece, parsing the graph If we go front to back with new value 2 well see we can get 5 and 7 if we already have 3, not the case if we go back-to-front Dont want to include new values in calculation If we use adjacency list, what do we need? What is a vertex? String or int? for(int k=0; k < dependencies.length; k++){ String[] adj = dependencies[k].split(" "); graph.put(""+k,adj); // or int[] iajd = new int[adj.length]; // loop: iajd[0] = Integer.parseInt(adj[0]); graph.put(k,iajd); } Compsci 100, Spring 2008 11.5 Compsci 100, Spring 2008 11.6 DFS arrives public Set<Graph.Vertex> dfs(Graph.Vertex start){ Set<Graph.Vertex> visited = new TreeSet<Graph.Vertex>(); Stack<Graph.Vertex> qu = new Stack<Gr...

Find millions of documents on Course Hero - Study Guides, Lecture Notes, Reference Materials, Practice Exams and more. Course Hero has millions of course specific materials providing students with the best way to expand their education.

Below is a small sample set of documents:

Duke - CPS - 018
Random Numbers Create a random number generator Random generator; Initialize it generator = new Random(); Generate Random Numbers from 0 to 8 x = generator.nextInt(9); How do you get random numbers from 1 to 10?
Duke - PS - 214
CPS 214: Computer Networks Distributed SystemsJanuary 23, 2007Problem Set 1Instructor: Prof. Bruce Maggs Computer Science Department, Duke UniversityThis problem set has four questions, each with several parts. Answer them as clearly and conci
Duke - PS - 214
CPS 214February 18, 2007Problem Set 2Instructor: Prof. Bruce Maggs Computer Science Department, Duke UniversityThis problem set has three questions. Answer them as clearly and concisely as possible. You may discuss ideas with others in the cla
Duke - CPS - 049
Discussion Report: The Database of IntentionsShivnath Babu Duke University shivnath@cs.duke.eduThis report summarizes the class discussion on &quot;The Database of Intentions&quot;. The assigned reading for this discussion was the first chapter of the book
Duke - CPS - 049
CPS 49S Google: The Computer Science Within and its Impact on Society - Spring 2008 Homework 2 Due date: Friday, Feb 29, 2008, 5.00 PM. Late submissions will not be accepted (unless there are documented excuses from the dean). Submission: You shou
Duke - CPS - 049
CPS 49S Google: The Computer Science Within and its Impact on Society - Spring 2008 Homework 1 Due date: Thursday, Jan 31, 2008, 1.00 PM (before class). Late submissions will not be accepted (unless there are documented excuses from the dean). Sub
Duke - CPS - 049
CPS 49S Google: The Computer Science Within and its Impact on Society - Spring 2008 Exercise 1Question 1 Compute the PageRank of the pages in Figure 1.Page BPage APage CPage DFigure 1: Link graph for Question 1Question 2 Compute the Pag
Duke - CPS - 049
1Chapter 1 Introduction to Program DesignChapter OverviewWhat is a computer program? What are the parts of a program? How are they put together? What kinds of questions does a program designer ask?In this chapter you will learn how a compu
Duke - CPS - 271
Why Neural Networks? Maybe we should make our computers more brain-like:Computers BrainsNeural NetworksCPS 271 Ron ParrComputational Units Storage Units Cycle Time Bandwidth Compute Power108 gates/CPU 1011 neurons 109 bits RAM 1012 bits HD 1
Duke - CPS - 210
Dynamic Voltage ScalingThe question: at what clock rate/voltage should the CPU run in the next scheduling interval? Voltage scalable processors StrongARM SA-2 (500mW at 600MHz; 40mW at 150MHz)(adjust clock based on past window, no process reorde
Duke - CPS - 100
ADTs and vectors, towards linked listslltvector is a class-based implementation of a lower-level data type called an array tvector grows dynamically (doubles in size as needed) when elements inserted with push_back tvector protects against bad
Duke - CPS - 110
I/O Caching and Page ReplacementMemory/Storage Hierarchy 101Very fast 1ns clock Multiple Instructions per cycle&quot;CPU-DRAM gap&quot; memory system architecture (CPS 104) volatile &quot;I/O bottleneck&quot; VM and file caching (CPS 110)P \$ SRAM, Fast, Small Expe
Duke - CPS - 271
The Problem Learning Probability DistributionsCPS 271 Ron Parr Observe a sequence of events Predict the probability of future events based upon observations Classical statistical problem Surprisingly subtle issues ariseEvent Spaces We first c
Duke - CPS - 108
Inheritance (language independent)qFirst view: exploit common interfaces in programming Iterator and Comparable in Java, see List/ArrayList/Vector Iterators in STL/C+ share interface by convention/templatesImplementation varies while interfac
Duke - CPS - 210
Tricks (mixed syntax)if (some_condition) / as a hint { LOCK m DO if (some_condition) /the truth {stuff} END Cheap to get info but must check for } correctness; always a slow wayMore TricksGeneral pattern:while (! required_conditions) wait (m, c)
Duke - CPS - 108
Software frameworks/cadaversExperience with OO programming and design shows that design patterns are useful Where do we get the experience? How do we impart experience? What can we use to illustrate patterns in practice? What patterns should we em
Duke - CPS - 210
Power-Aware Ad Hoc RoutingMobicom98 paper Power-Aware Routing in Ad Hoc Networks by Singh, Woo, and Raghavendra What is ad hoc routing? Routing through cooperating wireless nodes that may be mobile (topology changing). Goal: reduce the energy cons
Duke - CPS - 189
Thomas Finley An Empirical Study of Novice Program Comprehension in the Imperative and ObjectOriented Styles by Vennila Ramalingam and Susan Wiedenbeck The title says it all, does it not? The authors sought to determine what differences in comprehens
Duke - CPS - 100
Searching, Maps, HashingqSearching is a very important programming application Consider google.com and other search engines In general we search a collection for a key Vector/List, Tree: O(n) and O(log n) If we compare keys when searching we c
Duke - CPS - 100
Intersection, Union, MultisetsFinding the intersection of two sets requires examining all the elements of one set and determining if these are in the other How can we examine all the elements of a MultiSet? What mechanism exists for accessing ind
Duke - CPS - 100
What is Computer Science?What is it that distinguishes it from the separate subjects with which it is related? What is the linking thread which gathers these disparate branches into a single discipline? My answer to these questions is simple - it is
Duke - CPS - 100
Backtracking, Search, HeuristicsqMany problems require an approach similar to solving a maze Certain mazes can be solved using the &quot;right-hand&quot; rule Other mazes, e.g., with islands, require another approach If you have &quot;markers&quot;, leave them at
Duke - CPS - 100
Review of Data StructuresqWeve studied concrete data structures Vectors Homogeneous aggregates supporting random access Linked lists Collections supporting constant-time insertionTrees Combine efficiency of search/insert from vector/linke
Duke - CPS - 110
COMPSCI 110 Operating Systems Who - Introductions How - Policies and Administrative Details Why - Objectives and Expectations What - Our Topic: Operating SystemsHow COMPSCI 110 will work Its all explained on the webhttp:/www.cs.duke.edu/educa
Duke - CPS - 100
Intersection, Union, MultisetsAnatomy of IntersectionFinding the intersection of two sets requires examining all the elements of one set and determining if these are in the other How can we examine all the elements of a MultiSet? What mechanis
Duke - CPS - 100
Name: HW 1 - Linked Lists Instructions: This HW is due in-class on Oct. 16. Turn in your work stapled and with your name on every page. This assignment is worth 100 points. You should work on your own, but you can use books/notes. You should not use
Duke - CPS - 100
CPS 100E - Program Design and Analysis I Prof. Rodger Section: 2-3 Trees handout2-3 Treesleaf nodes contain data item all leaves on same level nonleaf node has 2 or 3 children two search values largest item in left subtree largest item in middle s
Duke - CPS - 100
CPS 100E - Program Design and Analysis I Prof. Rodger Section: Trees handout Read Chap 6.5-6.6, Chap 17. We will not use the class implementation of trees in the book, but you should read about them. General Tree set of nodes vertices set of edges no
Duke - CPS - 100
CPS 100E - Program Design and Analysis I Prof. Rodger Section: Red Black Trees handoutRed-Black TreeBinary search tree properties every node is red or black every leaf is a NULL node and black the root is black If node is red, then its children ar
Duke - CPS - 100
The PlanGraphical User Interfaces GUIs Components Flat Layouts Hierarchical Layouts Designing a GUI Coding a GUIGUI.1GUI.2Components JLabel text/image display JTextField single line for text input/output JTextArea multiple lines for te
Duke - CPS - 100
Java: Base Types All information has a type or class designation Built-in TypesCalled : primitive types or base types boolean, char, bye, short, int, long, float, double Primarily use: int, double, booleanNeed to declare before using; defined
Duke - CPS - 100
On the Limits of ComputingExistence of Noncomputable FunctionsReasons for Failure1.Approach Matching up Programs and Functions E.g., assume 3 functions, only 2 programs Without details, conclude one function has no programRuns too long
Duke - CPS - 100
Intro to SortingSelection Sorting Example Sorting &quot;Ideal&quot; Computer Science Topic Theory and Practice meet Efficient Sorting Saves MoneyFirst look at some simple (quick and dirty?) algorithms Selection Sort1. 2. 3. Find smalle
Duke - CPS - 100
Creating HeapsArray-based heap Heap is an array-based implementation of a binary tree used for implementing priority queues, supports:insert, findmin, deletemin: complexities?store &quot;node values&quot; in array beginning at index 1 for node with
Duke - CPS - 100
Binary TreesFrom doubly-linked lists to binary treesLinked lists: efficient insertion/deletion, inefficient search ArrayList: search can be efficient, insertion/deletion not Binary trees: efficient insertion, deletion, and search trees used i
Duke - CPS - 100
Big Oh Again AgainRecognizing Common Recurrences Have taken the attitude that mostly you can look things up Now need to be able to do your own derivations Extend our menu of solutions to common recurrence Lets look at previously shown tableBe
Duke - CPS - 100
Searching, Maps,Tries (hashing)From Google to MapsSearching is a fundamentally important operation We want to search quickly, very very quickly Consider searching using Google, ACES, issues? In general we want to search in a collection for
Duke - CPS - 100
Intro to GraphsDefinitions and VocabularyA graph consists of a set of vertices (or nodes) and a set of edges (or arcs) where each edge connects a pair of vertices. If the pair of vertices defining an edge is ordered, then it is a directed graph.
Duke - CPS - 100
Data CompressionCompression is a high-profile application.zip, .mp3, .jpg, .gif, .gz, What property of MP3 was a significant factor in what made Napster work (why did Napster ultimately fail?)Why do we care?Secondary storage capacity double
Duke - CPS - 100
Searching, Maps,Tries (hashing)Searching is a fundamentally important operationWe want to search quickly, very very quickly Consider searching using Google, ACES, issues? In general we want to search in a collection for a keyWe've searched us
Duke - CPS - 100
Memory ModelCost of Disk I/OFor this course: Assume Uniform Access Time All elements in an array accessible with same time cost Reality is somewhat different Registers On (cpu) chip cache memory Off chip cache memory Main memory Virtual memo
Duke - CPS - 100
Inheritance and Interfaces Single inheritance in JavaInheritance models an &quot;is-a&quot; relationshipA class can extend only one class in Java A dog is a mammal, an ArrayList is a List, a square is a shape, Write general programs to understand
Duke - CPS - 100
Inheritance and Interfaces Inheritance models an &quot;is-a&quot; relationshipA dog is a mammal, an ArrayList is a List, a square is a shape, Write general programs to understand the abstraction, advantages?void doShape(Shape s) { System.out.println(s.a
Duke - CPS - 100
Other N log N SortsBinary Tree SortBasic Recipe o Insert into binary search tree (BST) o Do Inorder Traversal Complexity o Create: O(N log N) o Traversal O(N) Not usually used for sorting unless you need BST for other reasonsCompSci 100E28.1
Duke - CPS - 100
Java: Base Types Java: Operators for Base TypesAll information has a type or class designation Built-in TypesCalled : primitive types or base types boolean, char, bye, short, int, long, float, double Primarily use: int, double, booleanFami
Duke - CPS - 100
Java Basics Arrays!Java Basics Arrays!Should be a very familiar idea&quot;!Problem: Deal with exam grades in a course o!Could have variable for each student o!Would need unique name for each variable o!Need lots of custom code o!Instead, assume
Duke - CPS - 100
Dropping Glass BallsTower with N Floors ! Given 2 glass balls ! Want to determine the lowest floor from which a ball can be dropped and will break ! How?!Glass balls revisited (more balls)! !1.! 2.! 3.! 4.! 5.! 6.! 7.! 8.! 9.! 10.!What is th
Duke - CPS - 100
Data CompressionYear Scheme 1967 ASCII 1950 Huffman 1977 Lempel-Ziv (LZ77) 1984 Lempel-Ziv-Welch (LZW) Unix compress 1987 (LZH) used by zip and unzip 1987 Move-to-front 1987 gzip 1995 Burrows-Wheeler 1997 BOA (statistical data compression)CompSci
Duke - CPS - 100
Problem 1!Problem 2!Given n, calculate 2n&quot; &quot;What if you wanted to print all from 20 to 2n? What if you wanted to return the value?Given a real number c and some error tolerance epsilon, estimate t, the square root of cCompSci 100E2.1
Duke - CPS - 100
Is there a Science of Networks?!From subsets to graphs with bits!What kinds of networks are there? From Bacon numbers to random graphs to Internet ! From FOAF to Selfish Routing: apparent similarities between many human and technological system
Duke - CPS - 100
Searching, Maps, TablesqSearching is a fundamentally important operation We want to do these operations quickly Consider searching using google.com, altavista.com, etc., In general we want to search in a collection for a key Weve seen searching
Duke - CPS - 100
Data Structures revisitedLinked lists and arrays and ArrayLists and . Linear structures, operations include insert, delete, traverse, . Advantages and trade-offs include . We want to move toward structures that support very efficient insertion a
Duke - CPS - 100
Conventions in Compsci 100 projectsKWIC: Key word in ContextArise, fair sun, and I. Yet I should shortly, for one would those twenty could but wherefore, villain, didst thou mean, But 'banished' to thou happy. Tybalt would cell there would she he
Duke - CPS - 100
Analysis: Algorithms and Data StructuresHow fast does the code run?We need a vocabulary to discuss performance and to reason about alternative algorithms and implementations Its faster! Its more elegant! Its safer! Its cooler! We need empirical
Duke - CPS - 100
Printed by Owen L. Astrachan Feb 04, 09 9:19import java.util.*;75ArrayListHash.javaPage 1/2Feb 04, 09 9:19ArrayListHash.javaPage 2/2public class ArrayListHash implements IMapper {5private static int SIZE = 1000000; private class Comb
Duke - CPS - 100
Printed by Owen L. Astrachan Mar 18, 09 11:42import java.util.*; public class Postfix {5Postfix.javaPage 1/1private static final String DELIMS = &quot;+-*/ &quot;; private int operate(String op, int lhs, int rhs){ if (op.equals(&quot;+&quot;) { return lhs + rhs;
Duke - CPS - 100
APT IPConverterhttp:/www.cs.duke.edu/csed/algoprobs/ipconverter.htmlAPT IPConverterThis problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior writ
Duke - FEB - 100
APT IPConverterhttp:/www.cs.duke.edu/csed/algoprobs/ipconverter.htmlAPT IPConverterThis problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior writ
Duke - CPS - 100
Data and InformationOrganizing Data: ideas and issuesHow and why do we organize data? Differences between data and information? What about knowledge?Often there is a time/space tradeoff If we use more space (memory) we can solve a data/ info
Duke - CPS - 100
Search, Trees, Games, BacktrackingSearch, Backtracking,HeuristicsTrees help with search How do you find a needle in a haystack? Set, map: binary search tree, balanced and otherwise Quadtree and more, scenes and objects in games 3-4 Tre
Duke - CPS - 100
Data Structures revisitedWordladder Story Linked lists and arrays and ArrayLists and Linear structures, operations include insert, delete, traverse, Advantages and trade-offs include We want to move toward structures that support very effi