Question

In: Computer Science

Give pseudocode for a recursive function that sorts all letters in a string. For example, the...

Give pseudocode for a recursive function that sorts all letters in a string. For example, the string "goodbye" would be sorted into "bdegooy".

Python

Solutions

Expert Solution

PSEUDO CODE TO REVERSE A STRING

//custom Method to reverse the String
   public static String newreversedString(String input)
   {   
   if ((input.length() <= 1)||(input==null) )
   return input;
  
   //Returning the reversed String
   return newreversedString(input.substring(1)) + input.charAt(0);
   }

COMPLETE JAVA CODE

package reverseString;

import java.util.Scanner;

public class Recursion {
   public static void main(String[] args)
   {
   System.out.print("Enter a string to reverse it by recursion: ");
   String input;
   Scanner scan = new Scanner(System.in);
  
   //Inputting the String to reverse
   input=scan.nextLine();
  
   //Calling the newreversedString() method and storing in
   //output variable
   String output= newreversedString(input);
  
   //Printing reversed String
   System.out.println("Reverse of input String \""+input+"\" is \""+output+"\"");
   }
     
   //Method to reverse the String
   public static String newreversedString(String input)
   {   
   if ((input.length() <= 1)||(input==null) )
   return input;
  
   //Returning the reversed String
   return newreversedString(input.substring(1)) + input.charAt(0);
   }

}

OUTPUT


Related Solutions

Give pseudocode for a recursive function that sorts all letters in a string. For example, the...
Give pseudocode for a recursive function that sorts all letters in a string. For example, the string "goodbye" would be sorted into "bdegooy". Java
Create program which sorts letters of a string based on ASCII value. The program will then...
Create program which sorts letters of a string based on ASCII value. The program will then print the sorted string to stdout. Use C programming language. - Only use stdio.h - Input prompt should say "Enter string of your choice: " - Remove any newline \n from input string - Implement sorting operation as a function. Should use selection sort algorithm, but you may use a different algorithm - Output should print sorted string on new line Example:     Enter...
Write pseudocode for a function that translates a telephone number with letters in it (such as...
Write pseudocode for a function that translates a telephone number with letters in it (such as 1-800-FLOWERS) into the actual phone number. Use the standard letters on a phone pad
Write in Racket Language Write a recursive Racket function "all-same" that takes a string as a...
Write in Racket Language Write a recursive Racket function "all-same" that takes a string as a parameter and evaluates to true iff every character in the string is the same. Note: A string of length 0 or 1 should also evaluate to true.
Write a short recursive C++ function that determines if a string s is a palindrome, that...
Write a short recursive C++ function that determines if a string s is a palindrome, that is, it is equal to its reverse. For example,"racecar" and "gohangasalamiimalasagnahog" are palindromes. Please include the pseudo code so that I can understand better with simple English as much as possible.
In Java, write a recursive function that accepts a string as its argument and prints the...
In Java, write a recursive function that accepts a string as its argument and prints the string in reverse order. Demonstrate the function in a driver program.
c++ using recursive no loops (for ,while ..ect)not allowed Write a recursive function ‘bool palindrome(string s)’...
c++ using recursive no loops (for ,while ..ect)not allowed Write a recursive function ‘bool palindrome(string s)’ that returns true if s is a palindrome and false if not. #5: Write a recursive function 'void reverse(string &word)' that reverses the given input string. string name = "damian"; reverse(name); cout << name << endl; //should display "naimad". #7: Write a function 'int numTwos(int n)' which returns the number of 2's in the base-4 expansion of n. cout << numTwos(2170) << endl; //...
Give a recursive algorithm to solve the following recursive function. f(0) = 0;    f(1) = 1;...
Give a recursive algorithm to solve the following recursive function. f(0) = 0;    f(1) = 1;   f(2) = 4; f(n) = 2 f(n-1) - f(n-2) + 2; n > 2 b) Solve f(n) as a function of n using the methodology used in class for Homogenous Equations. Must solve for the constants as well as the initial conditions are given.
Reversing certain segments of the alphabet, using a recursive function. (C++) 1. Obtain the following string:...
Reversing certain segments of the alphabet, using a recursive function. (C++) 1. Obtain the following string: abcdefghijklmnopqrstuvwxyz (as input or using initialization) 2. Using recursion, write a reverse function that reverses the characters in a string or character array given two indices (starting and ending). The string or the character array should reflect the reversal. 3. Read indices as input 11,18 (i.e. letters 12,19) 4. Call the reverse function to reverse letters: 12-19 5. Read indices as input 4,22 (i.e....
Write a recursive method to determine if a String is a palindrome. Create a String array...
Write a recursive method to determine if a String is a palindrome. Create a String array with several test cases and test your method. Write a recursive method to determine if a String is a palindrome. Create a String array with several test cases and test your method. In Java
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT