Data Structure Algorithms Articles

Found 234 articles

Dynamic Programming in JavaScript

Samual Sam
Samual Sam
Updated on 15-Mar-2026 3K+ Views

Dynamic programming breaks down complex problems into smaller sub-problems and stores their solutions to avoid redundant calculations. This technique is particularly useful for optimization problems where overlapping sub-problems exist. Dynamic programming is used where we have problems that can be divided into similar sub-problems so that their results can be re-used. Before solving a sub-problem, the algorithm checks if it has already been solved and stored. The solutions of sub-problems are combined to achieve the optimal solution. When to Use Dynamic Programming For a problem to benefit from dynamic programming: The ...

Read More

The Fibonacci sequence in Javascript

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 637 Views

The Fibonacci sequence is a series of numbers where each number is the sum of the two preceding ones. The sequence starts with 1, 1 (or sometimes 0, 1). 1, 1, 2, 3, 5, 8, 13, 21, 34, ... Naive Recursive Approach The most straightforward way to generate the nth Fibonacci number uses recursion: function fibNaive(n) { if (n

Read More

C program for DFA accepting all strings over w ∈(a,b)* containing "aba" as a substring

Bhanu Priya
Bhanu Priya
Updated on 11-Mar-2026 3K+ Views

ProblemDesign a DFA for the language L={w1abaw2 | w1, w2 Є(a, b)*}, which means the DFA accepts all strings which contain “aba” as a substring.SolutionThe strings that are accepted by language L= {aba, aabaa, aabab, babab, ababa, …….}Step 1 − Transition diagram for minimal string (starting string) −If w1 and w2 are null then the string it generates is “aba” because w1, w2 ε(a, b)*q0 is the initial state and q3 is the final state.Step 2 − The final DFA for the given language is as follows −Explanationqo is the initial state q0 on ‘a’ goes to q1 and on ...

Read More

C Program to construct DFA accepting odd numbers of 0s and 1s

Bhanu Priya
Bhanu Priya
Updated on 11-Mar-2026 10K+ Views

Construct deterministic finite automata (DFA) for the language L = { w : w has odd number of 0’s and w has odd number of 1’s}, over the alphabet Σ = {0, 1}.Example0111, 010101, 01110011 is an accepted string, because those strings have an odd number of 0’s and an odd number of 1’s.For the given language we will need four states to draw the main DFA which will read odd no. of 0s and 1s. We can also draw it by merging the two DFAs in which one will accept only an odd number of 0s and one accepts ...

Read More

C Program to build DFA accepting the languages ending with "01

Bhanu Priya
Bhanu Priya
Updated on 11-Mar-2026 18K+ Views

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

Operations on an Array in Data Structures

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 1K+ Views

Here we will see some basic operations of array data structure. These operations are −TraverseInsertionDeletionSearchUpdateThe traverse is scanning all elements of an array. The insert operation is adding some elements at given position in an array, delete is deleting element from an array and update the respective positions of other elements after deleting. The searching is to find some element that is present in an array, and update is updating the value of element at given position. Let us see one C++ example code to get better idea.Example#include #include using namespace std; main(){    vector arr;    //insert elements   ...

Read More

Matrix multiplication algorithm

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 27K+ Views

In this section we will see how to multiply two matrices. The matrix multiplication can only be performed, if it satisfies this condition. Suppose two matrices are A and B, and their dimensions are A (m x n) and B (p x q) the resultant matrix can be found if and only if n = p. Then the order of the resultant matrix C will be (m x q).AlgorithmmatrixMultiply(A, B): Assume dimension of A is (m x n), dimension of B is (p x q) Begin    if n is not same as p, then exit    otherwise define C ...

Read More

Binary Tree Traversals in Data Structures

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 1K+ Views

In this section we will see different traversal algorithms to traverse keys present in binary search tree. These traversals are Inorder traversal, Preorder traversal, Postorder traversal and the level order traversal.Suppose we have one tree like this −The Inorder traversal sequence will be like − 5 8 10 15 16 20 23The Preorder traversal sequence will be like − 10 5 8 16 15 20 23The Postorder traversal sequence will be like − 8 5 15 23 20 16 10The Level-order traversal sequence will be like − 10, 5, 16, 8, 15, 20, 23AlgorithminorderTraverse(root): Begin    if root is not ...

Read More

Level Order Tree Traversal in Data Structures

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 611 Views

In this section we will see the level-order traversal technique for binary search tree.Suppose we have one tree like this −The traversal sequence will be like: 10, 5, 16, 8, 15, 20, 23AlgorithmlevelOrderTraverse(root): Begin    define queue que to store nodes    insert root into the que.    while que is not empty, do       item := item present at front position of queue       print the value of item       if left of the item is not null, then          insert left of item into que       end ...

Read More

Bernoulli Distribution in Data Structures

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 504 Views

The Bernoulli Distribution is a discrete distribution having two possible outcomes labeled by x = 0 and x = 1. The x = 1 is success, and x = 0 is failure. Success occurs with probability p, and failure occurs with probability q as q = 1 – p. So$$P\lgroup x\rgroup=\begin{cases}1-p\:for & x = 0\p\:for & x = 0\end{cases}$$This can also be written as −$$P\lgroup x\rgroup=p^{n}\lgroup1-p\rgroup^{1-n}$$Example#include #include using namespace std; int main(){    const int nrolls=10000;    default_random_engine generator;    bernoulli_distribution distribution(0.7);    int count=0; // count number of trues    for (int i=0; i

Read More
Showing 1–10 of 234 articles
« Prev 1 2 3 4 5 24 Next »
Advertisements