Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The following is a recursive program. Assume that it only takes the positive integers as the input: int compute( int x, int n) { if(n==

The following is a recursive program. Assume that it only takes the positive integers as the input:

int compute(int x, int n) {

if(n==0) return 1;

else

if(n is even) return (compute(x, n/2) * compute(x, n/2));

else return (x * compute(x, n-1);

}

Can you tell what the above program really does?

  1. It always returns 1.
  2. It returns the value x.
  3. It returns the value xn.
  4. It returns the value x2.

Which one of the following statements gives us a correct inductive definition of a palindrome?

  1. A palindrome is a string that reads the same left to right as right to left.
  2. A palindrome is a string whose left half is a mirror image of its right half.
  3. A single character is a palindrome and if a string s is a palindrome, then xsx is also a palindrome.
  4. Both single character and an empty string are a palindrome. If a string s is a palindrome, then xsx is also a palindrome.

Which of the following pseudo code returns the length of a given list?

a) length(L) {

if(L has a single number x) return x;

else return (head(L) + length(tail(L)));

}

b) length(L) {

if(L has a single number x) return 1;

else return (1 + length(tail(L)));

}

c) length(L) {

if(L is an empty list) return 0;

else return (length(tail(L)) + 1);

}

d) length(L) {

if(L is an empty list) return 0;

else return (head(L) + length(tail(L)));

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Management Systems Designing And Building Business Applications

Authors: Gerald V. Post

1st Edition

0072898933, 978-0072898934

More Books

Students also viewed these Databases questions

Question

18. Explain the difference between translation and interpretation.

Answered: 1 week ago

Question

DEFINE HRIS and describe its main components.

Answered: 1 week ago

Question

Answered: 1 week ago

Answered: 1 week ago