In Bertrand's original paper, he explains a proof depended on a general formula for the number of favourable sequences implementing a recursion relation.ExampleLet there are 5 voters, of whom 3 vote for candidate A and 2 vote for candidate B (so p = 3 and q = 2). Ten possibilities are exist for the order of the votes cast −AAABBAABABABAABBAAABAABBAABABABAABAABBAABABAABBAAAFor the order AABAB, the tally of the votes as the election progresses is given below −CandidateAABABA12233B00112For each column the tally for A is always greater than the tally for B so the A is always strictly ahead of B. For ... Read More
In this tutorial, we will be discussing a program to convert one string to other using append and delete last operations.For this we will be provided with two strings. Our task is to calculate whether the first string can be converted into the second one by performing k operations of append and delete last element.Example#include using namespace std; //checking if conversion between strings is possible bool if_convert(string str1, string str2, int k){ if ((str1.length() + str2.length()) < k) return true; //finding common length of both string int commonLength = 0; for (int i = ... Read More
In this tutorial, we will be discussing a program to convert decimal number lying between 1 to 3999 to roman numerals.For this we will be provided with a random integer. Our task is to convert the given number into its roman numeral equivalent.Example Live Demo#include using namespace std; //converting decimal to roman numeral int printRoman(int number){ int num[] = {1,4,5,9,10,40,50,90,100,400,500,900,1000}; string sym[] = {"I","IV","V","IX","X","XL","L","XC","C","CD","D","CM","M"}; int i=12; while(number>0){ int div = number/num[i]; number = number%num[i]; while(div--){ cout
In this tutorial, we will be discussing a program to convert a number to have digits as 3 and 8 only.For this we will be provided with a random number. Our task is to convert its digits to be only 3 and 8 by either adding/subtracting 1 from the number or converting digits of the number to any desired digit.Example Live Demo#include using namespace std; //calculating minimum operations required int cal_min(long long int num){ //calculating remainder and operations int rem; int count = 0; while (num) { rem = num % 10; ... Read More
With respect of a given number, display or print all possible combinations of strings that can be implemented to dial the given number in a phone with the help of following pecifications.In the given phone, we can dial, 2 implementing A or B or C, 3 implementing D or E or F, ……………….8 implementing T or U or V, 9 implementing W or X or Y or Z, 1 implementing only 10 implementing 0.For example if 89, is the given phone number, the program should printTW, TX, TY, TZ, UW, UX, UY, UZ, VW, VX, VY, VZ#include #include ... Read More
In this tutorial, we will be discussing a program to convert to strictly increasing integer array with minimum changes.For this we will be provided with an array. Our task is to change the elements of the array to be in strictly increasing order by minimum number of changes in the elements.Example Live Demo#include using namespace std; //calculating number of changes required int remove_min(int arr[], int n){ int LIS[n], len = 0; for (int i = 0; i < n; i++) LIS[i] = 1; for (int i = 1; i < n; i++) { ... Read More
In this tutorial, we will be discussing a program to converting roman numerals to decimal lying between 1 to 3999.For this we will be provided with a random roman numeral. Our task is to convert the given roman numeral into its decimal equivalent.Example Live Demo#include using namespace std; //calculating the decimal value int value(char r){ if (r == 'I') return 1; if (r == 'V') return 5; if (r == 'X') return 10; if (r == 'L') return 50; if (r == 'C') return 100; if (r == 'D') ... Read More
In this tutorial, we will be discussing a program to find the convex hull of a given set of points using Jarvis’s Algorithm.Convex hull is the smallest polygon convex figure containing all the given points either on the boundary on inside the figure.In Jarvis’s algorithm, we select the leftmost point and keep wrapping points moving in the clockwise direction.Example Live Demo#include using namespace std; //structure of the point struct Point{ int x, y; }; //calculating the position of the points int cal_orientation(Point p, Point q, Point r){ int val = (q.y - p.y) * (r.x - q.x) - ... Read More
In this tutorial, we will be discussing a program to convert seconds into days, hours, minutes and seconds.For this we will be provided with a random number of seconds. Our task is to convert it into proper number of days, hours, minutes and seconds respectively.Example Live Demo#include using namespace std; //converting into proper format void convert_decimal(int n) { int day = n / (24 * 3600); n = n % (24 * 3600); int hour = n / 3600; n %= 3600; int minutes = n / 60 ; n %= 60; int seconds = n; cout
Some characters are reserved in HTML and they have special meaning when used in HTML document. For example, you cannot use the greater than and less than signs or angle brackets within your HTML text because the browser will treat them differently and will try to draw a meaning related to HTML tag.HTML processors must support following five special characters listed in the table that follows.SymbolDescriptionEntity NameNumber Code "quotation mark""'apostrophe''&ersand&&greater-than>>
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP