Server Side Programming Articles - Page 1956 of 2650

Construct a Turing machine for L = {aibjck | i>j>k; k ≥ 1}

Arnab Chakraborty
Updated on 03-Jan-2020 11:26:31

844 Views

Here we will see how to make a Turing machine for language L = {AiBjCk | i > j > k; k ≥ 1}. So this represents a kind of language where we will use only three characters a, b and c. The w is a string. So if w = aaaaaabbbbccc, The Turing machine will accept it.To solve this, we will use this approach. Firstly compare two elements by making A and D as a single element, after that comparing A and D if count of C is greater than |(A, D)|, then the string will not be accepted, ... Read More

Construct a Turing machine for L = {aibjck | i< j< k; i ≥ 1}

Arnab Chakraborty
Updated on 03-Jan-2020 11:24:50

2K+ Views

Here we will see how to make a Turing machine for language L = {AiBjCk | i < j < k; i ≥ 1}. So this represents a kind of language where we will use only three characters A, B and C. The w is a string. So if w = AABBBBCCCCC, The Turing machine will accept it.To solve this, we will use this approach. Firstly compare two elements as a single element, after that comparing the single element if |first| > |(Second, Third)|, and |Second| > |Third|, then it will be accepted. Now if |Third| > |(First, Second)| and ... Read More

Construct a Turing machine for L = {aibjck | i*j = k; i, j, k ≥ 1}

Arnab Chakraborty
Updated on 03-Jan-2020 11:23:30

2K+ Views

Here we will see how to make a Turing machine for language L = {AiBjCk | i * j = k; i, j, k ≥ 1}. So this represents a kind of language where we will use only three characters A, B and C. The w is a string. So if w = AABBBBCCCCCCCC, The Turing machine will accept it.To solve this, we will use this approach.First replace an A with x and move right. Then skip all the A’s and move rightWhen the head reach to the first B then replace one B with y, then move right skipping ... Read More

Construct a graph from given degrees of all vertices in C++

Arnab Chakraborty
Updated on 03-Jan-2020 11:21:57

342 Views

Suppose we have a list of vertices, and their degrees are given. We have to generate one undirected graph from that degree sequence. It will not include loop or multiple edges. So if the degree sequence is like [2, 2, 1, 1], then the graph can be likeTo solve this, we will follow these steps −Define adjacency matrix adj to store the graphfor each vertex i, dofor each vertex j that is valid, and next to iif the degree of vertex i and j are more than zero, then connect themdisplay the matrix.Example Live Demo#include #include using namespace std; ... Read More

Construct a frequency array of digits of the values obtained from x^1, x^2, ....., x^n in C++

Arnab Chakraborty
Updated on 03-Jan-2020 11:18:25

146 Views

Suppose we have two integers x and n. We have to find the array such that it contains the frequency of index numbers occurring in (x^1, x^2, … x^(n – 1), x^n). So if x = 15 and n = 3, then output will be [0, 1, 2, 2, 0, 3, 0, 1, 0, 0]. As we know that x^1 to x^n, the values are 15, 225 and 3375. So the frequency array is 0, 1, 2, 2, 0, 3, 0, 1, 0, 0To solve this, we will follow these steps −Maintain the frequency count array to store the counts ... Read More

Why is a[i] == i[a] in C/C++ arrays?

Arnab Chakraborty
Updated on 03-Jan-2020 11:15:27

340 Views

Here we will see one amazing trick in C or C++. The array subscript A[i] can also be written as i[a]. In C/C++ E1[E2] is defined as (*((E1) + (E2))). The compiler performs arithmetic internally to access the array elements. Because of the conversion of rules, that is applied to the binary + operator, if E1 is an array object, and E2 is an integer, then E1[[E2] signifies the E2th element in the E1 array. So A[B] can be defined as *(A + B), so B[A] = *(B + A). so they are basically the same thing.Example Live Demo#include using ... Read More

Unary operators in C/C++

Arnab Chakraborty
Updated on 03-Jan-2020 11:14:06

2K+ Views

Here we will see what are the unary operators in C / C++. Unary operator is operators that act upon a single operand to produce a new value. The unary operators are as follows.OperatorDescriptionIndirection operator (*)It operates on a pointer variable and returns an l-value equivalent to the value at the pointer address. This is called "dereferencing" the pointer.Address-of operator (&)The unary address-of operator (&) takes the address of its operand. The operand of the address-of operator can be either a function designator or an l-value that designates an object that is not a bit field and is not declared ... Read More

Type Conversion in C++

Arnab Chakraborty
Updated on 03-Jan-2020 11:11:22

2K+ Views

Here we will see what are the type conversion techniques present in C++. There are mainly two types of type conversion. The implicit and explicit.Implicit type conversionThis is also known as automatic type conversion. This is done by the compiler without any external trigger from the user. This is done when one expression has more than one datatype is present.All datatypes are upgraded to the datatype of the large variable.bool -> char -> short int -> int -> unsigned int -> long -> unsigned -> long long -> float -> double -> long doubleIn the implicit conversion, it may lose ... Read More

Top Reasons to Learn C++

Arnab Chakraborty
Updated on 03-Jan-2020 11:08:36

218 Views

Here we will see some good reasons behind taking the language C++ as our favorite programming language. We know that C++ is one of the most popular object oriented programming language. These are the reasons behind taking the C++ into consideration.C++ Popularity and High salary −C++ is one of the most popular language in the world. It is used nearly 4.4 million developers worldwide. The C++ developers hold highest paying jobs in the industry with an average base pay of $100000 per year.C++ has abundant library supportv −C++ has Standard Template Library (STL). This helps to write code compactly and ... Read More

Timer in C++ using system calls

Arnab Chakraborty
Updated on 13-Jul-2020 08:40:17

944 Views

Here we will see how to design timer in C++ using a system call. We will not use any graphics or animations. Here timer means the stopwatch, that is up-counting the time. The used system calls are −sleep(n) − This will help the program to sleep for n number of secondssystem() − This is used to execute the system command by passing command as an argument to this function.Example Live Demo#include #include #include #include using namespace std; int hrs = 0; int mins = 0; int sec = 0; void showClk() {    system("cls");    cout

Advertisements