Trace the Rabin-Karp search algorithm on pattern ccc and text dccdcddccddcccd using the fingerprint function in Fig.
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
int fingerprint (char str [], int m, const int q) { } } int i, finger; for (i = 0, finger 0; i <m; ++i) finger = mod( finger* 2 + str[i], q); return finger; int update_fingerprint (int prior_finger, char old_char, char new_char, const int q, int r) { return mod (prior_finger - r* old_char) 2 + new_char, q); } int improved_rabin_karp (char text [], char pattern []) { = const int q = 31321; // A prime number near square root of MAX_INT; int i, j, r, n = strlen(text), m = strlen(pattern); int pfinger int tfinger bool found; = for (i = { = fingerprint (pattern, m, q); fingerprint (text, m, q); for (i = 1, r = 1; i <= m-1; ++i) r mod (2*r, q); 0; i <n-m; ++i) if (pfinger == tfinger ) { // Set r= (2 to the power m-1) mod q; // then we may have a match, so compare // character by character. found= true; for (j = 0; j < m && found; ++j) if (text [i+j] != pattern [j]) // then we have a mismatch, found = false; // so we terminate the inner loop. if (found) // then the loop terminated without discovering a mismatch, return i; // so the substring starting at text [i] matches pattern. } if (i+m <= n-1) // then we'll try for a match with text [i+1..i+m]. tfinger update_fingerprint (tfinger, text [i], text [i+m], q, r); = return -1; // This signals that no match could be found. Fig. 5.81 A more elaborate Rabin-Karp algorithm int fingerprint (char str [], int m, const int q) { } } int i, finger; for (i = 0, finger 0; i <m; ++i) finger = mod( finger* 2 + str[i], q); return finger; int update_fingerprint (int prior_finger, char old_char, char new_char, const int q, int r) { return mod (prior_finger - r* old_char) 2 + new_char, q); } int improved_rabin_karp (char text [], char pattern []) { = const int q = 31321; // A prime number near square root of MAX_INT; int i, j, r, n = strlen(text), m = strlen(pattern); int pfinger int tfinger bool found; = for (i = { = fingerprint (pattern, m, q); fingerprint (text, m, q); for (i = 1, r = 1; i <= m-1; ++i) r mod (2*r, q); 0; i <n-m; ++i) if (pfinger == tfinger ) { // Set r= (2 to the power m-1) mod q; // then we may have a match, so compare // character by character. found= true; for (j = 0; j < m && found; ++j) if (text [i+j] != pattern [j]) // then we have a mismatch, found = false; // so we terminate the inner loop. if (found) // then the loop terminated without discovering a mismatch, return i; // so the substring starting at text [i] matches pattern. } if (i+m <= n-1) // then we'll try for a match with text [i+1..i+m]. tfinger update_fingerprint (tfinger, text [i], text [i+m], q, r); = return -1; // This signals that no match could be found. Fig. 5.81 A more elaborate Rabin-Karp algorithm
Expert Answer:
Answer rating: 100% (QA)
Well calculate the fingerprint values at each position in the text and mark the positions where there is a match with the fingerprint of the pattern W... View the full answer
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these algorithms questions
-
Are the simple graphs with the following adjacency matrices isomorphic? (a) (b) (c) 0 0 0 11 110 0 0 0 0 0 0 1 1110]LI 1 10 0 1 00 0 1 1 0 0 1 0 0 0
-
Valuing the Target Firm Zappa Inc. is considering acquiring the Jones Co. They are trying to estimate the value of the target firm. Recently, the Jones Co. reported cash flows of $15,000,000. The...
-
Suppose that three random variables X1, X2, and X3 have a mixed joint distribution with p.f./p.d.f.: (Notice that X1 has a continuous distribution and X2 and X3 have discrete distributions.)...
-
Develop a data type ResizingArrayQueueOfStrings that implements a queue with a fixed-length array in such a way that all operations take constant time. Then, extend your implementation to use a...
-
The frame shown is supported by three cables and a ball-and-socket joint at A. For P = 50 N, determine the tension in each cable and the reaction at A.
-
151. Humans have acquired immune system that produces antibodies to neutralize pathogens. Still innate immunity is present at the time of birth because it. (1) Is very specific and uses different...
-
The price of a share is \(\$ 25\), and after two months it will be \(\$ 23\) or \(\$ 27\). The risk-free interest rate is \(10 \%\) per year, continuously compounded. If \(S_{T}\) is the price of the...
-
One product produced and sold by Outback Outfitters is an ATV gun rack for which 2010 projections are as follows: Projected volume in units ......... 120,000 Sales price per unit ............. $60...
-
Describe the physical principles that explain electric motors and generators and the conceptual similarities between these devices. Showing your thoughts by drawing pictures.
-
In its annual report, WRM Athletic Supply, Inc. includes the following five-year financial summary: Requirements Analyze the company's financial summary for the fiscal years 2016-2020 to decide...
-
A company plans to borrow $2 million for a year. The stated interest rate is 12 percent. Compute the effective interest rate under each of these assumptions. Each part stands alone. a. The interest...
-
Dollarmite Company has 10,000,000 shares of common stock authorised, but to date, has only 6,000,000 shares outstanding, each with a $2.00 par value. The company has $20,000,000 in additional paid-in...
-
Factor each polynomial Completely. 2 14z-15z+4 2 2 x - 17x+12 2 4w-14 w (4) 4+2 +12++9
-
How Intrinsic valuation is more useful than relative valuation , discuss in detail
-
Discuss with examples, the FIVE (5) criteria in credit analysis.
-
Ted is 56 and has determined that he will need retirement income equal to $50,000/year in today's dollars. He plans to retire in 10 years. He assumes that inflation will average 3% per year.Ignoring...
-
Find x^[l S(3+1).
-
Why is it important to understand the macro-environment when making decisions about an international retail venture?
-
Van makes an investment in a partnership in 2012. Van's capital contributions to the partnership consisted of $30,000 cash and a building with an adjusted basis of$70,000, subject to a nonrecourse...
-
Ulysses and Penelope are married and file separate returns for 2012. Penelope itemizes her deductions on her return. Ulysses' adjusted gross income was $17,400, his itemized deductions were $2,250,...
-
Laura is a single taxpayer living in New Jersey with adjusted gross income for the 2012 tax year of $35,550. Laura's employer withheld $3,300 in state income tax from her salary. In April of 2012,...
-
A nickel crystals work function is measured to be 5.22 eV at 25C. As the temperature increases by 300C, the work function drops by 50 meV. By how much does this shift the threshold wavelength for...
-
A crystal sample of bacteriorhodpsin, a light-sensitive protein found in halobacteria that responds to light energy, has crystal planes separated by 0.20 nm. If a beam of 11 keV x rays illuminates a...
-
Investigators have created structures consisting of linear chains of ionized atoms on a smooth surface. Electrons are restricted to travel along the chain. The energy levels of the electrons match...
Study smarter with the SolutionInn App