If there are n people that have telephones, and only two people can talk to each
ID: 666639 • Letter: I
Question
If there are n people that have telephones, and only two people can talk to each other at any given times,
there can be many different ways in which people can be talking to each other. The number of ways possible grows quickly as the number of people, n , grows. This forms a sequence where the nth term is the number of ways the n people can connect. The first two terms of this sequence are both 1, and then the nth term can be obtained by taking the (n - 1)st term and adding it to the result of (n - 1) multiplied by the (n - 2)nd term.
The first few telephone numbers (starting with n = 0, i.e., zero phones) are
1; 1; 2; 4; 10; 26; 76; 232; 764; 2620; 9496;...
Create a recursive function in pseudocode which takes as input an integer n , and returns the nth term of the
sequence.
Explanation / Answer
Answer:
//Pseudo code for n people that have telephone numbers:
Procedure telephone(n):
STEP 1: Start
2: If n=0 OR n=1 Then //base case to stop recursion
3: Return 1 //return 1
4: Else //general case
5: Return telephone(n-1)+telephone(n-1)*telephone(n-2) //call recursion
[End If]
6: Stop
//I executed this pseudo code but given example : 1; 1; 2; 4; 10; 26; 76; 232; 764; 2620; 9496;... is wrong
//Actual right sequence as per the formulat (n-1)+(n-1)*(n-2) is - 1;1;2;4;12;60;780;47580;