id int64 0 25.6k | text stringlengths 0 4.59k |
|---|---|
21,300 | (mand between (mand (nnote the conquer step performed in step ( (continued from figure |
21,301 | merge-sort on sequence of size has height log we leave the justification of proposition as simple exercise ( - we will use this proposition to analyze the running time of the merge-sort algorithm having given an overview of merge-sort and an illustration of how it workslet us consider each of the steps of this divide-a... |
21,302 | we illustrate step in the merge of two sorted arrays in figure code fragment algorithm for merging two sorted array-based sequences figure step in the merge of two sorted arrays we show the arrays before the copy step in (aand after it in (bmerging two sorted lists in code fragment we give list-based version of algorit... |
21,303 | lists and add it to the end of the output sequencesuntil one of the two input lists is emptyat which point we copy the remainder of the other list to we show an example execution of this version of algorithm merge in figure code fragment algorithm merge for merging two sorted sequences implemented as linked lists the r... |
21,304 | the running time of merge-sort now that we have given the details of the merge-sort algorithmin both its arraybased and list-based versionsand we have analyzed the running time ofthe crucial merge algorithm used in the conquer steplet us analyze the running time of the entire merge-sort algorithmassuming it is given an... |
21,305 | merging two sorted sequences can be done in linear time as we mentioned earlierwe analyze the merge-sort algorithm by referring to the merge-sort tree (recall figures through we call the time spent at node of the running time of the recursive call associated with vexcluding the time taken waiting for the recursive call... |
21,306 | java implementations of merge-sort in this sectionwe present two java implementations of the merge-sort algorithmone for lists and the other for arrays recursive list-based implementation of merge-sort in code fragment we show complete java implementation of the listbased merge-sort algorithm as static recursive method... |
21,307 | merge implementing the recursive merge-sort algorithm |
21,308 | there is nonrecursive version of array-based merge-sortwhich runs in ( log ntime it is bit faster than recursive list-based merge-sort in practiceas it avoids the extra overheads of recursive calls and node creation the main idea is to perform merge-sort bottom-upperforming the merges level-by-level going up the merge-... |
21,309 | merge-sort and recurrence equations there is another way to justify that the running time of the merge-sort algorithm is ( log (proposition namelywe can deal more directly with the recursive nature of the merge-sort algorithm in this sectionwe present such an analysis of the running time of merge-sortand in so doing in... |
21,310 | asymptotic characterization still holds in the general case as an exercise in this casewe can specify the definition of (nas an expression such as the one above is called recurrence equationsince the function appears on both the leftand right-hand sides of the equal sign although such characterization is correct and ac... |
21,311 | main idea is to apply the divide-and-conquer techniquewhereby we divide into subsequencesrecur to sort each subsequenceand then combine the sorted subsequences by simple concatenation in particularthe quick-sort algorithm consists of the following three steps (see figure ) divideif has at least two elements (nothing ne... |
21,312 | shown in figures and unlike merge-sorthoweverthe height of the quick-sort tree associated with an execution of quick-sort is linear in the worst case this happensfor exampleif the sequence consists of distinct elements and is already sorted indeedin this casethe standard choice of the pivot as the largest element yield... |
21,313 | the tree represents recursive call the nodes drawn with dashed lines represent calls that have not been made yet the node drawn with thick lines represents the running invocation the empty nodes drawn with thin lines represent terminated calls the remaining nodes represent suspended calls (that isactive invocations tha... |
21,314 | ( (continues in figure figure visualization of an execution of quicksort note the conquer step performed in ( (continues in figure |
21,315 | omitted note the conquer steps performed in (oand ( (continued from figure |
21,316 | in code fragment we give pseudo-code description of the quick-sort algorithm that is efficient for sequences implemented as arrays or linked lists the algorithm follows the template for quick-sort given aboveadding the detail of scanning the input sequence backwards to divide it into the lists leand of elements that ar... |
21,317 | independent of whether the sequence is implemented as an array or linked list code fragment quick-sort for an input sequence implemented with linked list or an array running time of quick-sort we can analyze the running time of quick-sort with the same technique used for merge-sort in section namelywe can identify the ... |
21,318 | is atmosts( given quick-sort tree tlet denote the sum of the input sizes of the nodes at depth in clearlys nsince the root of is associated with the entire sequence alsos < since the pivot is not propagated to the children of consider next if both children of have nonzero input sizethen otherwise (one child of the root... |
21,319 | thusin the best caset has height (lognand quick-sort runs in (nlogntimewe leave the justification of this fact as an exercise ( - the informal intuition behind the expected behavior of quick-sort is that at each invocation the pivot will probably divide the input sequence about equally thuswe expect the average running... |
21,320 | such that subsequences and have size at least / and at most / eachotherwisea call is "bad nowconsider the implications of our choosing pivot uniformly at random note that there are / possible good choices for the pivot for any given call of size of the randomized quick-sort algorithm thusthe probability that any call i... |
21,321 | with high probability (see exercise - in-place quick-sort recall from section that sorting algorithm is in-place if it uses only small amount of memory in addition to that needed for the objects being sorted themselves the merge-sort algorithmas we have described it aboveis not inplaceand making it be in-place requires... |
21,322 | not explicitly create subsequences indeeda subsequence of the input sequence is implicitly represented by range of positions specified by left-most index and right-most index the divide step is performed by scanning the array simultaneously from forward and from backwardswapping pairs of elements that are in reverse or... |
21,323 | swap with the pivot completes the divide step code fragment coding of in-place quicksortassuming distinct elements |
21,324 | section we note that we need space for stack proportional to the depth of the recursion treewhich in this case can be as large as admittedlythe expected stack depth is (logn)which is small compared to neverthelessa simple trick lets us guarantee the stack size is (lognthe main idea is to design nonrecursive version of ... |
21,325 | lower bound on sorting recapping our discussions on sorting to this pointwe have described several methods with either worst-case or expected running time of (nlognon an input sequence of size these methods include merge-sort and quick-sortdescribed in this as well as heap-sortdescribed in section natural question to a... |
21,326 | trick the algorithm into outputting and in the wrong order since this cannot be allowed by correct sorting algorithmeach external node of must be associated with exactly one permutation of we use this property of the decision tree associated with sorting algorithm to prove the following resultproposition the running ti... |
21,327 | bucket-sort and radix-sort in the previous sectionwe showed that ohm(nlogntime is necessaryin the worst caseto sort an -element sequence with comparison-based sorting algorithm natural question to askthenis whether there are other kinds of sorting algorithms that can be designed to run asymptotically faster than (nlogn... |
21,328 | sequence into its bucketwe can put the entries back into in sorted order by enumerating the contents of the buckets [ ] [ ], [ in order we describe the bucket-sort algorithm in code fragment code fragment bucket-sort it is easy to see that bucket-sort runs in ( ntime and uses ( nspace hencebucket-sort is efficient when... |
21,329 | radix-sort one of the reasons that stable sorting is so important is that it allows the bucket-sort approach to be applied to more general contexts than to sort integers supposefor examplethat we want to sort entries with keys that are pairs ( , )where and are integers in the range [ , ]for some integer > in context su... |
21,330 | first component)then their relative order in the starting sequence (which is sorted by the second componentis preserved thusthe resulting sequence is guaranteed to be sorted lexicographically every time we leave to simple exercise ( - the determination of how this approach can be extended to triples and other -tuples o... |
21,331 | elements)because insertion-sort is simple to programand small sequences necessarily have few inversions alsoinsertion-sort is quite effective for sorting sequences that are already "almostsorted by "almost,we mean that the number of inversions is small but the ( )-time performance of insertion-sort makes it poor choice... |
21,332 | finallyif our application involves sorting entries with small integer keys or dtuples of small integer keysthen bucket-sort or radix-sort is an excellent choicefor it runs in ( ( )timewhere [ , is the range of integer keys (and for bucket sortthusif ( nis significantly "belowthe nlogn functionthen this sorting method s... |
21,333 | subtract( )replace with the difference of and bthat isexecute - simple set implementation one of the simplest ways of implementing set is to store its elements in an ordered sequence this implementation is included in several software libraries for generic data structuresfor example thereforelet us consider implementin... |
21,334 | have the followingproposition the set adt can be implemented with an ordered sequence and generic merge scheme that supports operationsunionintersectandsubtract in (ntimewhere denotes the sum of sizes of the sets involved generic merging as template method pattern the generic merge algorithm is based on the template me... |
21,335 | classes that redefine the three auxiliary methodsaislessbothareequaland bisless we show how unionintersectionand subtraction can be easily described in terms of these methods in code fragment the auxiliary methods are redefined so that the template method merge performs as follows |
21,336 | in class union mergemerge copies every element from and into cbut does not duplicate any element in class intersectmergemerge copies every element that is in both and into cbut "throws awayelements in one set but not in the other in class subtractmergemerge copies every element that is in and not in into code fragment ... |
21,337 | partitions with union-find operations partition is collection of disjoint sets we define the methods of the partition adt using position objects (section )each of which stores an element the parition adt supports the following methods makeset( )create singleton set containing the element and return the position storing... |
21,338 | the sequence implementation above is simplebut it is also efficientas the following theorem shows proposition performing series of nmakesetunionandfind operationsusing the sequence-based implementation abovestarting from an initially empty partition takes (nlogntime justificationwe use the accounting method and assume ... |
21,339 | partition implementation as follows proposition using sequence-based implementation of partitionin series of nmakesetunionandfind operations starting from an initially empty partitionthe amortized running time of each operation is (lognnote that in this sequence-based implementation of partitioneach find operation take... |
21,340 | arguments and that respectively represent the sets and (that isa and qwe perform this operation by making one of the trees subtree of the other (figure )which can be done in ( time by setting the set reference of the root of one tree to point to the root of the other tree operation find for position is performed by wal... |
21,341 | structurebut we add the following simple heuristics to make it run fasterunion-by-sizestorewith each position node pthe size of the subtree rooted at in union operationmake the tree of the smaller set become subtree of the other treeand update the size field of the root of the resulting tree path compressionin find ope... |
21,342 | surprising property of the tree-based partition data structurewhen implemented using the union-by-size and path-compression heuristicsis that performing series of nunion and find operations takes (nlog*ntimewhere log* is the log-star functionwhich is the inverse of the tower-of-twos function intuitivelylog* is the numb... |
21,343 | for >= ai( )ai (ai( )for > and > in other wordsthe ackermann functions define progression of functionsa ( is the multiply-by-two function ( is the power-of-two function ( =math (with 'sis the tower-of-twos function and so on we then define the ackermann function as (nan( )which is an incredibly fast growing function li... |
21,344 | in (ntime for any value of moreoverthe technique we use to achieve this result involves an interesting algorithmic design pattern this design pattern is known as prune-and-search or decrease-and-conquer in applying this design patternwe solve given problem that is defined on collection of objects by pruning away fracti... |
21,345 | selection algorithm that runs in (nworst-case time the existence of this deterministic algorithm is mostly of theoretical interesthoweversince the constant factor hidden by the big-oh notation is relatively large in this case suppose we are given an unsorted sequence of comparable elements together with an integer [ ,n... |
21,346 | up "heads that ise( ( ) thusif we let (nbe shorthand for ( ( ))then we can write the case for as ( )<= ( / bn to convert this relation into closed formlet us iteratively apply this inequality assuming is large sofor exampleafter two applicationst( <= (( / ) ( / ) bn at this pointwe should see that the general case is i... |
21,347 | drawn as arrows what is the meaning of downward arrowhow about an upward arrowr- give complete pseudo-code description of the recursive merge-sort algorithm that takes an array as its input and output - show that the running time of the merge-sort algorithm on an -element sequence is (nlogn)even when is not power of - ... |
21,348 | logn subproblems in size group ifor randomized quick-sortis at most / - suppose algorithm inplacequicksort (code fragment is executed on sequence with duplicate elements show that the algorithm still correctly sorts the input sequencebut the result of the divide step may differ from the highlevel description given in s... |
21,349 | give an example input list that requires merge-sort and heap-sort to take (nlogntime to sortbut insertion-sort runs in (ntime what if you reverse this listr- describein pseudo-codehow to perform path compression on path of length in (htime in tree-based partition union/find structure - george claims he has fast way to ... |
21,350 | her algorithm' correctness could be established on any given and in (ntime - given two sets and represented as sorted sequencesdescribe an efficient algorithm for computing bwhich is the set of elements that are in or bbut not in both - suppose that we represent sets with balanced search trees describe and analyze algo... |
21,351 | the result sublists after the recursive calls return showby inductionthat (nis (nlognc- modify inplacequicksort (code fragment to handle the general case efficiently when the input sequencesmay have duplicate keys - describe nonrecursivein-place version of the quick-sort algorithm the algorithm should still be based on... |
21,352 | (nlogntime with probability at least / - given an array of entries with keys equal to or describe an in-place method for ordering so that all the ' are before every - suppose we are given an -element sequence such that each element in represents different vote for presidentwhere each vote is given as an integer represe... |
21,353 | total size of all the sequences - given sequence of elementson which total order relation is defineddescribe an efficient method for determining whether there are two equal elements in what is the running time of your methodc- let be sequence of elements on which total order relation is defined recall that an inversion... |
21,354 | of his nuts and bolts - show how to use deterministic ( )-time selection algorithm to sort sequence of elements in ( log nworst-case time - given an unsorted sequence of comparable elementsand an integer kgive an (nlogkexpected-time algorithm for finding the (kelements that have rank / / / and so on - let be sequence o... |
21,355 | groupsort each little set and identify the median element in this set from this set of / "babymediansapply the selection algorithm recursively to find the median of the baby medians use this element as the pivot and proceed as in the quick-select algorithm show that this deterministic method runs in (ntime by answering... |
21,356 | sequence of elements with integer keys taken from the range [ , ]for > the algorithm should run in ( ntime - implement merge-sort and deterministic quick-sort and perform series of benchmarking tests to see which one is faster your tests should include sequences that are "randomas well as "almostsorted - implement dete... |
21,357 | the sorting problem and algorithms for solving it huang and langston [ describe how to merge two sorted lists in-place in linear time our set adt is derived from the set adt of ahohopcroftand ullman [ the standard quick-sort algorithm is due to hoare [ more information about randomizationincluding chernoff boundscan be... |
21,358 | string operations the java string class the java stringbuffer class patternmatching algorithms brute force the boyer-moore algorithm |
21,359 | tries standard tries compressed tries suffix tries search engines text compression the huffman coding algorithm the greedy method |
21,360 | text similarity testing the longest common subsequence problem dynamic programming applying dynamic programming to the lcs problem exercises java datastructures net string operations document processing is rapidly becoming one of the dominant functions of computers computers are used to edit documentsto search document... |
21,361 | (such as in text compressionactually gives rise to optimal algorithms finallyin discussing text similaritywe introduce the dynamic programming design patternwhich can be applied in some special instances to solve problem in polynomial time that appears at first to require exponential time to solve text processing at th... |
21,362 | constant string operations come in two flavorsthose that modify the string they act on and those that simply return information about the string without actually modifying it java makes this distinction precise by defining the string class to represent immutable stringswhich cannot be modifiedand the stringbuffer class... |
21,363 | on the string "abcdefghijklmnop"operation output length( charat( 'fconcat("qrs""abcdefghijklmnopqrsendswith("javapop"false indexof("ghi" startswith("abcd"true substring( , "efghijwith the exception of the indexof(qmethodwhich we discuss in section all the methods above are easily implemented simply by representing the ... |
21,364 | starting at index reverse()reverse and return the string setcharat( ,ch)set the character at index in to be ch charat( )return the character at index in error conditions occur when the index is out of the bounds of the indices of the string with the exception of the charat methodmost of the methods of the string class ... |
21,365 | length and apattern string of length mand want to find whether is substring of the notion of "matchis that there is substring of starting at some index that matches pcharacter by characterso that [ip[ ] [ [ ] [ [ that isp [ thusthe output from pattern matching algorithm could either be some indication that the pattern ... |
21,366 | the brute-force pattern matching algorithm could not be simpler it consists of two nested loopswith the outer loop indexing through all possible starting indices of the pattern in the textand the inner loop indexing through each character of the patterncomparing it to its potentially corresponding character in the text... |
21,367 | the boyer-moore algorithm at firstwe might feel that it is always necessary to examine every character in in order to locate pattern as substring but this is not always the casefor the boyer-moore (bmpattern matching algorithmwhich we study in this sectioncan sometimes avoid comparisons between and sizable fraction of ... |
21,368 | integrated team the looking-glass heuristic sets up the other heuristic to allow us to avoid comparisons between and whole groups of characters in in this case at leastwe can get to the destination faster by going backwardsfor if we encounter mismatch during the consideration of at certain location in tthen we are like... |
21,369 | figure illustration of the jump step in the algorithm of code fragment where we let last( [ ]we distinguish two cases( + <jwhere we shift the pattern by units(bj lwhere we shift the pattern by one unit |
21,370 | algorithm on an input string similar to example figure an illustration of the bm pattern matching algorithm the algorithm performs character comparisonswhich are indicated with numerical labels |
21,371 | each time the method makes shiftit is guaranteed not to "skipover any possible matches for last(cis the location of the last occurrence of in the worst-case running time of the bm algorithm is (nm+| |namelythe computation of the last function takes time ( +| |and the actual search for the pattern takes (nmtime in the w... |
21,372 | fragment code fragment java implementation of the bm pattern matching algorithm the algorithm is expressed by two static methodsmethod bmmatch performs the matching and calls the auxiliary method build lastfunction to compute the last functionexpressed by an array indexed by the ascii code of the character method bmmat... |
21,373 | algorithm the original bm algorithm achieves running time ( | |by |
21,374 | shifts the pattern more than the character-jump heuristic this alternative shift heuristic is based on applying the main idea from the knuth-morris-pratt pattern matching algorithmwhich we discuss next the knuth-morris-pratt algorithm in studying the worst-case performance of the brute-force and bm pattern matching alg... |
21,375 | for at its beginningwe repeat this process until we find match of in or the index for reaches nthe length of (indicating that we did not find the pattern pintcode fragment the kmp pattern matching algorithm the main part of the kmp algorithm is the while loopwhich performs comparison between character in and character ... |
21,376 | on the same input strings as in example note the use of the failure function to avoid redoing one of the comparisons between character of the pattern and character of the text also note that the algorithm performs fewer overall comparisons than the brute-force algorithm run on the same strings (figure performance exclu... |
21,377 | to construct the failure functionwe use the method shown in code fragment which is "bootstrappingprocess quite similar to the kmpmatch algorithm we compare the pattern to itself as in the kmp algorithm each time we have two characters that matchwe set (ij note that since we have throughout the execution of the algorith... |
21,378 | fragment code fragment java implementation of the kmp pattern matching algorithm the algorithm is expressed by two static methodsmethod kmpmatch performs the matching and calls the auxiliary method computefailfunction to compute the failure functionexpressed by an array method kmpmatch indicates the absence of match by... |
21,379 | tries the pattern matching algorithms presented in the previous section speed up the search in text by preprocessing the pattern (to compute the failure function in the kmp algorithm or the last function in the bm algorithmin this sectionwe take complementary approachnamelywe present string searching algorithms that pr... |
21,380 | bidbullbuysellstockstopan -character prefix [ of string of in factfor each character that can follow the prefix [ in string of the set sthere is child of labeled with character in this waya trie concisely stores the common prefixes that exist among set of strings if there are only two characters in the alphabetthen the... |
21,381 | common nonempty prefixthat isexcept for the rootall internal nodes have one child trie for set of strings can be used to implement dictionary whose keys are the strings of namelywe perform search in for string by tracing down from the root the path indicated by the characters in if this path can be traced and terminate... |
21,382 | which are also known as stop wordsexcluded)with external nodes augmented with indications of the word positions there is potential space inefficiency in the standard trie that has prompted the development of the compressed triewhich is also known (for historical reasonsas the patricia trie namelythere are potentially l... |
21,383 | in the trie has at least two children it enforces this rule by compressing chains of single-child nodes into individual edges (see figure let be standard trie we say that an internal node of is redundant if has one child and is not the root for examplethe trie of figure has eight redundant nodes let us also say that ch... |
21,384 | has external nodes the number of nodes of is (sthe attentive reader may wonder whether the compression of paths provides any significant advantagesince it is offset by corresponding expansion of the node labels indeeda compressed trie is truly advantageous only when it is used as an auxiliary index structure over colle... |
21,385 | can also be stored compactly suffix tries one of the primary applications for tries is for the case when the strings in the collection are all the suffixes of string such trie is called the suffix trie (also known as suffix tree or position treeof string for examplefigure shows the suffix trie for the eight suffixes of... |
21,386 | (asuffix trie for the string "minimize'(bcompact representation of twhere pair ( ,jdenotes [ jusing suffix trie the suffix trie for string can be used to efficiently perform pattern matching queries on text namelywe can determine whether pattern is substring of by trying to trace path associated with in is substring of... |
21,387 | given in code fragment which assumes the following additional property on the labels of the nodes in the compact representation of the suffix trieif node has label ( ,jand is the string of length associated with the path from the root to (included)then [ = this property ensures that we can easily compute the start inde... |
21,388 | search down the trie tmatching characters of the pattern one at time until one of the following events occurswe completely match the pattern we get mismatch (caught by the termination of the for loop without break outwe are left with characters of still to be matched after processing an external node |
21,389 | determine the running time of algorithm suffixtriematchwe make the following observationswe process at most nodes of the trie each node processed has at most children at each node processedwe perform at most one character comparison for each child of to determine which child of needs to be processed next (which may pos... |
21,390 | the core information stored by search engine is dictionarycalled an inverted index or inverted filestoring key-value pairs ( , )where is word and is collection of pages containing word the keys (wordsin this dictionary are called index terms and should be set of vocabulary entries and proper nouns as large as possible ... |
21,391 | large documents more efficientlyso as to allow for fixed-capacity storage device to contain as many documents as possible the method for text compression explored in this section is the huffman code standard encoding schemessuch as the ascii and unicode systemsuse fixedlength binary strings to encode characters (with b... |
21,392 | is the huffman coding algorithm the huffman coding algorithm begins with each of the distinct characters of the string to encode being the root node of single-node binary tree the algorithm proceeds in series of rounds in each roundthe algorithm takes the two binary trees with the smallest frequencies and merges them i... |
21,393 | the greedy method huffman' algorithm for building an optimal encoding is an example application of an algorithmic design pattern called the greedy method this design pattern is applied to optimization problemswhere we are trying to construct some structure while minimizing or maximizing some property of that structure ... |
21,394 | text similarity testing common text processing problemwhich arises in genetics and software engineeringis to test the similarity between two text strings in genetics applicationthe two strings could correspond to two strands of dnawhich couldfor examplecome from two individualswho we will consider genetically related i... |
21,395 | exponential time and produce polynomial-time algorithms to solve them dynamic programming is one such technique in additionthe algorithms that result from applications of the dynamic programming technique are usually quite simple-often needing little more than few lines of code to describe some nested loops for filling... |
21,396 | both [ ix and [ jy this definition allows us to rewrite [ ,jin terms of optimal subproblem solutions this definition depends on which of two cases we are in (see figure in this casewe have match between the last character of [ iand the last character of [ jwe claim that this character belongs to longest common subseque... |
21,397 | straightforward we initialize an ( ( arraylfor the boundary cases when or namelywe initialize [ for - , , and [ for - , , (this is slight abuse of notationsince in realitywe would have to index the rows and columns of starting with thenwe iteratively build up values in until we have [ ]the length of longest common subs... |
21,398 | characterswe can find the longest common subsequence of and in (nmtime justificationalgorithm lcs computes [ , ]the length of longest common subsequencein (nmtime given the table of [ijvaluesconstructing longest common subsequence is straightforward one method is to start from [nmand work back through the tablereconstr... |
21,399 | - list the prefixes of the stringp "aaabbaaathat are also suffixes of - draw figure illustrating the comparisons done by brute-force pattern matching for the text "aaabaadaabaaaand pattern "aabaaar- repeat the previous problem for the bm pattern matching algorithmnot counting the comparisons made to compute the last(cf... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.