Introduction to Algorithms
3rd Edition
ISBN: 9780262033848
Author: Thomas H. Cormen, Ronald L. Rivest, Charles E. Leiserson, Clifford Stein
Publisher: MIT Press
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 32.3, Problem 1E
Program Plan Intro
To construct string matching automation for pattern
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
(a) Build the string-matching automaton for the pattern P = abbab over the alphabetΣ = {a, b}
(b) Illustrate its operation on the text string T = aabbabaabbaababbab
iven an input string (s) and a pattern (p), implement wildcard pattern matching with support for '?' and '*' where:
'?' Matches any single character.
'*' Matches any sequence of characters (including the empty sequence).
The matching should cover the entire input string (not partial).
Write a regular expression, usable with Python's re.search, which captures in its capture groups the parts of a rudamentary URL as defined below:
Examples of URLs:
http://bing.com
https://google.com
https://yahoo.com
https://www.ycombinator.com/
The pattern should capture:
The scheme (the "https://" part) The domain (the part after the scheme and before the top level domain (TLD), e.g. "bing" or "www.ycombinator") The top level domain (aka. TLD) (the last part, eg. "edu", "com", "gov")
You do not need to handle URLs with paths (such as http://google.com/foo/bar), unless the path is just / as above, nor do you need to handle URLs with query strings (such as https://example.com?foo=bar).
For the last example:
>>> re.search(pattern, 'https://www.ycombinator.com/').groups()
('https://', 'www.ycombinator', 'com')
Assign your pattern to a variable named pattern.
Knowledge Booster
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
- A uwuified sentence is sentence that has been transformed using a made-up Internet language in which some of the letters in the words are replaced by something else. The exact scheme is described below: Any uppercase/lowercase R or L is replaced by w/w, respectively. • If we encounter an o/o in a word, check if the previous letter (if it exists) is an M/m or N/n. If the previous letter is one of these, insert the lowercase letter y in between them, regardless of the capitalization of the other letters. • All other characters are left unchanged. Some examples: Professor will be converted to Pwofessow (There are two r's that are replaced by w's. Since the two o's aren't proceeded by an M/n or N/n, no y will be inserted.) LLunoacyo will be converted to wwunyoacyo (The two L's will be replaced with two ws according to the first rule. Then the first o will have a y inserted in front of it between then and the o according to the second rule. The last o won't have a y inserted in between…arrow_forwardWrite a regular expression for the set of strings over the alphabet {a, b} that have at least one a andat least one b. For example, aaaba and bbaba are strings in the set, but aaaa and bbb are not.arrow_forwardUsing Matplotlib (based on python), write a code that takes the input of two different functions. The first function should be displayed first on a graph. Program such that the graph gradually transforms into the second function.arrow_forward
- Suppose a string Z is formed by interspersing the characters from other two strings X and Y. The new string Z is called a shuffle of X and Y if characters in Z com- ing from the same string still keep the order as in the original string. For example, the strings PRODGYRNAMAMMIINCG and DYPRONGARMAMMICING are both shuffles of DYNAMIC and PROGRAMMING: PRODGYRNAMAMMIINCG DYPRONGARMAMMICING Given three strings A[1..m], B[1..n], and C[1..m+n], design a dynamic programming algorithm to determine if C is a shuffle of A and B.arrow_forwardA string may use more than one type of delimiter to bracket information into “blocks.” For example, A string may use braces { }, parentheses ( ), and brackets [ ] as delimiters. A string is properly delimited if each right delimiter is matched with a preceding left delimiter of the same type in such a way that the either the resulting blocks of information are disjoint, or one of them is completely nested within the other. Write a program that uses a single stack to check whether a string containing braces, parentheses, and brackets is properly delimited.arrow_forwardAn edge labeled with multiple symbols a, b,... → edge labeled with the symbol. Select one: True False Given regular expressions R1 and R2, then... Select one: E a. R1+R2 is a regular expression b. R1R2 is a regular expression CR1 is a regular expression d. All of the abovearrow_forward
- Write a CFG to generate the language of all strings that have more a's than b's (not necessarily only one more, as with the nonterminal A for the language EQUAL, but any number more a's than b's). {a aa aab aba baa aaaa aaab ... }arrow_forwardConstruct a CFG and PDA for the language B={w| w is a string over {a,b} with the same count of a's and b's}. For example, abba € B, abab e B,aabb € B, babbbaaaba € B, that is, there is no particular order in which a's and b's appear in w as long as there is the same amount of them.arrow_forward: Imagine a histogram (bar graph). Design an algorithm to compute thevolume of water it could hold if someone poured water across the top. You can assume that eachhistogram bar has width 1.EXAMPLE (Black bars are the histogram. Gray is water.)lnput:{0, 0, 4, 0, 0, 6, 0, 0, 3, 0, 5, 0, 1, 0, 0, 0}arrow_forward
- Question 2: Ʃ = {a, b} Give the regular expression for all strings in which any b’s that occur are in groups of an odd number at a time. Some sample strings in the language aabaabbbab, bbbbbabbbaab, aaaa, ababab Some sample strings NOT in the language abba, babbbbarrow_forwardConstruct an NFA with e-transitions and Σ={a,b} which accepts those strings that satisfy one or more of the following conditions: contains abb • ends with bab • contains at least 4 a-symbols Note: your automaton needs to recognise strings that match any of these conditions (including any combination of these conditions).arrow_forwardAn edge labeled with multiple symbols a, b,... → edge labeled with the symbol. Select one: Given regular expressions R1 and R2, then... True False Select one: EN KE a. R1+R2 is a regular expression b. R1R2 is a regular expression c. R1 is a regular expression d. All of the abovearrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education