To plot true/false or active/deactive data in Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create data using numpy with True or False.Create a new figure or activate an existing figure using figure() method.Add an '~.axes.Axes' to the figure as part of a subplot arrangement.Use imshow() method to display data as an image, i.e., on a 2D regular raster.To display the figure, use show() method.Exampleimport matplotlib.pyplot as plt import numpy as np plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True data = np.random.random((20, 20)) > 0.5 fig = ... Read More
To view all colormaps available in Matplotlib, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create a new figure or activate an existing figure.Add an '~.axes.Axes' to the figure as part of a subplot arrangementMake an axis that is divider on the existing axes.Create random data using numpy.Display the data as an image, i.e., on a 2D regular raster.Create a colorbar for a ScalarMappable instance, im.Set a title for the current figure.Animate the image with all colormaps available in matplotlib.Make an animation by repeatedly calling a function.To display the figure, ... Read More
Before understanding the differences between the finite automata (FA) and the turing machine (TM), let us learn about these concepts.Finite AutomataFinite automata is an abstract computing deviceIt is a mathematical model of a system with discrete inputs, outputs, states and set of transitions from state to state that occurs on input symbol from alphabet ΣFinite Automata RepresentationFA can be represented as following in the theory of computation (TOC) −Graphical (Transition diagram)Tabular (Transition table)Mathematical (Transition function)Formal definition of Finite AutomataA Finite automata is a five tuplesM=(Q, Σ, δ, q0, F)Where, Q − Finite set called statesΣ − Finite set called alphabetsδ ... Read More
ProblemDesign deterministic finite automata (DFA) with ∑ = {0, 1} that accepts the languages ending with “01” over the characters {0, 1}.SolutionThe strings that are generated for a given language are as follows −L={01, 001, 101, 110001, 1001, ……….}The minimum length of the string is 2, the number of states that the DFA consists of for the given language is: 2+1 = 3 states.Here, q0 − On input 0 it goes to state q1 and on input 1 it goes to itself.q1 − On input 0 it goes to itself and on input 1 it goes to State q2.q2 − ... Read More
Firstly, let us learn about the infinite language and then understand how to construct the finite and infinite language in the theory of computation (TOC).Infinite languageThere is no bound on the length of any strings in an infinite language.There is no bound on any number of derivation steps used to derive the strings also.For example, if the grammar has n productions, then any derivation consisting of n + 1 steps uses some production twice.If the language is said to be infinite, then some production or sequence of productions must be used repeatedly to construct the derivationsExampleThe infinite language {anb | ... Read More
AlgorithmStep 1 - If there is no input, reach the final state and halt.Step 2 - If the input = “a‟, then traverse forward to process the last symbol = “a‟. Convert both a‟s to B‟.Step 3 - Move left to read the next symbol.Step 4 - If the input = “b‟, replace it by B and move right to process its equivalent “B‟ at the rightmost end.Step 5 - Convert the last ’b’ to ‘B’.Step 6 - Move left and process step 2 – 5 until there are no more inputs to process.Step 7 - If the machine reaches ... Read More
Type 2 grammars are context free grammars (CFG).All productions are of the form −A → x — where A is nonterminal, x is a string of nonterminal and terminals, A context-free grammar is equivalent to a pushdown automaton (PDA) and to context free languages.Example − Pushdown Automaton (PDA)PropertiesA grammars, G = (V, T, P, S) is said to be context free if the production rule is of the form, A → α .The transition allows A → ε [i.e., α → ε] where, A is a non terminal symbol α is any terminal or non-terminal symbol.Here, the left hand side of ... Read More
To have colorbar background and label placement, we can take the following steps −Set the figure size and adjust the padding between and around the subplots.Create random data using numpy.Plot the contours.With scalar mappable instance, make the colorbar.Set ticklabels for colorbar with background and label placementTo display the figure, use show() method.Exampleimport numpy as np import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True data = np.linspace(0, 10, num=16).reshape(4, 4) cf = plt.contourf(data, levels=(0, 2.5, 5, 7.5, 10)) cb = plt.colorbar(cf) cb.set_ticklabels([1, 2, 3, 4, 5]) plt.show()Output
AlgorithmStep 1: Process the leftmost „a‟ and replace it by „x‟.Step 2: Move right until the leftmost „b‟ is reached. Replace it by „y‟.Step 3: Move right until the leftmost „c‟ is reached. Replace it by „z‟.Step 4: Move left to reach the leftmost „a‟ and perform steps 1, 2 and 3 (n – 1) times.Step 5: Halt if there are „n‟ number of x, y, z.Turing Machine for the given language is as follows −The Turing machine, M is given by M = (Q, Σ, Γ, δ, q0, B, F)Where, Q = {q0, q1, q2, q3, q4, q5}Σ = ... Read More
The set of all strings (over terminal symbols) which can be derived from the start symbol is the language generated by the grammar G.Example 1Let grammar G be defined by the set of terminals T = {a, b}, the only non-terminal start symbol S and the set of production rules. Hence, the grammar G would be as follows −S → ∧, S → aSbOr in shorthand, it is as mentioned below −S → ∧ | aSbL(G) = {∧, ab, aabb, aaabbb, . . . }DefinitionIf G is called as a grammar with start symbol S and set of terminals T, ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP