Data Structure Questions and Answers-String Reversal using Recursion

 

 Help authour, Buy PDF Ebook   >>>Click Here<<<

Data Structure Questions and Answers-String Reversal using Recursion

Click on any option to know the CORRECT ANSWERS

Question 1
Consider the following iterative implementation used to reverse a string:

#include<stdio.h> #include<string.h> void reverse....string(char *s) { int len = strlen(s); int i, j; i=0; j=len-1; while(.....) { char tmp = s[i]; s[i] = s[j]; s[j] = tmp; i++; j--; } }

Which of the following lines should be inserted to complete the above code?

A
i > j
B
i < len
C
j > 0
D
i < j
Commerce Questions answers

Question 1 Explanation: 
The line "i < j" should be inserted to complete the above code.

Question 2
What is the output of the following code?

#include<stdio.h> #include<string.h> void reverse....string(char *s) { int len = strlen(s); int i, j; i=0; j=len-1; while(i < j) { char tmp = s[i]; s[i] = s[j]; s[j] = tmp; i++; j--; } } int main() { char s[100] = "reverse"; reverse....string(s); printf("%s", s); return 0; }
A
ersevre
B
esrever
C
eserver
D
eresevr
English literature Questions answers

Question 2 Explanation: 
The program reverses the string "reverse" and prints "esrever".

Question 3
What is the time complexity of the above code used to reverse a string?
A
O(1)
B
O(n)
C
O(n2)
D
O(n3)
Visual arts Questions answers

Question 3 Explanation: 
The time complexity of the above code used to reverse a string is O(n).

Question 4
What does the following code do?

#include<stdio.h> #include<string.h> void reverse....string(char *s) { int len = strlen(s); int i, j; i=0; j=len-1; while(i < j) { char tmp = s[i]; s[i] = s[j]; s[j] = tmp; i++; j--; } } int main() { char s[100] = "abcdefg"; char t[100]; strcpy(t, s); reverse....string(s); if(strcmp(t, s) == 0) printf("Yes"); else printf("No"); return 0; }
A
Copies a string to another string
B
Compares two strings
C
Reverses a string
D
Checks if a string is a palindrome
Arab culture Questions answers

Question 4 Explanation: 
The main purpose of the above code is to check if a string is a palindrome.

Question 5
What is the output of the following code?

#include<stdio.h> #include<string.h> void reverse....string(char *s) { int len = strlen(s); int i, j; i=0; j=len-1; while(i < j) { char tmp = s[i]; s[i] = s[j]; s[j] = tmp; i++; j--; } } int main() { char s[100] = "rotator"; char t[100]; strcpy(t, s); reverse....string(s); if(strcmp(t, s) == 0) printf("Yes"); else printf("No"); return 0; }
A
Yes
B
No
C
Runtime error
D
Compile time error
Library science Questions answers

Question 5 Explanation: 
The program checks if a string is a palindrome. Since the string rotator is a palindrome, it prints "yes".

There are 5 questions to complete.