Introduction To Algorithms, Third Edition (international Edition)
Introduction To Algorithms, Third Edition (international Edition)
3rd Edition
ISBN: 9780262533058
Author: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, Clifford Stein
Publisher: TRILITERAL
bartleby

Concept explainers

Question
Book Icon
Chapter 32, Problem 1P

a.

Program Plan Intro

To give and efficient algorithm that takes pattern P [1 . . m ] as input and computes the values of ρ(Pi) for i=1,2,m

a.

Expert Solution
Check Mark

Explanation of Solution

String matching based on repetition factors:

String matching is the method of finding some particular pattern in the whole string. There are two things one is pattern and one is whole string. The string matching refers to just check whether the given pattern is present in the string or not also to find out the position of the first letter of the patter till the length of the pattern. It may be in form of sequence or tree structures.

Suppose the input is a pattern P[1..m] and the following algorithm calculates the value ρ(Pi)

The first approach is the Naïve Approach.

The algorithm is given below:

  1i= Text size 0

  // inputs text size

  2m= Pattern size 0

  // inputs the text pattern

3 for a=0 to nm \{4

  5 if ( pattern [1.m]=text[a+1a+m])

add-result (a)

6\}

The running of the algorithm would be Θ(m2) .This is because one power of m for loop that is “for” loop (worst case) and another for checking process of “if” statement because it is run up-to m in worst case scenario.

b.

Program Plan Intro

To prove that the expected value of ρ*(P) is O(1) if the pattern P is chosen randomly form the set of all binary strings of length m .

b.

Expert Solution
Check Mark

Explanation of Solution

Taking the pattern P[1..m] and is defined as ρ*(P) is defined as max1imρ(Pi)

Taking the pattern involving one string: xor y

When matching the above pattern, it iterates in one cycle maximum.

Taking the pattern involving two strings:

    Introduction To Algorithms, Third Edition (international Edition), Chapter 32, Problem 1P , additional homework tip  1Introduction To Algorithms, Third Edition (international Edition), Chapter 32, Problem 1P , additional homework tip  2orIntroduction To Algorithms, Third Edition (international Edition), Chapter 32, Problem 1P , additional homework tip  3Introduction To Algorithms, Third Edition (international Edition), Chapter 32, Problem 1P , additional homework tip  4orIntroduction To Algorithms, Third Edition (international Edition), Chapter 32, Problem 1P , additional homework tip  5Introduction To Algorithms, Third Edition (international Edition), Chapter 32, Problem 1P , additional homework tip  6

When trying to match the given string with the above pattern. It will match the string as single one or the text as a two together completing it in maximum one or two iteration.

Taking the pattern of three strings:

    Introduction To Algorithms, Third Edition (international Edition), Chapter 32, Problem 1P , additional homework tip  7Introduction To Algorithms, Third Edition (international Edition), Chapter 32, Problem 1P , additional homework tip  8Introduction To Algorithms, Third Edition (international Edition), Chapter 32, Problem 1P , additional homework tip  9

Again, while trying to match the above string either it matches a single string or a few strings together or all might be same.

Similarly, it can be done so for mstrings . Each time involving O(1) time maximum

c.

Program Plan Intro

To argue that the string matching algorithm correctly find all occurrences of the patternP in a text T[1....n] taking the time O(ρ*(P)n+m) .

c.

Expert Solution
Check Mark

Explanation of Solution

The given Galil-Seiferas algorithm consists of preprocessing phase and searching phase.The preprocessing phase of Galil-Seiferas algorithm involves finding decompositionab of x followingb that has at least one prefix period and |a|=O(per(b)) the searching phase works in scanning the text for each occurrence of bandb checks immediately if aoccurs just beforeb .

  Introduction To Algorithms, Third Edition (international Edition), Chapter 32, Problem 1P , additional homework tip  10

While searching for x[s...m1] in y :

  1. If x[s....s+p1+q11] matches with a shift of length p1 , the comparisons are continued with x[s+q1] .
  2. Each time the mismatch occurs with x[s+q] and q=p1+q1 then a shift of length q/d+1 can be done and comparisons are carried with x[0] .

The preprocessing will incur O(m) times and the searching phase O(n) times and it is noticed in line 3 of algorithm that algorithm runs for ρ*(P) . The total process therefore will take O(ρ*(P)n+m) time.

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
I need help creating the network diagram and then revising it for the modified activity times.
Activity No. Activity Time (weeks) Immediate Predecessors 1 Requirements collection 3 2 Requirements structuring 4 1 3 Process analysis 3 2 4 Data analysis 3 2 5 Logical design 50 3,4 6 Physical design 5 5 7 Implementation 6 6 c. Using the information from part b, prepare a network diagram. Identify the critical path.
Given the following Extended-BNF grammar of the basic mathematical expressions:  Show the derivation steps for the expression: ( 2 + 3 ) * 6 – 20 / ( 3 + 1 ) Draw the parsing tree of this expression. SEE IMAGE
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
Operations Research : Applications and Algorithms
Computer Science
ISBN:9780534380588
Author:Wayne L. Winston
Publisher:Brooks Cole
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning
Text book image
LINUX+ AND LPIC-1 GDE.TO LINUX CERTIF.
Computer Science
ISBN:9781337569798
Author:ECKERT
Publisher:CENGAGE L