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 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.
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.
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
Write a recursive Racket function "remove-char" that takes two string parameters, s and c, and evaluates...
Write a recursive Racket function "remove-char" that takes two string parameters, s and c, and evaluates to string s with all occurrences of c removed. The string c is guaranteed to be a length-1 string; in other words a single character string. For example (remove-char "abc" "b") should evaluate to "ac". Here is pseudocode that you could implement.
Answer the following Discrete Structures Suppose string s = (s1 s2 ..sn). Give a recursive definition...
Answer the following Discrete Structures Suppose string s = (s1 s2 ..sn). Give a recursive definition of the function numOnes(n), which counts the number of 1s in bit-string of length n, Make sure to define the function for the base case, numOnes(0).
Code in Java Write a recursive method, reverseString, that accepts a String and returns the String...
Code in Java Write a recursive method, reverseString, that accepts a String and returns the String reversed. Write a recursive method, reverseArrayList, that accepts an ArrayList of Strings and returns the ArrayList in reserve order in reserve order of the input ArrayList. Write a main method that asks the user for a series of Strings, until the user enters “Done” and puts them in an ArrayList. Main should make use to reverseArrayList and reverseString to reverse each String in the...
Suppose that a “word” is any string of six letters. Repeated letters are allowed. For our...
Suppose that a “word” is any string of six letters. Repeated letters are allowed. For our purposes, vowels are the letters a, e, i, o, and u. a) How many words are there? b) How many words begin with a vowel? c) How many words begin with a vowel and end with a vowel? d) How many words have no vowels? e) How many words have exactly one vowel? A professor teaching a Discrete Math course gives a multiple choice...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT