- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 349 Articles for Data Structure Algorithms
79 Views
The Negative Binomial Distribution is a random number distribution that will produce integers according to a negative binomial discrete distribution. This is known as Pascal’s distribution So the negative binomial distribution can be written as$$P\lgroup i\arrowvert k,p\rgroup=\lgroup \frac{k+i-1}{i}\rgroup p^{k}\lgroup 1-p\rgroup^{i}$$Example Live Demo#include #include using namespace std; int main(){ const int nrolls = 10000; // number of rolls const int nstars = 100; // maximum number of stars to distribute default_random_engine generator; negative_binomial_distribution distribution(3,0.5); int p[10]={}; for (int i=0; i
226 Views
The Geometric Distribution is a discrete probability distribution for n = 0, 1, 2, …. having the probability density function.$$P\lgroup n\rgroup=p\lgroup1-p\rgroup^{n}$$The distribution function is −$$D\lgroup n\rgroup=\displaystyle\sum\limits_{i=0}^n P\lgroup i \rgroup=1-q^{n+1}$$Example Live Demo#include #include using namespace std; int main(){ const int nrolls = 10000; // number of rolls const int nstars = 100; // maximum number of stars to distribute default_random_engine generator; geometric_distribution distribution(0.3); int p[10]={}; for (int i=0; i
257 Views
The Binomial Distribution is a discrete probability distribution Pp(n | N) of obtaining n successes out of N Bernoulli trails (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 the binomial distribution can be written as$$P_{p}\lgroup n\:\arrowvert\ N\rgroup=\left(\begin{array}{c}N\ n\end{array}\right) p^{n}\lgroup1-p\rgroup^{N-n}$$Example Live Demo#include #include using namespace std; int main(){ const int nrolls = 10000; // number of rolls const int nstars = 100; // ... Read More
233 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 Live Demo#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
15K+ Views
A spanning tree is a subset of an undirected Graph that has all the vertices connected by minimum number of edges.If all the vertices are connected in a graph, then there exists at least one spanning tree. In a graph, there may exist more than one spanning tree.Minimum Spanning TreeA Minimum Spanning Tree (MST) is a subset of edges of a connected weighted undirected graph that connects all the vertices together with the minimum possible total edge weight. To derive an MST, Prim’s algorithm or Kruskal’s algorithm can be used. Hence, we will discuss Prim’s algorithm in this chapter.As we ... Read More
16K+ Views
Here we will see what are the different applications of DFS and BFS algorithms of a graph?The DFS or Depth First Search is used in different places. Some common uses are −If we perform DFS on unweighted graph, then it will create minimum spanning tree for all pair shortest path treeWe can detect cycles in a graph using DFS. If we get one back-edge during BFS, then there must be one cycle.Using DFS we can find path between two given vertices u and v.We can perform topological sorting is used to scheduling jobs from given dependencies among jobs. Topological sorting ... Read More
39K+ Views
In this section we will see what is a graph data structure, and the traversal algorithms of it.The graph is one non-linear data structure. That is consists of some nodes and their connected edges. The edges may be director or undirected. This graph can be represented as G(V, E). The following graph can be represented as G({A, B, C, D, E}, {(A, B), (B, D), (D, E), (B, C), (C, A)})The graph has two types of traversal algorithms. These are called the Breadth First Search and Depth First Search.Breadth First Search (BFS)The Breadth First Search (BFS) traversal is an algorithm, ... Read More
485 Views
The binary search trees are binary tree which has some properties. These properties are like below −Every Binary Search Tree is a binary treeEvery left child will hold lesser value than rootEvery right child will hold greater value than rootIdeal binary search tree will not hold same value twice.Suppose we have one tree like this −This tree is one binary search tree. It follows all of the mentioned properties. If we traverse elements into inorder traversal mode, we can get 5, 8, 10, 15, 16, 20, 23. Let us see one code to understand how we can implement this in ... Read More
367 Views
In this section we will see the pre-order traversal technique (recursive) for binary search tree.Suppose we have one tree like this −The traversal sequence will be like: 10, 5, 8, 16, 15, 20, 23AlgorithmpreorderTraverse(root): Begin if root is not empty, then print the value of root preorderTraversal(left of root) preorderTraversal(right of root) end if EndExample Live Demo#include using namespace std; class node{ public: int h_left, h_right, bf, value; node *left, *right; }; class tree{ private: node *get_node(int key); ... Read More
327 Views
In this section we will see the post-order traversal technique (recursive) for binary search tree.Suppose we have one tree like this −The traversal sequence will be like: 8, 5, 15, 23, 20, 16, 10AlgorithmpostorderTraverse(root): Begin if root is not empty, then postorderTraversal(left of root) postorderTraversal(right of root) print the value of root end if EndExample Live Demo#include using namespace std; class node{ public: int h_left, h_right, bf, value; node *left, *right; }; class tree{ private: node *get_node(int key); ... Read More