
Concept explainers
Write a computer
Input: The number of elements in a finite set S
Output: The number of derangements on S

Since you are not mentioning the programming language, here we are using C++ to complete the program.
PROGRAM:
#include <bits/stdc++.h>
using namespace std;
//derange_count() function
int derange_count(int n)
{
// Base case
if (n == 1) return 0;
if (n == 0) return 1;
if (n == 2) return 2;
//counting the Derangements
return ((n - 1) * (derange_count(n - 1) +derange_count(n - 2)));
}
//main() function
int main()
{
int n;
cout<<"\nEnter number of elements is the finite set:";
cin>>n;
cout << "\nNumber of Derangements: "
<< derange_count(n);
return 0;
}
Step by stepSolved in 2 steps with 1 images

- Sorting Jojo was given a Math assignment by his teacher. Jojo's task is to sort a number of given then find the closest pair of numbers that has the maximum difference after sorted. Jojo was asked to write down a list of the pairs of numbers. Input FormatThe first line of input is an integer N i.e. the number of numbersThe second line is a series of numbers Ai as many as N Output FormatPairs of numbers separated by spaces Constraints2 ≤ N ≤ 105-107 ≤ Ai ≤ 107 Sample Input 52 -8 3 1 -10 Sample Output-8 1 Sample Input1045 9 3 -6 100 68 -57 23 -11 -25 Sample Output-57 -25 68 100 In the sample above if the input is sorted then:-10 -8 1 2 3 so that the difference between each number in sequence is 2, 9, 1, 1-57 -25 -11 -6 3 9 23 45 68 100 so the difference is 32, 14, 5, 9, 6, 14, 22, 23, 32 NotesEven though it wasn't stated in the problem, by now you should know that the advantages spaces or lines are considered WRONG ANSWER.arrow_forwardUsing loops of any kind, lists, sets, def, etc NOT allowed Angela loves reading books. She recently started reading an AI generated series called “Harry Trotter”. Angela is collecting books from the series at her nearest bookstore. Since the series is AI generated, the publishers have produced an infinite collection of the books where each book is identified by a unique integer. The bookstore has exactly one copy of each book. Angela wants to buy the books in the range [l,r], where l ≤ r. As an example, the range [−3,3] means that Angela wants to buy the books − 3, − 2, − 1, 0, 1, 2, and 3. Dan also loves the series (or maybe annoying Angela – who knows, really), and he manages to sneak into the bookstore very early to buy all of the books in the range [d,u], where d ≤ u. When Angela later visits, sadly she will not find those books there anymore. For example, if Angela tries to buy books [−2,3] and Dan has bought books [0,2], Angela would only receive books − 2, − 1, and 3. The…arrow_forwardThere is more than one way to calculate the value of T. One way that this can be done is by generating random numbers. This works by recognizing that if you take a unit square that you can draw a quarter circle of unit radius inside the square. The area of the quarter circle is exactly π/4 and the area of the square is 1. So if you randomly generate a pair of uniform numbers between 0 and 1 they will be distributed uniformly across the square. If you count the total number of points generated and the number of points (x, y) where x² + y² = ² < 1 then the ratio of those two numbers will tend towards the ratios of the areas of the square and the circle as the number of points generated increases. The ratio of the areas is just π/4 so if you take that ratio and multiply it by 4 you get an estimate for . a) b Write code to estimate π using this method. You can generate random numbers in the range 0arrow_forward
- The power set of A is denoted by What is the size of the following set? (Enter your answer as a single integer). P(A) P(P(P(P(0))))arrow_forwardUp for the count def counting_series (n): The Champernowme word 1234567891011121314151617181920212223., also known as the counting series, is an infinitely long string of digits made up of all positive integers written out in ascending order without any separators. This function should return the digit at position n of the Champernowne word. Position counting again starts from zero for us budding computer scientists. Of course, the automated tester will throw at your function values of n huge enough that those who construct the Champernowne word as an explicit string will run out of both time and space long before receiving the answer. Instead, note how the fractal structure of this infinite sequence starts with 9 single-digit numbers, followed by 90 two-digit numbers, followed by 900 three-digit numbers, and so on. This observation gifts you a pair of seven league boots that allow their wearer skip prefixes of this series in exponential leaps and bounds, instead of having to crawl…arrow_forwardwrite a computer program that produces the desired output from the given input. Input: Elements in a finite set SOutput: Elements in ℘(S)Algorithm: Use recursion.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





