VOOZH about

URL: https://www.geeksforgeeks.org/dsa/program-count-vowels-string-iterative-recursive/

⇱ Program to count vowels in a string (Iterative and Recursive) - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Program to count vowels in a string (Iterative and Recursive)

Last Updated : 23 Jul, 2025

Given a string, count the total number of vowels (a, e, i, o, u) in it. There are two methods to count total number of vowels in a string. 

  1. Iterative 
  2. Recursive

Examples: 

Input : abc de
Output : 2

Input : geeksforgeeks portal
Output : 7
Recommended Practice

1. Iterative Method:

Below is the implementation: 


Output
2

Time Complexity: O(n), where n is the length of the string
Auxiliary Space: O(1) 

Recommended Practice

2. Recursive Method:

Below is the implementation: 


Output
2

Time Complexity: O(n), where n is the length of the string
Auxiliary Space: O(n), where n is the length of the string since the function is calling itself n times.

How Recursive Code Working.
 

👁 Image

Comment