Write a recursive method in **pseudocode** that returns the number of 1’s in the binary representation of N. Use the fact that this equal to the number of 1’s in the representation of N/2, plus 1, if N is odd
java pseudocode is best
JAVA CODE
import java.util.*;
public class Main
{
public static int rec(int n)
{
if(n==0)
return 0;
else if(n==1)
return 1;
else if(n%2==1)
return rec(n/2)+1;
else
return rec(n/2);
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
System.out.println(rec(n));
}
}
EXPLANATION
Hope this helps
please comment if you need further clarification
Write a recursive method in **pseudocode** that returns the number of 1’s in the binary representation...
1.3 Write a function to output an arbitrary double number (which might be negative using only printDigit for VO Write a recursive function that returns the number of 1 in the binary representation 1 in the representation of N/2 plus 1, if N is odd
MUST BE IN JAVA AND USE RECURSION Write a recursive method that returns the number of all occurrences of a given word in all the files under a directory. Write a test program. Use the following header: public static long findInFile(File file, String word)
In this assignment, you will write a Java program(s) to print the binary representation of a positive integer inserted from command line. You must finish your assignment in 2 different ways: Using a recursive method Using an iterative method Your main method must be: public static void main(String[] args) { int input; input = Integer.parseInt(args[0]); print_recursion(input); print_binary(input); } You must implement a class and test your program by different input values, including 0. Comment your program properly Example of test...
(Recursive Binary Search) Write a recursive method recursiveBinarySearch to perform a binary search of an array. The method should receive the search key, starting index and ending index as arguments. If the search key is found, return its index in the array. If the search key is not found, return –1. (NOTE: Complete the recursiveBinarySearch method in the BinaryArray class). java
2) Write a recursive procedure in pseudocode to implement the binary search algorithm. 3) Explain, how the binary search algorithm can be modified, or used, to insert, a new integer element x, into a sorted list of n intgers.
A. Write a recursive method that returns the sum of n to 1. B. Declare two attributes of a Node<E> object C. Give a line of code to create a node object that can create a double. JAVA
Write a java recursive method digitMatch that takes two nonnegative integers as parameters and that returns the number of digits that match between them. Two digits match if they are equal and have the same relative position starting from the end of the number (i.e., starting with the ones digit). In other words, the method should compare the last digits of each number, the second-to-last digits of each number, the third-to-last digits of each number, and so forth, counting how...
Write a recursive function that compares two given binary trees. It returns 1 if the two trees are different, and it returns 0 otherwise. The function signature is: int treeDiff (node "a, node *b); Write a recursive function that counts how many nodes in a tree have a single child. The function signature is: int countoneChild(node "root);
Write a recursive function that returns the minimum key value in a binary search tree of distinct (positive) integers. Return -1 in case the tree is empty. (b) Write a recursive function that returns the predecessor of the key value k in a binary search tree of distinct (positive) integers. This is the key value that precedes k in an inorder traversal of the tree. If k does not exist, or if k has no predecessor, your function should return...
java 2. Write a recursive method to return the number of occurrences a character c in a string s. c and s should be parameters.