Consider the following pattern searching/matching scenario: Suppose, your text: DAABAABABADBAABA and the pattern: AABA The searching/matching...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Consider the following pattern searching/matching scenario: Suppose, your text: DAABAABABADBAABA and the pattern: AABA The searching/matching process should be like this: 1st character of the text resides at text[0], 2nd character resides at text[1], 3rd character resides at text[2] and so on. Same goes for the given pattern also, that is, 1st character of the pattern resides at pat[0], 2nd character of the pattern resides at pat[1], 3" character of the pattern resides at pat[2] and so on. The whole text is divided into some fixed length windows and this window length is same as the length of the given pattern. Each time the given pattern is compared with a window and it is determined whether the pattern matches with the current window or not. If yes, then print the position and slide forward to the next window (to the right side in the text by one position) and repeat the same process. If not, then just slide forward to the next window (to the right side in the text by one position) and repeat the same process. DAABAABABADBAABA 1“ window: (DAAB with AABA) 2nd window: (AABA with AABA) 3rd window: (ABAA with AABA) 4th window: (BAAB with AABA) 5th window: (AABA with AABA) 6th window: (ABAB with AABA) AABA Pattern doesn't match in position 0 AABA Pattern found at position 1 AABA Pattern doesn't match in position 2 Pattern doesn't match in position 3 AABA AABA Pattern found at position 4 AABA Pattern doesn't match in position 5 And so on.. Construct a code/program in any of your preferred programming language (C/C++/Java) for the given scenario of pattern matching. Also discuss in short the time complexity of this approach with proper explanation. *** Hints: Take input the text and the pattern from the terminal. Calculate the length of both the text and the pattern. Let them be t and n respectively. So, there will be t-n + 1 number of search iterations/windows. *** Consider the following pattern searching/matching scenario: Suppose, your text: DAABAABABADBAABA and the pattern: AABA The searching/matching process should be like this: 1st character of the text resides at text[0], 2nd character resides at text[1], 3rd character resides at text[2] and so on. Same goes for the given pattern also, that is, 1st character of the pattern resides at pat[0], 2nd character of the pattern resides at pat[1], 3" character of the pattern resides at pat[2] and so on. The whole text is divided into some fixed length windows and this window length is same as the length of the given pattern. Each time the given pattern is compared with a window and it is determined whether the pattern matches with the current window or not. If yes, then print the position and slide forward to the next window (to the right side in the text by one position) and repeat the same process. If not, then just slide forward to the next window (to the right side in the text by one position) and repeat the same process. DAABAABABADBAABA 1“ window: (DAAB with AABA) 2nd window: (AABA with AABA) 3rd window: (ABAA with AABA) 4th window: (BAAB with AABA) 5th window: (AABA with AABA) 6th window: (ABAB with AABA) AABA Pattern doesn't match in position 0 AABA Pattern found at position 1 AABA Pattern doesn't match in position 2 Pattern doesn't match in position 3 AABA AABA Pattern found at position 4 AABA Pattern doesn't match in position 5 And so on.. Construct a code/program in any of your preferred programming language (C/C++/Java) for the given scenario of pattern matching. Also discuss in short the time complexity of this approach with proper explanation. *** Hints: Take input the text and the pattern from the terminal. Calculate the length of both the text and the pattern. Let them be t and n respectively. So, there will be t-n + 1 number of search iterations/windows. ***
Expert Answer:
Answer rating: 100% (QA)
Appending the strings in C Appending is a process of adding or attaching the one string with ... View the full answer
Posted Date:
Students also viewed these programming questions
-
Suppose that Pat and Sandy's restaurant has just installed fancy new decor costing $10,000. Suppose also that in a distant solar system, there is a planet identical to earth in every way except that...
-
Excercise1 : Use Ipconfig and Nslookup to work with DNS. Open a command prompt window. To see a list of recent DNS lookups, type ipconfig /displaydns and press Enter. To perform a DNS lookup, type...
-
Each chapter also includes an exercise like this one. Not only will completing them help you master each chapters vocabulary; you also may find questions like this one on your class exams and...
-
If a zero of f is i, find the complete factored form of f(x) = x 4 + x 3 + 2x 2 + x + 1.
-
Mobile homes are tightly constructed for energy conservation. This can lead to a buildup of indoor pollutants. The paper A Survey of Nitrogen Dioxide Levels Inside Mobile Homes (Journal of the Air...
-
Tanek Industries manufactures and sells three different models of wet-dry shop vacuum cleaners. Although the shop vacs vary in terms of quality and features, all are good sellers. Tanek is currently...
-
During the month of October, credit sales for a business actually amounted to \($754\) 534. However, an error of \($20\) 000 had been made in totalling the sales column of the sales journal. When and...
-
Duff Company is a subsidiary of Rand Corporation and is located in Madrid, Spain, where the currency is the euro (). Data on Duffs inventory and purchases are as follows: Inventory, January 1,...
-
Government spending as a fiscal policy tool is used to: A) ?Decrease the national debt B) ?Directly stimulate economic activity by increasing demand C) ?Reduce inflation D) ?Lower interest rates
-
The proposed rates were not in the range the CEO expected given the pricing analysis. The CEO has asked the pricing actuary to verify the total projected loss cost excluding potential large storm...
-
Consider the following three stocks. a. Stock Alpha is expected to pay a dividend of $1.50 per share forever - no growth or decline. b. Stock Beta will pay a dividend of $3.25 next year. Dividends...
-
Do you think men and women differ in their leadership styles? If so, how?
-
Given that Creative Systems Inc.s stock is currently selling for $50 a share, calculate the amount of money that Alister Cooper will make (or lose) on each of the following transactions. Assume that...
-
How much profit (if any) would William Anderson make if he short-sold 300 shares of stock at $75 a share and the price of the stock suddenly tumbled to $60?
-
Barbara Worrell and Rita Young are neighbors in Denver. Barbara works as a software engineer for Creative Games Corporation, a computer game company, while Rita works as an executive for United...
-
Michael Singleton, 48 and a widower, and Nicole Whitt, 44 and divorced, were married 5 years ago. There are children from their prior marriages, two children for Michael and one child for Nicole. The...
-
F=810N As shown in the figure below, the truss is loaded by the force F in kN at the joint A. Answer the following questions: 1) Determine the internal forces of all truss members except CD 2) From...
-
(a) Prove that form an orthonormal basis for R3 for the usual dot product. (b) Find the coordinates of v = (1, 1, 1)T relative to this basis. (c) Verify formula (5.5) in this particular case. 48-65...
-
Many of the living organisms in Hawaii are found nowhere else on Earth. Hawaii has numerous unique species of plants, birds, insects, mammals, mushrooms, and other living things. Why?
-
Islands tend to have fewer species than the mainlands they resemble. Furthermore, island species often include many flying organisms and few terrestrial ones. Do these biogeographic patterns support...
-
Laura says she doesnt believe that humans were at one time chimpanzees or gorillas. Jeff says he doesnt believe it either. Explain why biologists also dont believe that humans are descended from...
Study smarter with the SolutionInn App