chapter_num,question_num,question 1,1,Show the contents of the id[] array and the number of times the array is accessed for each input pair when you use quick‑find for the sequence 9‑0 3‑4 5‑8 7‑2 2‑1 5‑7 0‑3 4‑2. 1,2,"Do Exercise 1.5.1, but use quick‑union (page 224). In addition, draw the forest of trees represented by the id[] array after each input pair is processed." 1,3,"Do Exercise 1.5.1, but use weighted quick‑union (page 228)." 1,4,Show the contents of the sz[] and id[] arrays and the number of array accesses for each input pair corresponding to the weighted quick‑union examples in the text (both the reference input and the worst‑case input). 1,5,"Estimate the minimum amount of time (in days) that would be required for quick‑find to solve a dynamic connectivity problem with \(10^{9}\) sites and \(10^{6}\) input pairs, on a computer capable of executing \(10^{9}\) instructions per second. Assume that each iteration of the inner for loop requires 10 machine instructions." 1,6,Repeat Exercise 1.5.5 for weighted quick‑union. 1,7,"Develop classes QuickUnionUF and QuickFindUF that implement quick‑union and quick‑find, respectively." 1,8,"Give a counterexample that shows why this intuitive implementation of union() for quick‑find is not correct: ``java public void union(int p, int q) { if (connected(p, q)) return; // Rename p’s component to q’s name. for (int i = 0; i < id.length; i++) if (id[i] == id[p]) id[i] = id[q]; count--; } ``" 1,9,Draw the tree corresponding to the id[] array depicted at right. Can this be the result of running weighted quick‑union? Explain why this is impossible or give a sequence of operations that results in this array. `` i 0 1 2 3 4 5 6 7 8 9 id[i] 1 1 3 1 5 6 1 3 4 5 `` 1,10,"In the weighted quick‑union algorithm, suppose that we set id[find(p)] to q instead of to id[find(q)]. Would the resulting algorithm be correct? **Answer:** Yes, but it would increase the tree height, so the performance guarantee would be invalid." 1,11,"Implement weighted quick‑find, where you always change the id[] entries of the smaller component to the identifier of the larger component. How does this change affect performance?" 1,12,"Quick‑union with path compression. Modify quick‑union (page 224) to include path compression, by adding a loop to union() that links every site on the paths from p and q to the roots of their trees to the root of the new tree. Give a sequence of input pairs that causes this method to produce a path of length 4. Note: The amortized cost per operation for this algorithm is known to be logarithmic." 1,13,"Weighted quick‑union with path compression. Modify weighted quick‑union (Algorithm 1.5) to implement path compression, as described in Exercise 1.5.12. Give a sequence of input pairs that causes this method to produce a tree of height 4. Note: The amortized cost per operation for this algorithm is known to be bounded by a function known as the inverse Ackermann function and is less than 5 for any conceivable practical value of N." 1,14,Weighted quick‑union by height. Develop a UF implementation that uses the same basic strategy as weighted quick‑union but keeps track of tree height and always links the shorter tree to the taller one. Prove a logarithmic upper bound on the height of the trees for N sites with your algorithm. 1,15,Binomial trees. Show that the number of nodes at each level in the worst‑case trees for weighted quick‑union are binomial coefficients. Compute the average depth of a node in a worst‑case tree with \(N = 2^{n}\) nodes. 1,16,Amortized costs plots. Instrument your implementations from Exercise 1.5.7 to make amortized costs plots like those in the text. 1,17,"Random connections. Develop a UF client **ErdosRenyi** that takes an integer value N from the command line, generates random pairs of integers between 0 and N‑1, calling connected() to determine if they are connected and then union() if not (as in our development client), looping until all sites are connected, and printing the number of connections generated. Package your program as a static method count() that takes N as argument and returns the number of connections and a main() that takes N from the command line, calls count(), and prints the returned value." 1,18,"Random grid generator. Write a program **RandomGrid** that takes an int value N from the command line, generates all the connections in an \(N\times N\) grid, puts them in random order, randomly orients them (so that p q and q p are equally likely to occur), and prints the result to standard output. To randomly order the connections, use a RandomBag (see Exercise 1.3.34 on page 167). To encapsulate p and q in a single object, use the Connection nested class shown below. Package your program as two static methods: generate(), which takes N as argument and returns an array of connections, and main(), which takes N from the command line, calls generate(), and iterates through the returned array to print the connections." 1,19,Animation. Write a RandomGrid client (see Exercise 1.5.18) that uses UnionFind as in our development client to check connectivity and uses StdDraw to draw the connections as they are processed. 1,20,"Dynamic growth. Using linked lists or a resizing array, develop a weighted quick‑union implementation that removes the restriction on needing the number of objects ahead of time. Add a method newSite() to the API, which returns an int identifier." 1,21,Erdös‑Renyi model. Use your client from Exercise 1.5.17 to test the hypothesis that the number of pairs generated to get one component is \(\sim \tfrac{1}{2}N\ln N\). 1,22,"Doubling test for Erdös‑Renyi model. Develop a performance‑testing client that takes an int value T from the command line and performs T trials of the following experiment: Use your client from Exercise 1.5.17 to generate random connections, using UnionFind to determine connectivity as in our development client, looping until all sites are connected. For each N, print the value of N, the average number of connections processed, and the ratio of the running time to the previous. Use your program to validate the hypotheses in the text that the running times for quick‑find and quick‑union are quadratic and weighted quick‑union is near‑linear." 1,23,"Compare quick‑find with quick‑union for Erdös‑Renyi model. Develop a performance‑testing client that takes an int value T from the command line and performs T trials of the following experiment: Use your client from Exercise 1.5.17 to generate random connections. Save the connections, so that you can use both quick‑union and quick‑find to determine connectivity as in our development client, looping until all sites are connected. For each N, print the value of N and the ratio of the two running times." 1,24,Fast algorithms for Erdös‑Renyi model. Add weighted quick‑union and weighted quick‑union with path compression to your tests from Exercise 1.5.23. Can you discern a difference between these two algorithms? 1,25,"Doubling test for random grids. Develop a performance‑testing client that takes an int value T from the command line and performs T trials of the following experiment: Use your client from Exercise 1.5.18 to generate the connections in an \(N\times N\) square grid, randomly oriented and in random order, then use UnionFind to determine connectivity as in our development client, looping until all sites are connected. For each N, print the value of N, the average number of connections processed, and the ratio of the running time to the previous. Use your program to validate the hypotheses in the text that the running times for quick‑find and quick‑union are quadratic and weighted quick‑union is near‑linear. Note: As N doubles, the number of sites in the grid increases by a factor of 4, so expect a doubling factor of 16 for quadratic and 4 for linear." 2,1,"Consider the following implementation of the compareTo() method for String. How does the third line help with efficiency? ``java public int compareTo(String that) { if (this == that) return 0; // this line int n = Math.min(this.length(), that.length()); for (int i = 0; i < n; i++) { if (this.charAt(i) < that.charAt(i)) return -1; else if (this.charAt(i) > that.charAt(i)) return +1; } return this.length() - that.length(); } ``" 2,2,"Write a program that reads a list of words from standard input and prints all two‑word compound words in the list. For example, if after, thought, and afterthought are in the list, then afterthought is a compound word." 2,3,Criticize the following implementation of a class intended to represent account balances. Why is compareTo() a flawed implementation of the Comparable interface? ``java public class Balance implements Comparable { ... private double amount; public int compareTo(Balance that) { if (this.amount < that.amount - 0.005) return -1; if (this.amount > that.amount + 0.005) return +1; return 0; } ... } `` Describe a way to fix this problem. 2,4,"Implement a method String[] dedup(String[] a) that returns the objects in a[] in sorted order, with duplicates removed." 2,5,Explain why selection sort is not stable. 2,6,Implement a recursive version of select(). 2,7,"About how many compares are required, on the average, to find the smallest of \(N\) items using select()?" 2,8,"Write a program Frequency that reads strings from standard input and prints the number of times each string occurs, in descending order of frequency." 2,9,Develop a data type that allows you to write a client that can sort a file such as the one shown at right. *(The file listing is omitted here.)* 2,10,"Create a data type Version that represents a software version number, such as 115.1.1, 115.10.1, 115.10.2. Implement the Comparable interface so that 115.1.1 is less than 115.10.1, and so forth." 2,11,"One way to describe the result of a sorting algorithm is to specify a permutation p[] of the numbers 0 to a.length-1, such that p[i] specifies where the key originally in a[i] ends up. Give the permutations that describe the results of insertion sort, selection sort, shellsort, mergesort, quicksort, and heapsort for an array of seven equal keys." 2,12,"Scheduling. Write a program SPT.java that reads job names and processing times from standard input and prints a schedule that minimizes average completion time using the shortest processing time first rule, as described on page 349." 2,13,"Load balancing. Write a program LPT.java that takes an integer M as a command‑line argument, reads job names and processing times from standard input and prints a schedule assigning the jobs to M processors that approximately minimizes the time when the last job completes using the longest processing time first rule, as described on page 349." 2,14,"Sort by reverse domain. Write a data type Domain that represents domain names, including an appropriate compareTo() method where the natural order is in order of the reverse domain name. For example, the reverse domain of cs.princeton.edu is edu.princeton.cs. This is useful for web log analysis. Hint: Use s.split(""\\."") to split the string s into tokens, delimited by dots. Write a client that reads domain names from standard input and prints the reverse domains in sorted order." 2,15,"Spam campaign. To initiate an illegal spam campaign, you have a list of email addresses from various domains (the part of the email address that follows the @ symbol). To better forge the return addresses, you want to send the email from another user at the same domain. For example, you might want to forge an email from wayne@princeton.edu to rs@princeton.edu. How would you process the email list to make this an efficient task?" 2,16,"Unbiased election. In order to thwart bias against candidates whose names appear toward the end of the alphabet, California sorted the candidates appearing on its 2003 gubernatorial ballot by using the following order of characters: R W Q O J M V A H B S G Z X N T C I E K U P D Y F L. Create a data type where this is the natural order and write a client California with a single static method main() that sorts strings according to this ordering. Assume that each string is composed solely of uppercase letters." 2,17,"Check stability. Extend your check() method from Exercise 2.1.16 to call sort() for a given array and return true if sort() sorts the array in order in a stable manner, false otherwise. Do not assume that sort() is restricted to move data only with exch()." 2,18,"Force stability. Write a wrapper method that makes any sort stable by creating a new key type that allows you to append each key’s index to the key, call sort(), then restore the original key after the sort." 2,19,Kendall tau distance. Write a program KendallTau.java that computes the Kendall tau distance between two permutations in linearithmic time. 2,20,"Idle time. Suppose that a parallel machine processes \(N\) jobs. Write a program that, given the list of job start and finish times, finds the largest interval where the machine is idle and the largest interval where the machine is not idle." 2,21,"Multidimensional sort. Write a Vector data type for use in having the sort‑ing methods sort multidimensional vectors of \(d\) integers, putting the vectors in order by first component, those with equal first component in order by second component, those with equal first and second components in order by third component, and so forth." 2,22,"Stock market trading. Investors place buy and sell orders for a particular stock on an electronic exchange, specifying a maximum buy or minimum sell price that they are willing to pay, and how many shares they wish to trade at that price. Develop a program that uses priority queues to match up buyers and sellers and test it through simulation. Maintain two priority queues, one for buyers and one for sellers, executing trades whenever a new order can be matched with an existing order or orders." 2,23,Sampling for selection. Investigate the idea of using sampling to improve selection. Hint: Using the median may not always be helpful. 2,24,Stable priority queue. Develop a stable priority‑queue implementation (which returns duplicate keys in the same order in which they were inserted). 2,25,"Points in the plane. Write three static comparators for the Point2D data type of page 77, one that compares points by their \(x\) coordinate, one that compares them by their \(y\) coordinate, and one that compares them by their distance from the origin. Write two non‑static comparators for the Point2D data type, one that compares them by their distance to a specified point and one that compares them by their polar angle with respect to a specified point." 2,26,"Simple polygon. Given \(N\) points in the plane, draw a simple polygon with \(N\) vertices. Hint: Find the point \(p\) with the smallest \(y\) coordinate, breaking ties with the smallest \(x\) coordinate. Connect the points in increasing order of the polar angle they make with \(p\)." 2,27,"Sorting parallel arrays. When sorting parallel arrays, it is useful to have a version of a sorting routine that returns a permutation, say index[], of the indices in sorted order. Add a method indirectSort() to Insertion that takes an array of Comparable objects a[] as argument, but instead of rearranging the entries of a[] returns an integer array index[] so that a[index[0]] through a[index[N-1]] are the items in ascending order." 2,28,"Sort files by name. Write a program FileSorter that takes the name of a directory as a command‑line argument and prints out all of the files in the current directory, sorted by file name. Hint: Use the File data type." 2,29,"Sort files by size and date of last modification. Write comparators for the type File to order by increasing/decreasing order of file size, ascending/descending order of file name, and ascending/descending order of last modification date. Use these comparators in a program LS that takes a command‑line argument and lists the files in the current directory according to a specified order, e.g., “-t” to sort by timestamp. Support multiple flags to break ties. Be sure to use a stable sort." 2,30,"Boerner’s theorem. True or false: If you sort each column of a matrix, then sort each row, the columns are still sorted. Justify your answer." 2,31,"Duplicates. Write a client that takes integers M, N, and T as command‑line arguments, then uses the code given in the text to perform T trials of the following experiment: Generate N random int values between 0 and M – 1 and count the number of duplicates. Run your program for T = 10 and N = 10^3, 10^4, 10^5, and 10^6, with M = N / 2, N, and 2N. Probability theory says that the number of duplicates should be about \((1 – e^{-\lambda})\) where \(\lambda = N / M\) — print a table to help you confirm that your experiments validate that formula." 2,32,"8 puzzle. The 8 puzzle is a game popularized by S. Loyd in the 1870s. It is played on a 3‑by‑3 grid with 8 tiles labeled 1 through 8 and a blank square. Your goal is to rearrange the tiles so that they are in order. You are permitted to slide one of the available tiles horizontally or vertically (but not diagonally) into the blank square. Write a program that solves the puzzle using the A* algorithm. Start by using as priority the sum of the number of moves made to get to this board position plus the number of tiles in the wrong position. (Note that the number of moves you must make from a given board position is at least as big as the number of tiles in the wrong place.) Investigate substituting other functions for the number of tiles in the wrong position, such as the sum of the Manhattan distance from each tile to its correct position, or the sums of the squares of these distances." 2,33,"Random transactions. Develop a generator that takes an argument N, generates N random Transaction objects (see Exercises 2.1.21 and 2.1.22), using assumptions about the transactions that you can defend. Then compare the performance of shellsort, mergesort, quicksort, and heapsort for sorting N transactions, for N=10^3, 10^4, 10^5, and 10^6." 2,1,"Implement SET and HashSET as “wrapper class” clients of ST and HashST, respectively (provide dummy values and ignore them)." 2,2,Develop a SET implementation SequentialSearchSET by starting with the code for SequentialSearchST and eliminating all of the code involving values. 2,3,Develop a SET implementation BinarySearchSET by starting with the code for BinarySearchST and eliminating all of the code involving values. 2,4,"Develop classes HashSTint and HashSTdouble for maintaining sets of keys of primitive int and double types, respectively. (Convert generics to primitive types in the code of LinearProbingHashST.)" 2,5,"Develop classes STint and STdouble for maintaining ordered symbol tables where keys are primitive int and double types, respectively. (Convert generics to primitive types in the code of RedBlackBST.) Test your solution with a version of SparseVector as a client." 2,6,"Develop classes HashSETint and HashSETdouble for maintaining sets of keys of primitive int and double types, respectively. (Eliminate code involving values in your solution to Exercise 3.5.4.)" 2,7,"Develop classes SETint and SETdouble for maintaining ordered sets of keys of primitive int and double types, respectively. (Eliminate code involving values in your solution to Exercise 3.5.5.)" 2,8,"Modify LinearProbingHashST to keep duplicate keys in the table. Return any value associated with the given key for get(), and remove all items in the table that have keys equal to the given key for delete." 2,9,"Modify BST to keep duplicate keys in the tree. Return any value associated with the given key for get(), and remove all nodes in the tree that have keys equal to the given key for delete." 2,10,"Modify RedBlackBST to keep duplicate keys in the tree. Return any value associated with the given key for get(), and remove all nodes in the tree that have keys equal to the given key for delete." 2,11,"Develop a MultiSET class that is like SET, but allows equal keys and thus implements a mathematical multiset." 2,12,"Modify LookupCSV to associate with each key all values that appear in a key‑value pair with that key in the input (not just the most recent, as in the associative‑array abstraction)." 2,13,Modify LookupCSV to make a program RangeLookupCSV that takes two key values from the standard input and prints all key‑value pairs in the .csv file such that the key falls within the range specified. 2,14,"Develop and test a static method invert() that takes as argument an ST<String, Bag<String>> and produces as return value the inverse of the given symbol table (a symbol table of the same type)." 2,15,"Write a program that takes a string on standard input and an integer k as command‑line argument and puts on standard output a sorted list of the k‑grams found in the string, each followed by its index in the string." 2,16,Add a method sum() to SparseVector that takes a SparseVector as argument and returns a SparseVector that is the term‑by‑term sum of this vector and the argument vector. Note: You need delete() (and special attention to precision) to handle the case where an entry becomes 0. 2,17,Mathematical sets. Your goal is to develop an implementation of the following API MathSET for processing (mutable) mathematical sets: `` public class MathSET MathSET(Key[] universe) // create a set void add(Key key) // put key into the set MathSET complement() // set of keys in the universe that are not in this set void union(MathSET a) // put any keys from a into the set that are not already there void intersection(MathSET a) // remove any keys from this set that are not in a void delete(Key key) // remove key from the set boolean contains(Key key) // is key in the set? boolean isEmpty() // is the set empty? int size() // number of keys in the set `` Use a symbol table. Extra credit: Represent sets with arrays of boolean values. 2,18,"Multisets. After referring to Exercises 3.5.2 and 3.5.3 and the previous exercise, develop APIs MultiHashSET and MultiSET for multisets (sets that can have equal keys) and implementations SeparateChainingMultiSET and BinarySearchMultiSET for multisets and ordered multisets, respectively." 2,19,"Equal keys in symbol tables. Consider the API MultiST (unordered or ordered) to be the same as our symbol‑table APIs defined on pages 363 and 366, but with equal keys allowed, so that the semantics of get() is to return any value associated with the given key, and we add a new method `` Iterable getAll(Key key) // returns all values associated with the given key `` Using our code for SeparateChainingST and BinarySearchST as a starting point, develop implementations SeparateChainingMultiST and BinarySearchMultiST for these APIs." 2,20,Concordance. Write an ST client Concordance that puts on standard output a concordance of the strings in the standard input stream (see page 498). 2,21,"Inverted concordance. Write a program InvertedConcordance that takes a concordance on standard input and puts the original string on standard output stream. Note: This computation is associated with a famous story having to do with the Dead Sea Scrolls. The team that discovered the original tablets enforced a secrecy rule that essentially resulted in their making public only a concordance. After a while, other researchers figured out how to invert the concordance, and the full text was eventually made public." 2,22,"Fully indexed CSV. Implement an ST client FullLookupCSV that builds an array of ST objects (one for each field), with a test client that allows the user to specify the key and value fields in each query." 2,23,Sparse matrices. Develop an API and an implementation for sparse 2D matrices. Support matrix addition and matrix multiplication. Include constructors for row and column vectors. 2,24,"Non‑overlapping interval search. Given a list of non‑overlapping intervals of items, write a function that takes an item as argument and determines in which, if any, interval that item lies. For example, if the items are integers and the intervals are 1643‑2033, 5532‑7643, 8999‑10332, 5666653‑5669321, then the query point 9122 lies in the third interval and 8122 lies in no interval." 2,25,"Registrar scheduling. The registrar at a prominent northeastern University recently scheduled an instructor to teach two different classes at the same exact time. Help the registrar prevent future mistakes by describing a method to check for such conflicts. For simplicity, assume all classes run for 50 minutes starting at 9:00, 10:00, 11:00, 1:00, 2:00, or 3:00." 2,26,"LRU cache. Create a data structure that supports the following operations: access and remove. The access operation inserts the item onto the data structure if it’s not already present. The remove operation deletes and returns the item that was least recently accessed. Hint: Maintain the items in order of access in a doubly linked list, along with pointers to the first and last nodes. Use a symbol table with keys = items, values = location in linked list. When you access an element, delete it from the linked list and reinsert it at the beginning. When you remove an element, delete it from the end and remove it from the symbol table." 2,27,"List. Develop an implementation of the following API: `` public class List implements Iterable List() // create a list void addFront(Item item) // add item to the front void addBack(Item item) // add item to the back Item deleteFront() // remove from the front Item deleteBack() // remove from the back void delete(Item item) // remove item from the list void add(int i, Item item) // add item as the ith in the list Item delete(int i) // remove the ith item from the list boolean contains(Item item) // is key in the list? boolean isEmpty() // is the list empty? int size() // number of items in the list `` Hint: Use two symbol tables, one to find the ith item in the list efficiently, and the other to efficiently search by item. (Java’s java.util.List interface contains methods like these but does not supply any implementation that efficiently supports all operations.)" 2,28,"UniQueue. Create a data type that is a queue, except that an element may only be inserted into the queue once. Use an existence symbol table to keep track of all elements that have ever been inserted and ignore requests to re‑insert such items." 2,29,"Symbol table with random access. Create a data type that supports inserting a key‑value pair, searching for a key and returning the associated value, and deleting and returning a random key. Hint: Combine a symbol table and a randomized queue." 2,30,"Duplicates (revisited). Redo Exercise 2.5.31 using the Dedup filter given on page 490. Compare the running times of the two approaches. Then use Dedup to run the experiments for N = 10⁷, 10⁸, and 10⁹, repeat the experiments for random long values and discuss the results." 2,31,"Spell checker. With the file dictionary.txt from the booksite as command‑line argument, the BlackFilter client described on page 491 prints all misspelled words in a text file taken from standard input. Compare the performance of RedBlackBST, SeparateChainingHashST, and LinearProbingHashST for the file WarAndPeace.txt (available on the booksite) with this client and discuss the results." 2,32,"Dictionary. Study the performance of a client like LookupCSV in a scenario where performance matters. Specifically, design a query‑generation scenario instead of taking commands from standard input, and run performance tests for large inputs and large numbers of queries." 2,33,"Indexing. Study a client like LookupIndex in a scenario where performance matters. Specifically, design a query‑generation scenario instead of having commands from standard input, and run performance tests for large inputs and large numbers of queries." 2,34,Sparse vector. Run experiments to compare the performance of matrix‑vector multiplication using SparseVector to the standard implementation using arrays. 2,35,"Primitive types. Evaluate the utility of using primitive types for Integer and Double values, for LinearProbingHashST and RedBlackBST. How much space and time are saved, for large numbers of searches in large tables?" 4,1,True or false: Adding a constant to every edge weight does not change the solution to the single‑source shortest‑paths problem. 4,2,Provide an implementation of toString() for EdgeWeightedDigraph. 4,3,Develop an implementation of EdgeWeightedDigraph for dense graphs that uses an adjacency‑matrix (two‑dimensional array of weights) representation (see Exercise 4.3.9). Ignore parallel edges. 4,4,"Draw the SPT for source 0 of the edge‑weighted digraph obtained by deleting vertex 7 from tinyEWD.txt (see page 644), and give the parent‑link representation of the SPT. Answer the question for the same graph with all edges reversed." 4,5,Change the direction of edge 0→2 in tinyEWD.txt (see page 644). Draw two different SPTs that are rooted at 2 for this modified edge‑weighted digraph. 4,6,Give a trace that shows the process of computing the SPT of the digraph defined in Exercise 4.4.5 with the eager version of Dijkstra’s algorithm. 4,7,Develop a version of DijkstraSP that supports a client method that returns a second shortest path from s to t in an edge‑weighted digraph (and returns null if there is only one shortest path from s to t). 4,8,The diameter of a digraph is the length of the maximum‑length shortest path connecting two vertices. Write a DijkstraSP client that finds the diameter of a given EdgeWeightedDigraph that has nonnegative weights. 4,9,"The table below, from an old published road map, purports to give the length of the shortest routes connecting the cities. It contains an error. Correct the table. Also, add a table that shows how to achieve the shortest routes. Providence Westerly New London Norwich Providence - 53 54 48 Westerly 53 - 18 101 New London 54 18 - 12 Norwich 48 101 12 - 685" 4,10,Consider the edges in the digraph defined in Exercise 4.4.4 to be undirected edges such that each edge corresponds to equal‑weight edges in both directions in the edge‑weighted digraph. Answer Exercise 4.4.6 for this corresponding edge‑weighted digraph. 4,11,Use the memory‑cost model of Section 1.4 to determine the amount of memory used by EdgeWeightedDigraph to represent a graph with V vertices and E edges. 4,12,"Adapt the DirectedCycle and Topological classes from Section 4.2 to use the EdgeWeightedDigraph and DirectedEdge APIs of this section, thus implementing EdgeWeightedCycleFinder and EdgeWeightedTopological classes." 4,13,"Show, in the style of the trace in the text, the process of computing the SPT with Dijkstra’s algorithm for the digraph obtained by removing the edge 5→7 from tinyEWD.txt (see page 644)." 4,14,Show the paths that would be discovered by the two strawman approaches described on page 668 for the example tinyEWDn.txt shown on that page. 4,15,What happens to Bellman‑Ford if there is a negative cycle on the path from s to v and then you call pathTo(v)? 4,16,Suppose that we convert an EdgeWeightedGraph into an EdgeWeightedDigraph by creating two DirectedEdge objects in the EdgeWeightedDigraph (one in each direction) for each Edge in the EdgeWeightedGraph (as described for Dijkstra’s algorithm in the Q&A on page 684) and then use the Bellman‑Ford algorithm. Explain why this approach fails spectacularly. 4,17,"What happens if you allow a vertex to be enqueued more than once in the same pass in the Bellman‑Ford algorithm? Answer : The running time of the algorithm can go exponential. For example, describe what happens for the complete edge‑weighted digraph whose edge weights are all -1." 4,18,Write a CPM client that prints all critical paths. 4,19,Find the lowest‑weight cycle (best arbitrage opportunity) in the example shown in the text. 4,20,Find a currency‑conversion table online or in a newspaper. Use it to build an arbitrage table. Note : Avoid tables that are derived (calculated) from a few values and that therefore do not give sufficiently accurate conversion information to be interesting. Extra credit : Make a killing in the money‑exchange market! 4,21,"Show, in the style of the trace in the text, the process of computing the SPT with the Bellman‑Ford algorithm for the edge‑weighted digraph of Exercise 4.4.5." 4,22,Vertex weights. Show that shortest‑paths computations in edge‑weighted digraphs with nonnegative weights on vertices (where the weight of a path is defined to be the sum of the weights of the vertices) can be handled by building an edge‑weighted digraph that has weights on only the edges. 4,23,Source‑sink shortest paths. Develop an API and implementation that use a version of Dijkstra’s algorithm to solve the source‑sink shortest‑path problem on edge‑weighted digraphs. 4,24,"Multisource shortest paths. Develop an API and implementation that uses Dijkstra’s algorithm to solve the multisource shortest‑paths problem on edge‑weighted digraphs with positive edge weights: given a set of sources, find a shortest‑paths forest that enables implementation of a method that returns to clients the shortest path from any source to each vertex. Hint : Add a dummy vertex with a zero‑weight edge to each source, or initialize the priority queue with all sources, with their distTo[] entries set to 0." 4,25,"Shortest path between two subsets. Given a digraph with positive edge weights, and two distinguished subsets of vertices S and T, find a shortest path from any vertex in S to any vertex in T. Your algorithm should run in time proportional to E log V, in the worst case." 4,26,Single‑source shortest paths in dense graphs. Develop a version of Dijkstra’s algorithm that can find the SPT from a given vertex in a dense edge‑weighted digraph in time proportional to V². Use an adjacency‑matrix representation (see Exercise 4.4.3 and Exercise 4.3.29). 4,27,Shortest paths in Euclidean graphs. Adapt our APIs to speed up Dijkstra’s algorithm in the case where it is known that vertices are points in the plane. 4,28,"Longest paths in DAGs. Develop an implementation AcyclicLP that can solve the longest‑paths problem in edge‑weighted DAGs, as described in Proposition T." 4,29,"General optimality. Complete the proof of Proposition W by showing that if there exists a directed path from s to v and no vertex on any path from s to v is on a negative cycle, then there exists a shortest path from s to v (Hint : See Proposition P.)." 4,30,"All‑pairs shortest path in graphs with negative cycles. Articulate an API like the one implemented on page 656 for the all‑pairs shortest‑paths problem in graphs with no negative cycles. Develop an implementation that runs a version of Bellman‑Ford to identify weights π[v] such that for any edge v→w, the edge weight plus the difference between π[v] and π[w] is nonnegative. Then use these weights to reweight the graph, so that Dijkstra’s algorithm is effective for finding all shortest paths in the reweighted graph." 4,31,"All‑pairs shortest path on a line. Given a weighted line graph (undirected connected graph, all vertices of degree 2, except two endpoints which have degree 1), devise an algorithm that preprocesses the graph in linear time and can return the distance of the shortest path between any two vertices in constant time." 4,32,"Parent‑checking heuristic. Modify Bellman‑Ford to visit a vertex v only if its SPT parent edgeTo[v] is not currently on the queue. This heuristic has been reported by Cherkassky, Goldberg, and Radzik to be useful in practice. Prove that it correctly computes shortest paths and that the worst‑case running time is proportional to Ε V." 4,33,"Shortest path in a grid. Given an N‑by‑N matrix of positive integers, find the shortest path from the (0, 0) entry to the (N–1, N–1) entry, where the length of the path is the sum of the integers in the path. Repeat the problem but assume you can only move right and down." 4,34,"Monotonic shortest path. Given a weighted digraph, find a monotonic shortest path from s to every other vertex. A path is monotonic if the weight of every edge on the path is either strictly increasing or strictly decreasing. The path should be simple (no repeated vertices). Hint : Relax edges in ascending order and find a best path; then relax edges in descending order and find a best path." 4,35,"Bitonic shortest path. Given a digraph, find a bitonic shortest path from s to every other vertex (if one exists). A path is bitonic if there is an intermediate vertex v such that the edges on the path from s to v are strictly increasing and the edges on the path from v to t are strictly decreasing. The path should be simple (no repeated vertices)." 4,36,"Neighbors. Develop an SP client that finds all vertices within a given distance d of a given vertex in a given edge‑weighted digraph. The running time of your method should be proportional to the size of the subgraph induced by those vertices and the vertices incident on them, or V (to initialize data structures), whichever is larger." 4,37,Critical edges. Develop an algorithm for finding an edge whose removal causes maximal increase in the shortest‑paths length from one given vertex to another given vertex in a given edge‑weighted digraph. 4,38,"Sensitivity. Develop an SP client that performs a sensitivity analysis on the edge‑weighted digraph’s edges with respect to a given pair of vertices s and t: Compute a V‑by‑V boolean matrix such that, for every v and w, the entry in row v and column w is true if v→w is an edge in the edge‑weighted digraphs whose weight can be increased without the shortest‑path length from v to w being increased and is false otherwise." 4,39,Lazy implementation of Dijkstra’s algorithm. Develop an implementation of the lazy version of Dijkstra’s algorithm that is described in the text. 4,40,"Bottleneck SPT. Show that an MST of an undirected graph is equivalent to a bottleneck SPT of the graph: For every pair of vertices v and w, it gives the path connecting them whose longest edge is as short as possible." 4,41,Bidirectional search. Develop a class for the source‑sink shortest‑paths problem that is based on code like Algorithm 4.9 but that initializes the priority queue with both the source and the sink. Doing so leads to the growth of an SPT from each vertex; your main task is to decide precisely what to do when the two SPTs collide. 4,42,Worst case (Dijkstra). Describe a family of graphs with V vertices and E edges for which the worst‑case running time of Dijkstra’s algorithm is achieved. 4,43,"Negative cycle detection. Suppose that we add a constructor to Algorithm 4.11 that differs from the constructor given only in that it omits the second argument and that it initializes all distTo[] entries to 0. Show that, if a client uses that constructor, a client call to hasNegativeCycle() returns true if and only if the graph has a negative cycle (and negativeCycle() returns that cycle). Answer : Consider a digraph formed from the original by adding a new source with an edge of weight 0 to all the other vertices. After one pass, all distTo[] entries are 0, and finding a negative cycle reachable from that source is the same as finding a negative cycle anywhere in the original graph." 4,44,Worst case (Bellman‑Ford). Describe a family of graphs for which Algorithm 4.11 takes time proportional to V E. 4,45,Fast Bellman‑Ford. Develop an algorithm that breaks the linearithmic running time barrier for the single‑source shortest‑paths problem in general edge‑weighted digraphs for the special case where the weights are integers known to be bounded in absolute value by a constant. 4,46,Animate. Write a client program that does dynamic graphical animations of Dijkstra’s algorithm. 4,47,Random sparse edge‑weighted digraphs. Modify your solution to Exercise 4.3.34 to assign a random direction to each edge. 4,48,Random Euclidean edge‑weighted digraphs. Modify your solution to Exercise 4.3.35 to assign a random direction to each edge. 4,49,Random grid edge‑weighted digraphs. Modify your solution to Exercise 4.3.36 to assign a random direction to each edge. 4,50,Negative weights I. Modify your random edge‑weighted digraph generators to generate weights between x and y (where x and y are both between –1 and 1) by rescaling. 4,51,Negative weights II. Modify your random edge‑weighted digraph generators to generate negative weights by negating a fixed percentage (whose value is supplied by the client) of the edge weights. 4,52,"Negative weights III. Develop client programs that use your edge‑weighted digraph to produce edge‑weighted digraphs that have a large percentage of negative weights but have at most a few negative cycles, for as large a range of values of V and E as possible." 4,53,"Prediction. Estimate, to within a factor of 10, the largest graph with E = 10V that your computer and programming system could handle if you were to use Dijkstra’s algorithm to compute all its shortest paths in 10 seconds." 4,54,"Cost of laziness. Run empirical studies to compare the performance of the lazy version of Dijkstra’s algorithm with the eager version, for various edge‑weighted di‑graph models." 4,55,Johnson’s algorithm. Develop a priority‑queue implementation that uses a d‑way heap. Find the best value of d for various edge‑weighted digraph models. 4,56,Arbitrage model. Develop a model for generating random arbitrage problems. Your goal is to generate tables that are as similar as possible to the tables that you used in Exercise 4.4.20. 4,57,Parallel job‑scheduling‑with‑deadlines model. Develop a model for generating random instances of the parallel job‑scheduling‑with‑deadlines problem. Your goal is to generate nontrivial problems that are likely to be feasible. 5,1,"Consider the four variable‑length codes shown in the table at right. Which of the codes are prefix‑free? Uniquely decodable? For those that are uniquely decod‑able, give the encoding of 1000000000000." 5,2,Given a example of a uniquely decodable code that is not prefix‑free. Answer : Any suffix‑free code is uniquely decodable. 5,3,"Give an example of a uniquely decodable code that is not prefix free or suffix free. Answer : {0011, 011, 11, 1110} or {01, 10, 011, 110}" 5,4,"Are { 01, 1001, 1011, 111, 1110 } and { 01, 1001, 1011, 111, 1110 } unique‑ly decodable? If not, find a string with two encodings." 5,5,Use RunLength on the file q128x192.bin from the booksite. How many bits are there in the compressed file? 5,6,How many bits are needed to encode N copies of the symbol a (as a function of N)? N copies of the sequence abc? 5,7,"Give the result of encoding the strings a, aa, aaa, aaaa, ... (strings consisting of N a’s) with run‑length, Huffman, and LZW encoding. What is the compression ratio as a function of N?" 5,8,"Give the result of encoding the strings ab, abab, ababab, abababab, ... (strings consisting of N repetitions of ab) with run‑length, Huffman, and LZW encoding. What is the compression ratio as a function of N?" 5,9,"Estimate the compression ratio achieved by run‑length, Huffman, and LZW en‑coding for a random ASCII string of length N (all characters equally likely at each position, independently)." 5,10,"In the style of the figure in the text, show the Huffman coding tree construction process when you use Huffman for the string ""it was the age of foolishness”. How many bits does the compressed bitstream require?" 5,11,What is the Huffman code for a string whose characters are all from a two‑character alphabet? Give an example showing the maximum number of bits that could be used in a Huffman code for an N‑character string whose characters are all from a two‑character alphabet. 5,12,Suppose that all of the symbol probabilities are negative powers of 2. Describe the Huffman code. 5,13,Suppose that all of the symbol frequencies are equal. Describe the Huffman code. 5,14,Suppose that the frequencies of the occurrence of all the characters to be encoded are different. Is the Huffman encoding tree unique? 5,15,Huffman coding could be extended in a straightforward way to encode in 2‑bit characters (using 4‑way trees). What would be the main advantage and the main disadvantage of doing so? 5,16,What is the LZW encoding of the following inputs? a. T O B E O R N O T T O B E b. Y A B B A D A B B A D A B B A D O O c. A A A A A A A A A A A A A A A A A A A A 5,17,"Characterize the tricky situation in LZW coding. Solution : Whenever it encounters cScSc, where c is a symbol and S is a string, cS is in the dictionary already but cSc is not." 5,18,"Let Fn be the k th Fibonacci number. Consider N symbols, where the k th symbol has frequency Fk. Note that F1 + F1 + … + FN = FN+2 – 1. Describe the Huffman code. Hint : The longest codeword has length N – 1." 5,19,Show that there are at least 2N – 1 different Huffman codes corresponding to a given set of N symbols. 5,20,"Give a Huffman code where the frequency of 0s in the output is much, much higher than the frequency of 1s. Answer : If the character A occurs 1 million times and the character B occurs once, the codeword for A will be 0 and the codeword for B will be 1." 5,21,Prove that the two longest codewords in a Huffman code have the same length. 5,22,"Prove the following fact about Huffman codes: If the frequency of symbol i is strictly larger than the frequency of symbol j, then the length of the codeword for symbol i is less than or equal to the length of the codeword for symbol j." 5,23,What would be the result of breaking up a Huffman‑encoded string into five‑bit characters and Huffman‑encoding that string? 5,24,"In the style of the figures in the text, show the encoding trie and the compression and expansion processes when LZW is used for the string ""it was the best of times it was the worst of times""." 5,25,"Fixed length width code. Implement a class RLE that uses fixed‑length encoding, to compress ASCII bytestreams using relatively few different characters, including the code as part of the encoded bitstream. Add code to compress() to make a string alpha with all the distinct characters in the message and use it to make an Alphabet for use in compress(), prepend alpha (8‑bit encoding plus its length) to the compressed bitstream, then add code to expand() to read the alphabet before expansion." 5,26,Rebuilding the LZW dictionary. Modify LZW to empty the dictionary and start over when it is full. This approach is recommended in some applications because it bet­ter adapts to changes in the general character of the input. 5,27,"Long repeats. Estimate the compression ratio achieved by run‑length, Huffman, and LZW encoding for a string of length 2N formed by concatenating two copies of a random ASCII string of length N (see Exercise 5.5.9), under any assumptions that you think are reasonable." 6,1,"Maxwell‑Boltzmann. The distribution of velocity of particles in the hard disc model obeys the Maxwell‑Boltzmann distribution (assuming that the system has thermalized and particles are sufficiently heavy that we can discount quantum‑mechanical effects), which is known as the Rayleigh distribution in two dimensions. The distribution shape depends on temperature. Write a driver that computes a histogram of the particle velocities and test it for various temperatures." 6,2,"Arbitrary shape. Molecules travel very quickly (faster than a speeding jet) but diffuse slowly because they collide with other molecules, thereby changing their direction. Extend the model to have a boundary shape where two vessels are connected by a pipe containing two different types of particles. Run a simulation and measure the fraction of particles of each type in each vessel as a function of time." 6,3,"Rewind. After running a simulation, negate all velocities and then run the system backwards. It should return to its original state! Measure roundoff error by measuring the difference between the final and original states of the system." 6,4,Pressure. Add a method pressure() to Particle that measures pressure by accumulating the number and magnitude of collisions against walls. The pressure of the system is the sum of these quantities. Then add a method pressure() to CollisionSystem and write a client that validates the equation \(pv = nRT\). 6,5,Index priority queue implementation. Develop a version of CollisionSystem that uses an index priority queue to guarantee that the size of the priority queue is at most linear in the number of particles (instead of quadratic or worse). 6,6,"Priority queue performance. Instrument the priority queue and test Pressure at various temperatures to identify the computational bottleneck. If warranted, try switching to a different priority‑queue implementation for better performance at high temperatures." 6,7,"Suppose that, in a three‑level tree, we can afford to keep a links in internal memory, between \(b\) and \(2b\) links in pages representing internal nodes, and between \(c\) and \(2c\) items in pages representing external nodes. What is the maximum number of items that we can hold in such a tree, as a function of \(a\), \(b\), and \(c\)?" 6,8,Develop an implementation of Page that represents each B‑tree node as a BinarySearchST object. 6,9,"Extend BTreeSET to develop a BTreeST implementation that associates keys with values and supports our full ordered symbol table API that includes min(), max(), floor(), ceiling(), deleteMin(), deleteMax(), select(), rank(), and the two‑argument versions of size() and get()." 6,10,"Write a program that uses StdDraw to visualize B‑trees as they grow, as in the text." 6,11,"Estimate the average number of probes per search in a B‑tree for \(S\) random searches, in a typical cache system, where the \(T\) most‑recently‑accessed pages are kept in memory (and therefore add 0 to the probe count). Assume that \(S\) is much larger than \(T\)." 6,12,"Web search. Develop an implementation of Page that represents B‑tree nodes as text files on web pages, for the purposes of indexing (building a concordance for) the web. Use a file of search terms. Take web pages to be indexed from standard input. To keep control, take a command‑line parameter \(m\), and set an upper limit of \(10m\) internal nodes (check with your system administrator before running for large \(m\)). Use an \(m\)-digit number to name your internal nodes. For example, when \(m\) is 4, your nodes names might be BTreeNode0000, BTreeNode0001, BTreeNode0002, and so forth. Keep pairs of strings on pages. Add a close() operation to the API, to sort and write. To test your implementation, look for yourself and your friends on your university’s website." 6,13,"B∗ trees. Consider the sibling split (or B∗‑tree) heuristic for B‑trees: When it comes time to split a node because it contains \(M\) entries, we combine the node with its sibling. If the sibling has \(k\) entries with \(k < M-1\), we reallocate the items giving the sibling and the full node each about \((M+k)/2\) entries. Otherwise, we create a new node and give each of the three nodes about \(2M/3\) entries. Also, we allow the root to grow to hold about \(4M/3\) items, splitting it and creating a new root node with two entries when it reaches that bound. State bounds on the number of probes used for a search or an insertion in a B∗‑tree of order \(M\) with \(N\) items. Compare your bounds with the corresponding bounds for B‑trees (see Proposition B). Develop an insert implementation for B∗‑trees." 6,14,Write a program to compute the average number of external pages for a B‑tree of order \(M\) built from \(N\) random insertions into an initially empty tree. Run your program for reasonable values of \(M\) and \(N\). 6,15,"If your system supports virtual memory, design and conduct experiments to compare the performance of B‑trees with that of binary search, for random searches in a huge symbol table." 6,16,"For your internal‑memory implementation of Page in EXERCISE 6.15, run experiments to determine the value of \(M\) that leads to the fastest search times for a B‑tree implementation supporting random search operations in a huge symbol table. Restrict attention to values of \(M\) that are multiples of 100." 6,17,"Run experiments to compare search times for internal B‑trees (using the value of \(M\) determined in the previous exercise), linear probing hashing, and red‑black trees for random search operations in a huge symbol table." 6,18,"Give, in the style of the figure on page 882, the suffixes, sorted suffixes, index() and lcp() tables for the following strings: a. abacadaba b. mississippi c. abcdefghij d. aaaaaaaaaa" 6,19,"Identify the problem with the following code fragment to compute all the suffixes for suffix sort: ``c suffix = """"; for (int i = s.length() - 1; i >= 0; i--) { suffix = s.charAt(i) + suffix; suffixes[i] = suffix; } `` Answer: It uses quadratic time and quadratic space." 6,20,"Some applications require a sort of cyclic rotations of a text, which all contain all the characters of the text. For i from 0 to N-1, the ith cyclic rotation of a text of length N is the last N-i characters followed by the first i characters. Identify the problem with the following code fragment to compute all the cyclic rotations: ``c int N = s.length(); for (int i = 0; i < N; i++) rotation[i] = s.substring(i, N) + s.substring(0, i); `` Answer: It uses quadratic time and quadratic space." 6,21,"Design a linear‑time algorithm to compute all the cyclic rotations of a text string. Answer: ``java String t = s + s; int N = s.length(); for (int i = 0; i < N; i++) rotation[i] = t.substring(i, i + N); ``" 6,22,"Under the assumptions described in Section 1.4, give the memory usage of a SuffixArray object with a string of length \(N\)." 6,23,"Longest common substring. Write a SuffixArray client LCS that takes two file‑names as command‑line arguments, reads the two text files, and finds the longest substring that appears in both in linear time. (In 1970, D. Knuth conjectured that this task was impossible.) Hint: Create a suffix array for s#t where s and t are the two text strings and # is a character that does not appear in either." 6,24,"Burrows‑Wheeler transform. The Burrows‑Wheeler transform (BWT) is a transformation that is used in data compression algorithms, including bzip2 and in high‑throughput sequencing in genomics. Write a SuffixArray client that computes the BWT in linear time, as follows: Given a string of length \(N\) (terminated by a special end‑of‑file character $ that is smaller than any other character), consider the \(N \times N\) matrix in which each row contains a different cyclic rotation of the original text string. Sort the rows lexicographically. The Burrows‑Wheeler transform is the rightmost column in the sorted matrix. For example, the BWT of mississippi$ is ipssm$pissii. The Burrows‑Wheeler inverse transform (BWI) inverts the BWT. For example, the BWI of ipssm$pissii is mississippi$. Also write a client that, given the BWT of a text string, computes the BWI in linear time." 6,25,"Circular string linearization. Write a SuffixArray client that, given a string, finds the cyclic rotation that is the smallest lexicographically in linear time. This problem arises in chemical databases for circular molecules, where each molecule is represented as a circular string, and a canonical representation (smallest cyclic rotation) is used to support search with any rotation as key. (See Exercise 6.27 and Exercise 6.28.)" 6,26,"Longest \(k\)-repeated substring. Write a SuffixArray client that, given a string and an integer \(k\), finds the longest substring that is repeated \(k\) or more times." 6,27,"Long repeated substrings. Write a SuffixArray client that, given a string and an integer \(L\), finds all repeated substrings of length \(L\) or more." 6,28,"\(k\)-gram frequency counts. Develop and implement an ADT for preprocessing a string to support efficiently answering queries of the form “How many times does a given \(k\)-gram appear?” Each query should take time proportional to \(k \log N\) in the worst case, where \(N\) is the length of the string." 6,29,"If capacities are positive integers less than \(M\), what is the maximum possible flow value for any \(st\)-network with \(V\) vertices and \(E\) edges? Give two answers, depending on whether or not parallel edges are allowed." 6,30,Give an algorithm to solve the max‑flow problem for the case that the network forms a tree if the sink is removed. 6,31,"True or false. If true provide a short proof, if false give a counterexample: a. In any max‑flow, there is no directed cycle on which every edge carries positive flow. b. There exists a max‑flow for which there is no directed cycle on which every edge carries positive flow. c. If all edge capacities are distinct, the max‑flow is unique. d. If all edge capacities are increased by an additive constant, the min cut remains unchanged. e. If all edge capacities are multiplied by a positive integer, the min cut remains unchanged." 6,32,"Complete the proof of Proposition G: Show that each time an edge is a critical edge, the length of the augmenting path through it must increase by 2." 6,33,"Find a large network online that you can use as a vehicle for testing flow algorithms on realistic data. Possibilities include transportation networks (road, rail, or air), communications networks (telephone or computer connections), or distribution networks. If capacities are not available, devise a reasonable model to add them. Write a program that uses the interface to implement flow networks from your data. If warranted, develop additional private methods to clean up the data." 6,34,Write a random‑network generator for sparse networks with integer capacities between 0 and 220. Use a separate class for capacities and develop two implementations: one that generates uniformly distributed capacities and another that generates capacities according to a Gaussian distribution. Implement client programs that generate random networks for both weight distributions with a well‑chosen set of values of \(V\) and \(E\) so that you can use them to run empirical tests. 6,35,"Write a program that generates \(V\) random points in the plane, then builds a flow network with edges (in both directions) connecting all pairs of points within a given distance \(d\) of each other, setting each edge’s capacity using one of the random models described in the previous exercise." 6,36,Basic reductions. Develop Ford–Fulkerson clients for finding a max‑flow in each of the following types of flow networks: * Undirected * No constraint on the number of sources or sinks or on edges entering the source or leaving the sink * Lower bounds on capacities * Capacity constraints on vertices 6,37,"Product distribution. Suppose that a flow represents products to be transferred by trucks between cities, with the flow on edge \(u\!-\!v\) representing the amount to be taken from city \(u\) to city \(v\) in a given day. Write a client that prints out daily orders for truckers, telling them how much and where to pick up and how much and where to drop off. Assume that there are no limits on the supply of truckers and that nothing leaves a given distribution point until everything is delivered." 6,38,"Job placement. Develop a Ford–Fulkerson client that solves the job‑placement problem, using the reduction in Proposition J. Use a symbol table to convert symbolic names to integers for use in the flow network." 6,39,Construct a family of bipartite matching problems where the average length of the augmenting paths used by any augmenting‑path algorithm to solve the corresponding max‑flow problem is proportional to \(E\). 6,40,"\(st\)-connectivity. Develop a Ford–Fulkerson client that, given an undirected graph \(G\) and vertices \(s\) and \(t\), finds the minimum number of edges in \(G\) whose removal will disconnect \(t\) from \(s\)." 6,41,"Disjoint paths. Develop a Ford–Fulkerson client that, given an undirected graph \(G\) and vertices \(s\) and \(t\), finds the maximum number of edge‑disjoint paths from \(s\) to \(t\)." 6,42,Find a nontrivial factor of 37703491. 6,43,Prove that the shortest‑paths problem reduces to linear programming. 6,44,"Could there be an algorithm that solves an NP‑complete problem in an average time of \(N \log N\), if \(P \neq NP\)? Explain your answer." 6,45,Suppose that someone discovers an algorithm that is guaranteed to solve the boolean satisfiability problem in time proportional to \(1.1^N\). Does this imply that we can solve other NP‑complete problems in time proportional to \(1.1^N\)? 6,46,What would be the significance of a program that could solve the integer linear programming problem in time proportional to \(1.1^N\)? 6,47,Give a poly‑time reduction from vertex cover to 0‑1 integer linear inequality satisfiability. 6,48,"Prove that the problem of finding a Hamiltonian path in a directed graph is NP‑complete, using the NP‑completeness of the Hamiltonian‑path problem for undirected graphs." 6,49,Suppose that two problems are known to be NP‑complete. Does this imply that there is a poly‑time reduction from one to the other? 6,50,"Suppose that \(X\) is NP‑complete, \(X\) poly‑time reduces to \(Y\), and \(Y\) poly‑time reduces to \(X\). Is \(Y\) necessarily NP‑complete? Answer: No, since \(Y\) may not be in NP." 6,51,"Suppose that we have an algorithm to solve the decision version of boolean satisfiability, which indicates that there exists an assignment of truth values to the variables that satisfies the boolean expression. Show how to find the assignment." 6,52,"Suppose that we have an algorithm to solve the decision version of the vertex‑cover problem, indicating that there exists a vertex cover of a given size. Show how to solve the optimization version of finding the vertex cover of minimum cardinality." 6,53,Explain why the optimization version of the vertex‑cover problem is not necessarily a search problem. 6,54,"Suppose that \(X\) and \(Y\) are two search problems and \(X\) poly‑time reduces to \(Y\). Which of the following can we infer? a. If \(Y\) is NP‑complete then so is \(X\). b. If \(X\) is NP‑complete then so is \(Y\). c. If \(X\) is in \(P\), then \(Y\) is in \(P\). d. If \(Y\) is in \(P\), then \(X\) is in \(P\)." 6,55,"Suppose that \(P \neq NP\). Which of the following can we infer? e. If \(X\) is NP‑complete, then \(X\) cannot be solved in polynomial time. f. If \(X\) is in \(NP\), then \(X\) cannot be solved in polynomial time. g. If \(X\) is in \(NP\) but not NP‑complete, then \(X\) can be solved in polynomial time. h. If \(X\) is in \(P\), then \(X\) is not NP‑complete."