Docsity

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

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) ) ; }