- 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
Negative Binomial distribution in Data Structures
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
#include <iostream> #include <random> 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<int> distribution(3,0.5); int p[10]={}; for (int i=0; i<nrolls; ++i) { int number = distribution(generator); if (number<10) p[number]++; } cout << "negative_binomial_distribution (3,0.5):" << endl; for (int i=0; i<10; ++i) cout << i << ": " << string(p[i]*nstars/nrolls,'*') << endl; }
Output
0: ************ 1: ******************* 2: ***************** 3: **************** 4: *********** 5: ******* 6: ***** 7: *** 8: ** 9: *
Advertisements