1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Nata [24]
3 years ago
9

Write a recursive function is_pow2(n) that returns True if the positive integer n is an integer power of 2, and False otherwise.

For example: function call return value is_pow2(1) True is_pow2(2) True is_pow2(3) False is_pow2(4) True is_pow2(5) False is_pow2(6) False is_pow2(7) False is_pow2(8) True is_pow2(9) False is_pow2(255) False is_pow2(256) True Hint: Consider using repeated floor division.
Computers and Technology
1 answer:
bezimeni [28]3 years ago
8 0

Answer:

In Python:

def is_power(n):

   if n > 2:

       n = n/2

       return is_power(n)

   elif n == 2:

       return True

   else:

       return False

Explanation:

This defines the function

def is_power(n):

If n is greater than 0

   if n > 2:

Divide n by 2

       n = n/2

Call the function

       return is_power(n)

If n equals 2

   elif n == 2:

Return True

       return True

If n is less than 2

   else:

Then, return false

       return False

You might be interested in
) Suppose algorithm A takes 10 seconds to handle a data set of 1000 records. Suppose the algorithm A is of complexity O(n2). Ans
Mice21 [21]

Answer:

i) The time taken for 1500 records = 15 seconds.

ii) The time taken for 1500 records = 50 seconds.

Explanation:

A is an O(n) algorithm.

An algorithm with O(n) efficiency is described as a linearly increasing algorithm, this mean that the rate at which the input increases is linear to the time needed to compute that algorithm with n inputs.

From the question, it is given that for 1000 records, the time required is: 10 seconds.

Algorithm time taken is O(n)

Hence,

1) For 1,500 records

=> 10/1000 = x/1500

=> 10x1500/1000 = x

x = 15 seconds

Thus, the time taken for 1500 records = 15 seconds.

2) For 5,000 records

=> 10/1000 = x/5000

=> 10x5000/1000 = x

x = 50 seconds

Thus, the time taken for 1500 records = 50 seconds.

8 0
3 years ago
Help asap dont answer with a link​
dezoksy [38]

Answer:

90

Explanation:

dur nearly all my friends and family knows that

4 0
3 years ago
What is the process of attaching gage blocks to each other
const2013 [10]

The blocks are joined by a sliding process called wringing, which causes their ultra-flat surfaces to cling together.

7 0
3 years ago
You have been instructed to connect a computer to a group of hosts that have been segmented from the regular network. What kind
san4es73 [151]

Answer: VLAN(Virtual local area network)

Explanation: VLAN(Virtual local area network) is the networking device that displays the flexible nature due to the logical connection of one or more LANs. VLAN is used for the purpose of the management, security, scaling etc.

VLAN also has the ability to provide the segmentation in the network by dividing the physical network into segments and making logical network. Router is the source for maintaining the communication in the VLAN.

Thus according to the requirement mentioned in the question ,VLAN is the network device that should be used.

8 0
3 years ago
50 POINTS! What can be viewed in the Tasks folder? Check all that apply.
Rom4ik [11]

1, 2, and 4 :))) good luck

6 0
3 years ago
Read 2 more answers
Other questions:
  • Analyzing Uses for PDFs
    6·1 answer
  • Mobile computing has two major characteristics that differentiate it from other forms of computing. What are these two character
    8·1 answer
  • What do you do to add a line or circle to your presentation?
    7·2 answers
  • The Cursor is blinking in a white area on the Screen. This area where text will appear in the ____.
    10·2 answers
  • Which of the following barriers to oral communication is not the fault of the sender or receiver? being unprepared noise not pay
    12·2 answers
  • HIPAA requires the following controls for medical records: A. Encryption of all data B. Technical safeguards C. Physical control
    12·1 answer
  • Whenever Jim starts his laptop he sees some commands and numbers appearing on his screen these instructions are being processed
    9·1 answer
  • Which statistical measurement tools should be
    8·1 answer
  • Learning Task 2: Identify what is being asked. Write your answers on your notebook 1. What Microsoft Office program is used for
    15·1 answer
  • question 2 which data link layer protocol defines the process by which lan devices interface with upper network layer protocols?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!