Concept explainers
CONSIDER
In Ocaml:
type ('q, 's) transi = 'q * 's option * 'q
type ('q, 's) nfa_y = { sigma : 's list; qs : 'q list; q0 : 'q; fs : 'q list; delta : ('q, 's) transi list; }
So:
- let nfa = { sigma = ['z']; qs = [1; 2; 3]; q0 = 1; fs = [3]; delta = [(1, Some 'z', 2); (2, None, 3)] }
mo n ql t, of Type: ('q, 's) nfa_y -> 'q list -> 's option -> 'q list, takes an NFA n, a set of initial states ql, and a symbol option t. It returns a set of states that the NFA might be in after starting from any state in ql and making one transition on the symbol t.
So:
- mo nfa [1] (Some 'z') = [2]
mo nfa [2] (Some 'z') = []
mo nfa [3] (Some 'z') = []
mo nfa [1;2] (Some 'z') = [2]
mo nfa [2] None = [3]
e_clo n ql, of Type: ('q, 's) nfa_y -> 'q list -> 'q list, takes an NFA n and a set of initial states ql. It returns a set of states that the NFA might be in after making zero or more epsilon transitions from any state in ql.
So:
- e_clo nfa [1] = [1]
e_clo nfa [2] = [2;3]
e_clo nfa [3] = [3]
e_clo nfa [1;2] = [1;2;3]
PROBLEM: Complete function
acce n t, of Type ('q, char) nfa_y -> string -> bool
which takes an NFA nfa and a string s, and returns true if the NFA accepts the string.
Example:
let dfa = {
sigma = ['z'; 'y'; 'x'];
qs = [1; 2; 3];
q0 = 1;
fs = [3];
delta = [(1, Some 'z', 2); (2, Some 'y', 1); (2, Some 'x', 3)]
};;
acce dfa "" = false;; (* dfa_ex is the NFA defined above *)
acce dfa "zx" = true;;
acce dfa "zyx" = false;;
acce dfa "zyzx" = true;;
Step by stepSolved in 2 steps
- 2arrow_forwardPYTHON LANGUAGEarrow_forwardThis code is a part of a C dictionary. Please write the code for the below requirements. dict_get Next, you will implement: char* dict_get (const dict_t* dict, const char* key); This function goes through the list given by dict. If you use the above structure, this means starting at el = dict->head and checking each time whether the key at el is key; if it is not, we set el = el->next, until either key is found, or we reach el == NULL. To compare key with el->key, we need to compare one by one each character in key with those in el->key. Remember that strings in C are just pointers (memory addresses) to the first character in the string, so comparing el->key == key will not do what you want. So how do you even get the length of a string s? You would start at memory location s and advance as long as the byte at s (i.e. *s) is not the end-of-string marker (\0, the NULL character). This can get a bit messy, so luckily, you are allowed to use the string comparison…arrow_forward
- 1. Write a function invert_dict to reverse a dictionary, for example: >>> eng2sp = {'one': 'uno', 'two': 'dos', 'three': 'tres'} >>> sp2eng = invert_dict(eng2sp) >>> sp2eng {'uno':'one', 'dos':'two', 'tres':'three'} 2. Write a function print_dict to print all the key-values in a dictionary, for example: >>> d2 {'a': 'one', 'b': 'two', 'c': 'Three'} >>> print_dict(d2) a:one b:two c:Threearrow_forward4 ete t of With the following lists: list1 = [x + y for x in ['a', 'b', 'c'] for y in ['1', '2', '3']] list2 = [[x + y for x in ['a', 'b', 'c']] for y in ['1', '2', '3']] which option is true? Select one: A. len(list1)> len(list2) B. 'a1' is an element (or subelement) for list1 whereas '1a' is for list2 C. list1 and list2 will error because numbers and letters cannot be added. D. Both A and B are true.arrow_forwardprogram by using C language In the struct structure given below, the data of a student is stored in a singly linear linked list. Write a function named "secondHighest" that takes the starting address of the list as a parameter and returns the student number with the second highest grade? typedef struct node { int OgrNo; int not; struct node *next; };arrow_forward
- use code below in part with bts #include <stdio.h>#include <stdlib.h>#include <time.h> typedef struct node_struct {int item;struct node_struct *next;} node; /*** 10->NULL* We want to insert 20* First call ([10], 20) [not complete]* {10, {20, NULL}} To compute the conditional probabilities you need to determine unigram andbigram counts first (you can do this in a single pass through a file if you do thingscarefully) and store them in a Binary Search Tree (BST). After that, you can computethe conditional probabilities.Input filesTest files can be found on (http://www.gutenberg.org/ebooks/). For example,search for “Mark Twain.” Then click on any of his books. Next download the “PlainText UTF-8” format.In addition, you should test your program on other input files as well, for which youcan hand-compute the correct answer.Output filesYour program must accept the name of an input file as a command line argument.Let's call the file name of this file fn. Your program must…arrow_forwarddef animals(animal_dict, target): """ Filter animals based on the target category. :param animal_dict: A dictionary mapping animals to their categories. :type animal_dict: dict :param target: The target category to filter animals. :type target: str :return: A list of animals belonging to the target category. :rtype: list animals_dict = {"dogs": "mammals", "snakes": "reptiles", \ "dolphins": "mammals", "sharks": "fish"} >>> target = "mammals" >>> animals(animals_dict, target) ['dogs', 'dolphins'] >>> animals_dict = {True: "mammals"} >>> animals(animals_dict, target) # This will raise an AssertionError Traceback (most recent call last): ... AssertionError: Target should be provided and not None """ assert target is not None, "Target should be provided and not None" assert isinstance(animal_dict, dict) assert all(isinstance(animal, str) for animal in animal_dict.keys())…arrow_forwardcard_t * moveCardBack (card t *head); The moveCardBack function will take the card in front of the pile and place it in the back. In coding terms, you are taking the head of the linked list and moving it to the end. The function has one parameter which is the head of the linked list. After moving the card to the back, the function returns the new head of the linked list.arrow_forward
- ▾ Part 1: Sin Tax Syntax [NEW PROBLEM] Complete the function sin_tax, which computes and returns the total cost to purchase several items, some of which might be subject to sin taxes. The function takes three arguments: • items: a list of items to purchase (strings). If an item appears more than once, this means we want to buy it more than once. • prices! a dictionary that maps an item (string) to its price (float) • tax rates: a dictionary that maps an item (string) to its sin tax rate (float). The rate is given as a decimal (e.g., 0.08 to represent 8%). If an item from items does not appear in tax rates, then that item is not subject to a sin tax. Assume that every string in items is a valid key in prices. Example #1: items: ['beer', 'wine', 'cigarettes'] prices: {'beer': 18.95, 'cigarettes': 12, 'wine': 20.0} tax_rates: {'beer': 0.03, 'cigarettes': 0.1, wine': 0.05) Returned: 53.72 Example #2: ['wine', 'beer', 'wine', 'cigarettes', 'wine'] {'beer': 15.5, 'cigarettes': 13, 'soda':…arrow_forward3 4 5 5 7 3 9 3 1 2 B 4 5 7 9 0 2 3 4 5 8 0 1 def calculate_trip_time( iata_src: str, iata_dst: str, flight_walk: List[str], flights: FlightDir ) -> float: Return a float corresponding to the amount of time required to travel from the source airport to the destination airport to the destination airport, as outlined by the flight_walk. PERBE The start time of the trip should be considered zero. In other words, assuming we start the trip at 12:00am, this function should return the time it takes for the trip to finish, including all the waiting times before, and between the flights. If there is no path available, return -1.0 >>> calculate_trip_time("AA1", 2.0 >>> calculate_trip_time("AA1", >>> calculate_trip_time("AA1", >>> calculate_trip_time("AA1", 0.0 >>> calculate_trip_time("AA4", 14.0 >>> calculate_trip_time("AA1", 7.5 >>> calculate_trip_time("AA1", 2.0 *** "AA2", ["AA1", "AA2"], TEST_FLIGHTS_DIR_FOUR_CITIES) "AA7", ["AA7"] "AA1"], TEST_FLIGHTS_DIR_FOUR_CITIES) "AA7", ["AA1",…arrow_forwardC languagearrow_forward
- 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