The Handshake Problem - Recurrence Function in C - Computer Algorithms, Study Guides, Projects, Research of Algorithms and Programming

The Handshake problem's implementation as a recursive function in C language.

Typology: Study Guides, Projects, Research

2014/2015

Uploaded on 10/27/2015

hishamnajam
hishamnajam 🇵🇰

5

(1)

8 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
The Handshake Problem
At a party with npeople, everyone shakes hands once with everybody else.
Let H(n) be the total number of handshakes among the nguests. Write a
recurrence for H(n).
The Recursive Code for the Handshake Problem
#include < s t di o . h >
in t ha n ds h ak e (int n) ;
in t main( ) {
printf("%d \n",h an ds h ak e (2 5) ) ;
return 0;
}
ha n ds h ak e (n) {
if (n= = 0)
return 0;
else
return (( n-1 ) + h an d sh a ke (n- 1) ) ;
}
1

Partial preview of the text

Download The Handshake Problem - Recurrence Function in C - Computer Algorithms and more Study Guides, Projects, Research Algorithms and Programming in PDF only on Docsity!

The Handshake Problem

At a party with n people, everyone shakes hands once with everybody else.

Let H(n) be the total number of handshakes among the n guests. Write a

recurrence for H(n).

The Recursive Code for the Handshake Problem

include < stdio .h >

int handshake ( int n ) ;

int main () { printf ( " % d \ n " , handshake (25) ) ; return 0; }

handshake ( n ) { if ( n == 0) return 0; else return (( n -1) + handshake (n -1) ) ; }