Found 33676 Articles for Programming

Program for Rabin-Karp Algorithm for Pattern Searching in C

sudhir sharma
Updated on 17-Jul-2020 12:36:21

411 Views

In this problem, we are given two strings a text and a pattern. Our task is to create a program for Rabin-Karp algorithm for pattern search, it will find all the occurrences of pattern in text string.Here, we have to find all the occurrences of the pattern in the text.Let’s take an example to understand the problem, Inputtext = “xyztrwqxyzfg” pattern = “xyz”OutputFound at index 0 Found at index 7Here, we will discuss the solution of the problem using the Rabin-Karp algorithm. In this algorithm, we take a window of the size of the pattern in the string and slide ... Read More

C Program for KMP Algorithm for Pattern Searching

sudhir sharma
Updated on 17-Jul-2020 12:32:15

10K+ Views

In this problem, we are given two strings a text and a pattern. Our task is to create a program for KMP algorithm for pattern search, it will find all the occurrences of pattern in text string.Here, we have to find all the occurrences of patterns in the text.Let’s take an example to understand the problem, Inputtext = “xyztrwqxyzfg” pattern = “xyz”OutputFound at index 0 Found at index 7Here, we will discuss the solution to the problem using KMP (Knuth Morris Pratt) pattern searching algorithm, it will use a preprocessing string of the pattern which will be used for matching ... Read More

C Program for Iterative Merge Sort

sudhir sharma
Updated on 17-Jul-2020 12:27:30

1K+ Views

Merge sort what is a sorting algorithm based on the divide and conquer technique. the time complexity of merge sort is O(n log n). The algorithm first divides the array into equal halves and then merges them in a certain manner.Iterative merge sortIn iterative merge sort, we will divide the elements into equal halves using a recursive approach and then merge them back as a sorted array using the iterative approach.Program for iterative Merge Sort/* Recursive C program for merge sort */Example Live Demo#include #include void merge(int arr[], int l, int m, int r) {    int i, j, k;   ... Read More

C Program for Anagram Substring Search

sudhir sharma
Updated on 17-Jul-2020 12:24:10

280 Views

In this problem, we are given two string one text of size n and other a pattern of size m. Our task is to create a program for Anagram substring search.Here, we have to find all the occurrence of pattern and all its permutations (anagrams) in the text.Let’s take an example to understand the problem, Inputtext = “xyztrwqyzxfg” pattern = “xyz”OutputFound at index 0 Found at index 7To solve this problem, we will have to use an algorithm similar to the Rabin Karp algorithm which is used to check for anagram occurrence by adding the ASCII values of all characters ... Read More

Binary tree to string with brackets in C++

sudhir sharma
Updated on 17-Jul-2020 12:21:45

487 Views

In this problem, we are given a binary tree. Our task is to create a program that will convert a binary tree to string with brackets in C++.The values of the binary tree are integers and it will be fed to the program in a preorder traversing way. The string should contain only integers and parentheses (), also it should be optimized i.e. all the empty pairs should be eliminated.Binary Tree is a tree that has a special condition that each node can have a maximum of two children.Example of a binary tree −Preorder traversal : [4, 1, 8, 3, ... Read More

Binary Indexed Tree: Range Update and Range Queries in C++

sudhir sharma
Updated on 17-Jul-2020 12:09:31

385 Views

Here, we are given an array of size n which initially has all elements 0. And there are some queries that are to be performed on it. There are two types of queries −update(l, r, value) − Add value to the elements of the array that are between index l to r. For example, update(2, 4, 5) will update the array by placing the element 2 at the element at index 4 and 5.getRangeSum(l, r) − Find the sum of elements within the range of elements from l to r. For example, getRangeSum(4, 7) will find the sum of all ... Read More

beta(), betaf() and betal() functions in C++ STL

sudhir sharma
Updated on 17-Jul-2020 12:05:24

288 Views

The functions beta(), betaf() and betal() are built-in functions in the standard template library of C++. These functions are used to calculate the beta function of two positive real numbers.The functions beta(), betaf() and betal() are built-in functions in the standard template library of C++. These functions are used to calculate the beta function of two positive real numbers.$B(x, y)=\int_{0}^{1}t^{(x-1)}(1-t)^{(y-1)}dt$beta()The beta() function is used to deal with values of data type double i.e. it accepts the parameter of double type and returns are double value.Syntaxdouble beta(double x, double y)Parametersx is a double value that gives the value of x in ... Read More

Bertrand's Postulate in C++

sudhir sharma
Updated on 17-Jul-2020 12:00:29

195 Views

Bertrand’s postulates is a mathematical showroom which states that for every number n>3, there exists a prime number p which lies between n and 2n-2.The formula for Bertrand's Postulaten < p < 2n -2Where n is a number such that n>3 and p is a prime number.Prime number − A number is a prime number if it's only factors are 1 and itself.A less restrictive formulation of Bertrand’s postulate isn < p < 2n , for all n>1.ExamplesNumber5Output7Explanationprime number in range 5 and 2*5 i.e. prime number between 5 and 10Number11Output13, 17, 19Explanationprime number in range 11 and 2*11 i.e. ... Read More

Berkeley’s Algorithm in C/C++

sudhir sharma
Updated on 17-Jul-2020 11:56:44

2K+ Views

Berkeley’s Algorithm is an algorithm that is used for clock Synchronisation in distributed systems. This algorithm is used in cases when some or all systems of the distributed network have one of these issues −A. The machine does not have an accurate time source.B. The network or machine does not have a UTC server.Distributed system contains multiple nodes that are physically separated but are linked together using a network.Berkeley’s AlgorithmIn this algorithm, the system chooses a node as master/ leader node. This is done from pool nodes in the server.The algorithm is −An election process chooses the master node in ... Read More

Bayes Theorem for Conditional Probability in C/C++

sudhir sharma
Updated on 17-Jul-2020 11:54:29

885 Views

Conditional probability denoted by P(A|B) is the probability of occurrence of an event ‘A’ given that event ‘B’ has already occurred.Formula for conditional probability −P(A|B) = P( A⋂B ) / P(B)Bayes’s TheoremIt is the formula that shows the relation between probabilities of occurrences of mutually dependent events i.e. it given the relation between their conditional probabilities.Given an event A and another event B, according to bayes’ theorem, P(A/B) = {P(B/A) * P(A)} / P(B)Lets derive the formula for Bayes’ theorem, For this we will use the formula for conditional probability, P(A|B) = P( A?B ) / P(B) —— 1 P(B|A) ... Read More

Advertisements