FOR FREE YEAR SOLVED

String Reverse

Back to Programming

Description

Here, the program is written to reverse the string. A string is a sequence of characters. The program takes a string input from the user and reverses it that means the characters of the main string are arranged in opposite or reverse order.

For example: 

If a given string is – “osmosis” then the reverse string will be- “sisomso”.

Code

TIME COMPLEXITY:

for(i=n-1;i>=0;i--)-----------------------------O(n)

                              s1[in++]=s[i];

The time complexity of this program is O(n) where n is the number of characters of the string.

SPACE COMPLEXITY:

The space complexity of this program is O(n) where n is the number of characters of the string.