id
int64
0
25.6k
text
stringlengths
0
4.59k
21,400
draw the compact representation of the suffix trie for the string "minimize minimer- what is the longest prefix of the string "cgtacgttcgtacgthat is also suffix of this stringr- draw the frequency array and huffman tree for the following string"dogs do not spot hot pots or catsr- show the longest common subsequence arr...
21,401
say that pattern of length is circular substring of text of length if there is an index < msuch that [ [ ]that isif is (normalsubstring of or is equal to the concatenation of suffix of and prefix of give an ( )-time algorithm for determining whether is circular substring of - the kmp pattern matching algorithm can be m...
21,402
describe an efficient algorithm to find the longest palindrome that is suffix of string of length recall that apalindrome is string that is equal to its reversal what is the running time of your methodc- given sequence ( - of numbersdescribe an ( )-time algorithm for finding longest subsequence (xi ,xi xi xi - of numbe...
21,403
values of ( ,jfor = , and , - anna has just won contest that allows her to take pieces of candy out of candy store for free anna is old enough to realize that some candy is expensivecosting dollars per piecewhile other candy is cheapcosting pennies per piece the jars of candy are numbered so that jar has pieces in itwi...
21,404
coding - create class that implements standard trie for set of ascii strings the class should have constructor that takes as argument list of stringsand the class should have method that tests whether given string is stored in the trie - create class that implements compressed trie for set of ascii strings the class sh...
21,405
algorithms is referred to the book by stephen [ and the book by aho [ and crochemore and lecroq [ the trie was invented by morrison [ and is discussed extensively in the classic sorting and searching book by knuth [ the name "patriciais short for "practical algorithm to retrieve information coded in alphanumeric[ mccre...
21,406
the edge list structure the adjacency list structure the adjacency matrix structure graph traversals depth-first search implementing depth-first search breadth-first search directed graphs
21,407
transitive closure directed acyclic graphs weighted graphs shortest paths dijkstra' algorithm minimum spanning trees kruskal' algorithm the prim-jarnik algorithm
21,408
exercises java datastructures net the graph abstract data type graph is way of representing relationships that exist between pairs of objects that isa graph is set of objectscalled verticestogether with collection of pairwise connections between them by the waythis notion of "graphshould not be confused with bar charts...
21,409
vertices represent the classes defined in the programand whose edges indicate inheritance between classes there is an edge from vertex to vertex if the class for extends the class for such edges are directed because the inheritance relation only goes in one direction (that isit is asymmetricif all the edges in graph ar...
21,410
edge if an edge is directedits first endpoint is its origin and the other is the destination of the edge two vertices and are said to be adjacent if there is an edge whose end vertices are and an edge is said to be incident on vertex if the vertex is one of the edge' endpoints the outgoing edges of vertex are the direc...
21,411
proposition if is graph with edgesthen justificationan edge ( ,vis counted twice in the summation aboveonce by its endpoint and once by its endpoint thusthe total contribution of the edges to the degrees of the vertices is twice the number of edges proposition if is directed graph with edgesthen justificationin directe...
21,412
same endpoints and there are no self-loopsthe maximum degree of vertex in is in this case thusby proposition < ( now suppose that is directed since no two edges can have the same origin and destinationand there are no self-loopsthe maximum in-degree of vertex in is in this case thusby proposition < ( path is sequence o...
21,413
computers and the connections between them in single domainlike wiley comform subgraph of the internet if this subgraph is connectedthen two users on computers in this domain can send -mail to one another without having their information packets ever leave their domain suppose the edges of this subgraph form spanning t...
21,414
return an array storing the end vertices of edge areadjacent( , )test whether vertices and are adjacent replace( , )replace the element stored at vertex with replace( , )replace the element stored at edge with insertvertex( )insert and return new vertex storing element insertedge(vw, )insert and return new undirected e...
21,415
spacewhereas an adjacency matrix representation uses ( space the edge list structure the edge list structure is possibly the simplestthough not the most efficientrepresentation of graph in this representationa vertex of storing an element is explicitly represented by vertex object all such vertex objects are stored in ...
21,416
references to the element objects the reason this structure is called the edge list structure is that the simplest and most common implementation of the edge collection is with list even soin order to be able to conveniently search for specific objects associated with edgeswe may wish to implement with dictionary (whos...
21,417
edges to the vertices they are incident upon this allows us to define simple algorithms for methods endvertices(eand opposite(veperformance of the edge list structure one method that is inefficient for the edge list structurehoweveris that of accessing the edges that are incident upon vertex determining this set of ver...
21,418
replace ( insertvertexinsert edgeremoveedgeo( removevertex (mdetails for selected methods of the graph adt are as followsmethods vertices(and edges(are implemented by calling iterator(and iterator()respectively methods incidentedges and areadjacent all take (mtimesince to determine which edges are incident upon vertex ...
21,419
the edge object for an edge with end vertices and holds references to the positions (or entriesassociated with edge in the incidence collections ( )and (wtraditionallythe incidence collection (vfor vertex is listwhich is why we call this way of representing graph the adjacency list structure the adjacency list structur...
21,420
structure in ( time can also be implemented in ( time with the adjacency list structureusing essentially the same algorithms in additionbeing able to provide access between vertices and edges in both directions allows us to speed up the performance of number of the graph methods by using an adjacency list structure ins...
21,421
( removevertex (deg( )in contrast to the edge-list way of doing thingsthe adjacency list structure provides improved running times for the following methodsmethod incidentedges(vtakes time proportional to the number of incident vertices of vthat iso(deg( )time method areadjacent( ,vcan be performed by inspecting either...
21,422
for graphs with parallel edgesthe adjacency matrix representation must be extended so thatinstead of having [ijstoring pointer to an associated edge (vw)it must store pointer to an incidence collection (vw)which stores all the edges from to since most of the graphs we consider are simplewill not consider this complicat...
21,423
increase in space usagehoweverwhich is now ( )and in the running time of other methods for examplemethod incidentedges(vnow requires that we examine an entire row or column of array and thus runs in (ntime moreoverany vertex insertions or deletions now require creating whole new array aof larger or smaller sizerespecti...
21,424
in computing due to its faster methods for most algorithms (many algorithms do not use method areadjacentand its space efficiency most of the graph algorithms we examine will run efficiently when acting upon graph stored using the adjacency list representation in some caseshowevera trade-off occurswhere graphs with few...
21,425
backtrack along the path that we have traced so far until we find vertex that has yet unexplored edgestake one such edgeand continue the traversal the process terminates when our backtracking leads us back to the start vertex sand there are no more unexplored edges incident on this simple process traverses all the edge...
21,426
21,427
which they are explored during the traversaldistinguishing the edges used to discover new verticescalled discovery edgesor tree edgesfrom those that lead to already visited verticescalled back edges (see figure fin the analogy abovediscovery edges are the edges where we unroll our string when we traverse themand back e...
21,428
spanning tree of the connected component of justificationsuppose there is at least one vertex in ' connected component not visitedand let be the first unvisited vertex on some path from to (we may have wsince is the first unvisited vertex on this pathit has neighbor that was visited but when we visited uwe must have co...
21,429
computing cycle in gor reporting that has no cycles the justification of proposition is based on algorithms that use slightly modified versions of the dfs algorithm as subroutines implementing depth-first search as we have mentioned abovethe data structure we use to represent graph impacts the performance of the dfs al...
21,430
dynamically attached to an object in our dfs examplewe would like to have "decorablevertices and edges with an explored decoration and boolean value making graph vertices decorable we can realize the decorator pattern for any position by allowing it to be decorated this allows us to add labels to vertices and edgesfor ...
21,431
use small constant number of decorations thusthe decorable position methods will run in ( worst-case time no matter how we implement the embedded map code fragment an interface defining an adt for decorable positions note that we don' use generic parameterized types for the inherited map methodssince we don' know in ad...
21,432
depth-first search traversal using general classdfswhich has methodexecutewhich takes as input the grapha start vertexand any auxiliary information neededand then initializes the graph and calls the recursive methoddfstraversalwhich activates the dfs traversal our implementation assumes that the vertices and edges are ...
21,433
dfstraversal of class dfswhich performs generic dfs traversal of graph (continued from code fragment
21,434
the dfs class is based on the template method pattern (see section )which describes generic computation mechanism that can be specialized by redefining certain steps the way we identify vertices and edges that have already been visited during the traversal is in calls to methods isvisitedvisitand unvisit for us to do a...
21,435
start and target vertices it performs depth-first search traversal beginning at the start vertex we maintain the path of discovery edges from the start vertex to the current vertex when we encounter an unexplored vertexwe add it to the end of the pathand when we finish processing vertexwe remove it from the path the tr...
21,436
component of given vertex vby performing depth-first search traversal from that terminates when back edge is found it returns (possibly emptyiterable collection of the vertices and edges in the cycle formed by the found back edge code fragment specialization of class dfs to find cycle in the connected component of the ...
21,437
breadth-first search in this sectionwe consider the breadth-first search (bfstraversal algorithm like dfsbfs traverses connected component of graphand in so doing defines useful spanning tree bfs is less "adventurousthan dfshowever instead of wandering the graphbfs proceeds in rounds and subdivides the vertices into
21,438
unrolling the string in more conservative manner bfs starts at vertex swhich is at level and defines the "anchorfor our string in the first roundwe let out the string the length of one edge and we visit all the vertices we can reach without unrolling the string any farther in this casewe visitand paint as "visited,the ...
21,439
example of breadth-first search traversalwhere the edges incident on vertex are explored by the alphabetical order of the adjacent vertices the discovery edges are shown with solid lines and the cross edges are shown with dashed lines(agraph before the traversal(bdiscovery of level (cdiscovery of level (ddiscovery of l...
21,440
traversalwe can label each vertex by the length of shortest path (in terms of the number of edgesfrom the start vertex in particularif vertex is placed into level by bfs starting at vertex sthen the length of shortest path from to is as with dfswe can visualize the bfs traversal by orienting the edges along the directi...
21,441
given start vertex of gcomputingfor every vertex of , path with the minimum number of edges between and vor reporting that no such path exists computing cycle in gor reporting that has no cycles directed graphs in this sectionwe consider issues that are specific to directed graphs recall that directed graph (digraph)is...
21,442
examples is acyclic if it has no directed cycles (see figure for some the transitive closure of digraph are the same as the vertices of is the digraph and such that the vertices of has an edge (uv)whenever has directed path from to that iswe define by starting with the digraph and adding in an extra edge (uvfor each an...
21,443
followinginclude the given vertices and vdetermine whether reaches find all the vertices of determine whether is strongly connected determine whether is acyclic compute the transitive closure that are reachable from given vertex of in the remainder of this sectionwe explore some efficient algorithms for solving these p...
21,444
methods akin to the depth-first search (dfsand breadth-first search (bfsalgorithms defined previously for undirected graphs (sections and such explorations can be usedfor exampleto answer reachability questions the directed depth-first search and breadth-first search methods we develop in this section for performing su...
21,445
reachable from the starting dfs on digraph vertex into tree edges or discovery edgeswhich lead us to discover new vertexand nontree edgeswhich take us to previously visited vertex the tree edges form tree rooted at the starting vertexcalled the depth-first search treeand there are three kinds of nontree edgesback edges...
21,446
and ms edges are reachable from vertex sa directed dfs starting at runs in ( timeprovided the digraph is represented with data structure that supports constant-time vertex and edge methods the adjacency list structure satisfies this requirementfor example by proposition we can use dfs to find all the vertices reachable...
21,447
as with dfswe can extend breadth-first search (bfsto work for directed graphs the algorithm still visits vertices level by level and partitions the set of edges into tree edges (or discovery edges)which together form directed breadth-first search tree rooted at the start vertexand nontree edges unlike the directed dfs ...
21,448
of by incrementally computing series of digraphs where for this description is actually an example of an algorithmic design pattern known as dynamic programmingwhich is discussed in more detail in section from the description and analysis above we may immediately derive the following proposition proposition let be digr...
21,449
edge (vivjwith thick blue line performance of the floyd-warshall algorithm
21,450
performing dfs of directed graph from each of its verticesbut this depends upon the representation of the graph if graph is represented using an adjacency matrixthen running the dfs method once on directed graph takes ( time (we explore the reason for this in exercise - thusrunning dfs times takes ( timewhich is no bet...
21,451
figure note that digraph may have more than one topological ordering figure two topological orderings of the same acyclic digraph proposition has topological ordering if and only if it is acyclic justificationthe necessity (the "only ifpart of the statementis easy to demonstrate suppose is topologically ordered assumef...
21,452
because of the construction aboveif (vi,vjis an edge of then vi must be deleted before vj can be deletedand thus < thusv vn is topological ordering proposition ' justification suggests an algorithm (code fragment )called topological sortingfor computing topological ordering of digraph code fragment pseudo-code for the ...
21,453
incounter variables can be done with simple traversal of the graphwhich takes ( mtime we use the decorator pattern to associate counter attributes with the vertices say that vertex is visited by the topological sorting algorithm when is removed from the stack vertex can be visited only when incounter ( which implies th...
21,454
weighted graphs as we saw in section the breadth-first search strategy can be used to find shortest path from some starting vertex to every other vertex in connected graph this approach makes sense in cases where each edge is as good as any otherbut there are many situations where this approach is not appropriate for e...
21,455
each otherfor some connections in computer network are typically much faster than others (for examplesome edges might represent slow phone-line connections while others might represent high-speedfiber-optic connectionslikewisewe might want to use graph to represent the roads between citiesand we might be interested in ...
21,456
minimum length path (also called shortest pathfrom to uif such path exists people often use the convention that (vuif there is no path at all from to in even if there is path from to in gthe distance from to may not be definedhoweverif there is cycle in whose total weight is negative for examplesuppose vertices in repr...
21,457
outside the cloud that is closest to the algorithm terminates when no more vertices are outside the cloudat which point we have shortest path from to every other vertex of this approach is simplebut nevertheless powerfulexample of the greedy method design pattern greedy method for finding shortest paths applying the gr...
21,458
value for [zusing the edge ( ,zthe specific edge relaxation operation is as followsedge relaxationif [ + (( , ) [zthen [ ]- [ ]+ (( , )we give the pseudo-code for dijkstra' algorithm in code fragment note that we use priority queue to store the vertices outside of the cloud code fragment dijkstra' algorithm for the sin...
21,459
in figure figure an example execution of dijkstra' algorithm (continued from figure
21,460
the interestingand possibly even little surprisingaspect of the dijkstra algorithm is thatat the moment vertex is pulled into cits label [ustores the correct length of shortest path from to thuswhen the algorithm terminatesit will have computed the shortest-path distance from to every vertex of that isit will have solv...
21,461
into the cloudthe label [uis equal to (vu)the length of shortest path from to justificationsuppose that [ ]> ( ,tfor some vertex in vand let be the first vertex the algorithm pulled into the cloud (that isremoved from qsuch that [ ]> ( ,uthere is shortest path from to (for otherwise (vu)= [ ]let us therefore consider t...
21,462
in this sectionwe analyze the time complexity of dijkstra' algorithm we denote with and mthe number of vertices and edges of the input graph grespectively we assume that the edge weights can be added and compared in constant time because of the high level of the description we gave for dijkstra' algorithm in code fragm...
21,463
are as followsinserting all the vertices in with their initial key value can be done in ( logntime by repeated insertionsor in (ntime using bottom-up heap construction (see section at each iteration of the while loopwe spend (logntime to remove vertex from qand (degree( )log ntime to perform the relaxation procedure on...
21,464
vertices and edgessuch that the weight of each edge is nonnegativeand vertex of gdijkstra' algorithm computes the distance from to all other vertices of in (( +mlog nworst-case timeoralternativelyin ( worstcase time in exercise - we explore how to modify dijkstra' algorithm to output tree rooted at vsuch that the path ...
21,465
visit an adaptable priority queue supporting location-aware entries (section is used we insert vertex into with method insertwhich returns the location-aware entry of in we "attachto its entry in by means of method setentryand we retrieve the entry of by means of method getentry note that associating entries to the ver...
21,466
dijkstra (continued from code fragment
21,467
minimum spanning trees suppose we wish to connect all the computers in new office building using the least amount of cable we can model this problem using weighted graph whose vertices represent the computersand whose edges represent all the possible pairs (uvof computerswhere the weight ((vu)of edge (vuis equal to the...
21,468
case depends crucially on the following fact (see figure figure an illustration of the crucial fact about minimum spanning trees proposition let be weighted connected graphand let and be partition of the vertices of into two disjoint nonempty sets furthermorelete be an edge in with minimum weight from among those with ...
21,469
kruskal' algorithm the reason proposition is so important is that it can be used as the basis for building minimum spanning tree in kruskal' algorithmit is used to build the minimum spanning tree in clusters initiallyeach vertex is in its own cluster all by itself the algorithm then considers each edge in turnordered b...
21,470
mst algorithm on graph with integer weights we show the clusters as shaded regions and we highlight the edge being considered in each iteration (continues in figure
21,471
mst algorithm rejected edges are shown dashed (continues in figure
21,472
mst algorithm (continuedthe edge considered in (nmerges the last two clusterswhich concludes this
21,473
figure the running time of kruskal' algorithm we denote the number of vertices and edges of the input graph with and mrespectively because of the high level of the description we gave for kruskal' algorithm in code fragment analyzing its running time requires that we give more details on its implementation specifically...
21,474
the prim-jarnik algorithm in the prim-jarnik algorithmwe grow minimum spanning tree from single cluster starting from some "rootvertex the main idea is similar to that of dijkstra' algorithm we begin with some vertex vdefining the initial "cloudof vertices thenin each iterationwe choose minimum-weight edge ( , )connect...
21,475
let and denote the number of vertices and edges of the input graph grespectively the implementation issues for the prim-jarnik algorithm are similar to those for dijkstra' algorithm if we implement the adaptable priority queue as heap that supports location-aware entries (section )then we can extract the vertex in each...
21,476
algorithm (continued from figure
21,477
exercises for source code and help with exercisesplease visit java datastructures net
21,478
- draw simple undirected graph that has vertices edgesand connected components why would it be impossible to draw with connected components if had edgesr- let be simple connected graph with vertices and edges explain why (log mis (log nr- draw an adjacency list and adjacency matrix representation of the undirected grap...
21,479
la la la :la ,la la la la la la la :la ,la la la find the sequence of courses that allows bob to satisfy all the prerequisites - suppose we represent graph having vertices and edges with the edge list structure whyin this casedoes the insert vertex method run in ( time while the remove vertex method runs in (mtimer- le...
21,480
( ( ( ( ( ( , assume thatin traversal of gthe adjacent vertices of given vertex are returned in the same order as they are listed in the table above draw give the sequence of vertices of visited using dfs traversal starting at vertex give the sequence of vertices visited using bfs traversal starting at vertex - would y...
21,481
little space as possible the graph has , vertices and , , edgesand it is important to use as little space as possible you need to answer the query areadjacent as fast as possibleno matter how much space you use - explain why the dfs traversal runs in ( time on an -vertex simple graph that is represented with the adjace...
21,482
show how to modify dijkstra' algorithm to not only output the distance from to each vertex in gbut also to output tree rooted at such that the path in from to vertex is shortest path in from to - there are eight small islands in lakeand the state wants to build seven bridges to connect them so that each island can be r...
21,483
21,484
21,485
find which bridges to build to minimize the total construction cost - draw simpleconnectedundirectedweighted graph with vertices and edgeseach with unique edge weights illustrate the execution of kruskal' algorithm on this graph (note that there is only one minimum spanning tree for this graph - repeat the previous pro...
21,486
algorithm - repeat exercise - for figures and illustrating dijkstra' algorithm - repeat exercise - for figures and illustrating kruskal' algorithm - repeat exercise - for figures and illustrating the primjarnik algorithm - how many edges are in the transitive closure of graph that consists of simple directed path of ve...
21,487
algorithmcreativity - say that an -vertex directed acyclic graph is compact if there is some way of numbering the vertices of with the integers from to such that contains the edge (ijif and only if jfor all ij in [ give an ( )time algorithm for detecting if is compact - justify proposition - describein pseudo-codean ( ...
21,488
of design an efficient algorithm thatgiven an -node free tree tcomputes center of is the center uniqueif nothow many distinct centers can free tree havec- show thatif is bfs tree produced for connected graph gthenfor each vertex at level ithe path of between and has edgesand any other path of between and has at least e...
21,489
traverses each edge of exactly once according to its direction such tour is connected and the in-degree equals the out-degree of each always exists if vertex in with vertices and edges is cycle that describe an ( )-time algorithm for finding an euler tour of such digraph - an independent set of an undirected graph ( ,e...
21,490
initialize visitedvertices to {start if start=goalreturn path and exit otherwisecontinue find the edge (start,vof minimum weight such that is adjacent to start and is not in visitedvertices add to path add to visitedvertices set start equal to and go to step does this greedy strategy always find shortest path from star...
21,491
computer networks should avoid single points of failurethat isnetwork nodes that can disconnect the network if they fail we say connected graph is biconnected if it contains no vertex whose removal would divide into two or more connected components give an ( )-time algorithm for adding at most edges to connected graph ...
21,492
problemwe are given airports and band time tand we wish to compute sequence of flights that allows one to arrive at the earliest possible time in when departing from at or after time minimum connecting times at intermediate airports should be observed what is the running time of your algorithm as function of and mc- in...
21,493
now suppose that is weighted and assume the following for < < , ( , )= for < , <nm(ijweight(ijif (ijis in for <ij <nm(ijif (ijis not in alsolet be definedfor < , <nas followsm (ijmin{ ( + ( , ), ( , + ( , )if (ijkwhat may we conclude about the relationship between vertices and jc- graph is bipartite if its vertices can...
21,494
let be graph with vertices and edges such that all the edge weights in are integers in the range [ ,ngive an algorithm for finding minimum spanning tree for in (mlogntime projects - write class implementing simplified graph adt that has only methods relevant to undirected graphs and does not include update methodsusing...
21,495
design an experimental comparison of repeated dfs traversals versus the floyd-warshall algorithm for computing the transitive closure of digraph - implement kruskal' algorithm assuming that the edge weights are integers - implement the prim-jarnik algorithm assuming that the edge weights are integers - perform an exper...
21,496
should output the routing table for each node in the networkgiven an input list of node connectivity listseach of which is input in the syntax as shown aboveone per line notes the depth-first search method is part of the "folkloreof computer sciencebut hopcroft and tarjan [ are the ones who showed how useful this algor...
21,497
memory contents memory management stacks in the java virtual machine allocating space in the memory heap garbage collection
21,498
external memory and caching the memory hierarchy caching strategies external searching and btrees ( ,btrees -trees external-memory sorting
21,499
exercises java datastructures net memory management in order to implement any data structure on an actual computerwe need to use computer memory computer memory is simply sequence of memory wordseach of which usually consists of or bytes (depending on the computerthese memory words are numbered from to where is the num...