Vous êtes sur la page 1sur 2

EXPRIMENT NO 8:

1.Explain String Matching algorithm


Finding all occurrences of a pattern in a text is a problem that arises frequently in text-editing programs.
Typically, the text is a document being edited, and the pattern searched for is a particular word supplied
by the user. Efficient algorithms for this problem can greatly aid the responsiveness of the text-editing
program.

2.What is Naïve string matching


The Naive String Matching Algorithm is one of the simplest methods to check whether a string follows a
particular pattern or not.It is simple of all the algorithm but is highly inefficient.checks where the string
matches the input pattern one by one with every character of the string.

3.List the different string matching algorithm


1. Naïve String Matching Algorithm
2. Rabin Karp String Search Algorithm
3. Two Way String Matching Algorithm
4. Backward Non-Deterministic Dawg Matching Algorithm
5. Finite State Automation Algorithm
6. Knuth Morris Prat Algorithm

4. What is time complexity of Naïve String matching algo.


The time complexity of Naïve Pattern Search method is O(m*n). The m is the size of pattern and
n is the size of the main string.

5. What is the condition for valid shift?

6. When the invalid shift does occur in string matching?


We say that pattern P occurs with shift s in text T (or, equivalently, that pattern P occurs beginning at
position s + 1 in text T) if 0 s n - m and T[s + 1 . . s + m] = P[1 . . m] (that is, if T[s + j] = P[j], for 1 j m). If
P occurs with shift s in T, then we call s a valid shift; otherwise, we call s an invalid shift.

7. How many shifts does above algorithm takes to match if pattern P=0001 in the text
T=0000100011010001?
4 Shifts

8. How many string matchings will be possible in above question?


3 possible matching strings
T=0000100011010001
9.How much preprocessing and matching time will be taken in question 7?
It doesn’t takes preprocessing time and its 5 matching strings for comparison.

10. Does naïve string-matching employs dynamic programming approach?

The simplest of all exact string approaches is the naive approach, which scans the text T[l..n] from left to
right, comparing each character in the pattern P[l..m] to the text each iteration.

EXPRIMENT NO 9:

1. What are the components of finite automata?

The components of FA model are Input tape, Read control and finite control.

• a finite set S of N states


• a special start state
• a set of final (or accepting) states
• a set of transitions T from one state to another, labeled with chars in C

2. Does it possible to have multiple transitions from one node to same node in finite automata? Why?

we can represent a FA graphically, with nodes for states, and arcs for transitions.

We execute our FA on an input sequence as follows:

• Begin in the start state

• If the next input char matches the label on a transition from the current state to a new state, go
to that new state

• Continue making transitions on each input char

o If no move is possible, then stop

o If in accepting state, then accept

3. If two transitions are missing in FA then it becomes DFA.

4.Find the time complexity of above problem?

The time complexity of the search process is O(n).


5.State preprocessing time and matching time for this algorithm.

we preprocess the pattern and build a 2D array that represents a Finite Automata. Number of
states in FA will be M+1 where M is length of the pattern will be matching time.

Vous aimerez peut-être aussi