Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSCI 3333 Data Structures Recursion Exercises

Similar presentations


Presentation on theme: "CSCI 3333 Data Structures Recursion Exercises"— Presentation transcript:

1 CSCI 3333 Data Structures Recursion Exercises
by Dr. Bun Yue Professor of Computer Science

2 Exercise 1 Write a recursive algorithm to count the number of negative integers in an integer array.

3 Exercise 2 A palindrome is a string that reads the same in both direction. E.g. racecar, eve, lol. Give a recursive algorithm to test whether a string is a palindrome.

4 Greatest Common Divisor
The GCD of two natural numbers are their greatest common factor: largest integer divisible. Examples: gcd(100, 25): 25 gcd(278, 64): 2 gcd(64,278): 2 gcd(33,178): 1 gcd(95,38): 19

5 Euclidean Algorithm A way of computing GCD by integer division and module. E.g. GCD(95,38). a1=95, b1=38 (a >= b) 95 = 2 * a2=38, b2=19 (a >= b) 38 = 2 * Since remainder = 0; GCD = 19

6 Exercise 3 Using similar steps, show how you obtain the GCD below:
Construct a recursive algorithm. Implement the algorithm in Java, C++ or other languages.

7 Questions and Comments?


Download ppt "CSCI 3333 Data Structures Recursion Exercises"

Similar presentations


Ads by Google