Skip to content

SwiftTuition/CP143-Recursion-and-Advanced-Functions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CP143: Recursion and Advanced Function Concepts

Good day, good people! Welcome to the Recursion practice exercises for CP143.

📚 Module Information

Course: CP143 - Computer Programming Institution: Stellenbosch University Topic: Recursion and Advanced Function Concepts Lecture Coverage: Lecture 12 Textbook: Chapter 5 (sections 5.13-5.16) Learning Outcomes: LO2 (Design efficient algorithms), LO5 (Control structures - recursion)

🎯 Learning Objectives

By completing these exercises, you will:

  • Understand recursive problem solving (base case + recursive step)
  • Implement classic recursive algorithms
  • Trace recursive execution and call stacks
  • Compare recursive vs iterative solutions
  • Apply recursion to strings, arrays, and mathematical problems

Overview

This repository contains 5 practice exercises designed to help you master recursion in C. Each exercise focuses on different aspects of recursive thinking and implementation.

📋 Exercises

Exercise 1: Recursive Sum and Product (⭐ Easy)

File: Exercise_01/exercise_1.c

Write recursive functions to calculate sum and product of numbers 1 to n

Exercise 2: Palindrome Checker (⭐ Easy)

File: Exercise_02/exercise_2.c

Check if a string is a palindrome using recursion

Exercise 3: Recursive Array Search (⭐⭐ Medium)

File: Exercise_03/exercise_3.c

Implement linear search recursively

Exercise 4: GCD - Euclidean Algorithm (⭐⭐ Medium)

File: Exercise_04/exercise_4.c

Find greatest common divisor using the Euclidean algorithm

Exercise 5: Binary to Decimal Conversion (⭐⭐⭐ Hard)

File: Exercise_05/exercise_5.c

Convert binary strings to decimal numbers recursively

🚀 Getting Started

Option 1: GitHub Codespaces (Recommended)

Click the button below to open this repository in a fully configured cloud development environment:

Open in GitHub Codespaces

Why Codespaces?

  • ✅ No setup required - works in your browser
  • ✅ Pre-configured C compiler and debugger
  • ✅ Consistent environment across all devices
  • ✅ Free tier available (60 hours/month)
  • ✅ Access from anywhere with internet

Option 2: Local Development

Clone the repository:

git clone https://github.com/SwiftTuition/CP143-Recursion-and-Advanced-Functions.git
cd CP143-Recursion-and-Advanced-Functions

💻 How to Compile

Each exercise can be compiled using GCC:

gcc exercise_1.c -o exercise_1
gcc exercise_2.c -o exercise_2
gcc exercise_3.c -o exercise_3
gcc exercise_4.c -o exercise_4
gcc exercise_5.c -o exercise_5

Or if you're in an exercise folder:

cd Exercise_01
gcc exercise_1.c -o exercise_1

How to Run

After compiling, run the executable:

./exercise_1
./exercise_2
./exercise_3
./exercise_4
./exercise_5

On Windows:

exercise_1.exe
exercise_2.exe
exercise_3.exe
exercise_4.exe
exercise_5.exe

Tips for Success

  1. Identify the Base Case: Every recursive function needs a terminating condition
  2. Define the Recursive Step: How does the problem get smaller with each call?
  3. Trust the Recursion: Assume the recursive call works for smaller inputs
  4. Trace Your Code: Use pencil and paper to trace through recursive calls
  5. Test Edge Cases: Try n=0, n=1, empty strings, etc.

Common Mistakes to Avoid

  • Forgetting the base case (causes infinite recursion and stack overflow)
  • Incorrect base case (function never terminates)
  • Not making progress toward the base case
  • Modifying parameters incorrectly
  • Stack overflow from too many recursive calls

Getting Help

If you're stuck:

  1. Read the problem description carefully in each exercise's README.md
  2. Review the theory and examples from the learning package
  3. Trace through the recursion with small inputs (n=1, n=2, n=3)
  4. Check that your base case is correct
  5. Verify that each recursive call makes progress toward the base case

Good luck!


Swift Tuition CP143 Learning Package

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages