Give a pseudo-code description of the O(n)-time algorithm for computing the power function p(x,n).Also draw the trace of computing p(3,3)using this algorithm?

Answers

Answer 1

Answer:

p(x,n)

1. if(n==0)    [if power is 0]

2.    then result =1.

3.else

4. {    result=1.

5.      for i=1 to n.

6.          {  result = result * x. }  [each time we multiply x once]

7.       return result.

8.  }

Let's count p(3,3)

3[tex]\neq[/tex]0, so come to else part.

i=1: result = result *3 = 3

i=2: result = result *3 = 9

i=2: result = result *3 = 27

Explanation:

here the for loop at step 4 takes O(n) time and other steps take constant time. So overall time complexity = O(n)


Related Questions

What is the minimum valid subscript value for array a?
#define MAX 50
int a[MAX], i, j, temp;
A. 0
B. 1
C. Any negative number
D. There is no minimum
E. None of the above

Answers

Answer:

The answer to this question is A. 0.

Explanation:

In this segment of code #define MAX 50 is used.It is a pre-processor directive and in pre processor directive it is a MACRO means whenever the compiler encounters the word MAX in the execution it replaces MAX with 50.

So the size of the array becomes 50 and the indexing starts from 0 and upto 49.

The true or false questions.

The command: find -empty -type f -exec rm { } \; will remove all empty regular files, starting from the current directory

Answers

Answer:

true

Explanation:

The command:

find -empty -type f -exec rm { } \;

carries out the following steps.

1) Finds all the empty files in the current directory and its subdirectories.

2) For each of the identified files, it executes the command specified as the parameter to exec option,namely, rm <filename>.

So effectively it removes all empty files in the directory tree starting at the current directory.  

An expression tag contains a scripting language expression thatis evaluated.TrueFalse

Answers

Answer: True

Explanation:

Yes, an expression tag contains a scripting language expression that is evaluated. As, expression tag is used to display the output of the data in the generated page. If data is placed in expression tag then, it prints on the output stream and then it automatically convert data into the string and the output are displayed.

The Task Manager can be used ot track running _________________ .

Answers

Answer:

Processes

Explanation:

The Windows Task Manager helps us track processes running on the system.

It can be invoked by pressing Ctrl+Alt+Delete and selecting the 'Task Manager' option or by right clicking on the status bar and choosing 'Task Manager' menu item. Besides the running process name it also provides supplementary information about the process such as :

CPUMemoryDiskNetwork

When a user process is running and an instruction is executed that requests a file-open operation, which of the following event will occur? (A) Supervisor call (B) Trap (C) I/O interrupt (D) Fault (E) None of the above

Answers

Answer:e

Explanation:

Because it will automatically work

The AND operator is written as two ____.

a.
asterisks

b.
equal signs

c.
ampersands

d.
plus signs

Answers

Answer:

ampersands

Explanation:

In the programming the AND operator is denoted as '&&' , two ampersands.

it is used to between two conditions and give Boolean result.

It has four possible result:

first condition TRUE  second TRUE, result TRUE

first condition TRUE  second FALSE, result FALSE

first condition FALSE second TRUE, result FALSE

first condition FALSE second FALSE , result FALSE

For example:

(5 > 0 && 7 > 4):   it gives the result TRUE because both are true.

5 > 8 && 7 > 4):   it gives the result FALSE because one is false.

The general case in a recursive function is the case for which the solution is obtained directly.

True

False

Answers

Answer: False.

Explanation:

The general case of recursive function is when the solution is obtained recursively by simplification at each step.

However, it is the base case in a recursive function when the solution is obtained directly.

The general case must be reducible to base to arrive at a solution else the recursion would be a infinite recursion.

What is the output frequency for a counter circuit that contains 12 flip-flops with an input clock frequency of 20.48 MHz?

Answers

Answer:

5KHz

Explanation:

The formula for calculating the output frequency when the input frequency and the number of flip-flops are given.

[tex]out put Frequency = \frac{in put frequency}{2^{N}}[/tex]

here, N is the number of filp-flops.

Note: The input frequency must be in Hz.

first convert given input frequency (MHz) into HZ.

[tex]in put frequency = 20.48 *10^{6}Hz[/tex]

apply the formula:

[tex]out put Frequency = \frac{20.48*10^{6}}{2^{12}}[/tex]

which comes out to be 5000Hz or 5KHz.

Which of the following is categorized as an indirect payment
portion of employee compensation?
a. Wages
b. Salaries
c. Employer-paid insurance
d. Commissions

Answers

Answer:    C. Employer-paid insurance

Explanation:  Employees can receive benefits i.e. financial payments in two ways, direct and indirect payments. Direct financial payments are all those paid directly by the employer to the employee, which means the employee can use those payments immediately after payment, such as wages, salaries, various bonuses, commissions, etc. Indirect benefits are all those paid by the employer to an employee from which the employee will benefit during or after a fixed period of time. These are, for example, life, health, so all kinds of insurance, paid holidays, pension funds, etc.

Differentiate Between register and Memory location (

Answers

Answer:

Register-it contains all the instructions that are present in the processor.

Memory location- it is the particular memory address where the data is stored.

Explanation: Difference between register and memory location are as follows :-

Register are the found in the CPU internal storage and memory location is present on the RAM.Registers are faster in movement as compared to the memory location.Register has the capacity of holding of less data as compared to the memory location which can store data in large amount .

A B-tree can be ____ in three ways: inorder, preorder, and postorder.

A.
copied

B.
reversed

C.
traversed

Answers

Answer:

traversed

Explanation:

B-tree is a self balancing tree and it is a data structure which allows insertion, deletion operations.

inorder, preorder and post order, they all are traversing algorithms in the tree data structure.

inorder: first print left, then root and then right.

preorder: first print root, then left and then right.

postorder: first print left, then right and then root.

Therefore, the answer is traversed.

What is ment by WCF services in asp.net?How does it help in creating web pages?

Answers

Answer:

WCF -  Windows Communication   Foundation

Explanation:

WCF stands for Windows Communication   Foundation.

The first version of WCF is released as   a part of .NET 3.0.The later versions are 4.0 and   4.5.

WCF is used to build distributed applications.   Distributed application is an application that where   parts of it run on two or more systems.  

For example,  

We have a web application running on one server. If   this web application is consuming a web server   which is running on another server, then this  

application is called distributed application.

The programmers can also build 3-tier web   application. The 3-tiers are,

          1. Presentation tier

          2. Business tier

          3. Data Access tier

If all 3 tiers are deployed on same machine,   scalability can be an issue, if more number of users   try to access the application.  

If we deploy each tier on different machines, then it   can handle multiple requests without degrading   performance of an application.

WCF is also used to build interoperable applications.  An interoperable application is an application where   one application can communicate with any other   application that is built on any platform.

So, the two advantages of using WCF are:

An enterprise application can use the services  

provided by other.  

we can have better scalability.  

Earlier, we used to have web services and .NET   Remoting to build distributed applications.  

Web service was used to exchange messages in   XML format using HTTP protocol. A .NET remoting was used to exchange messages   in binary format using TCP protocol.

Microsoft unified these communicating technologies   and named it as WCF.

A digital computer has a memory unit with 24 bits per word. The instruction set consists of 150 different operations. All instructions have an operation code part (opcode) and an address part (allowing for only one address). Each instruction is stored in one word of memory. How many bits are needed for the opcode?

Answers

Answer:

8 bit

Explanation:

we have given that the instruction consist 150 different operation

we know that [tex]2^{8}[/tex] = 256

but we have only 150 operation

so now we check [tex]2^{7}[/tex]=128

which is less than 150 so we need 8 bit for the opcode

so the 8 bit are needed for the opcode because when we take 7 bit then [tex]2^{7}[/tex]=128 which is less than 150 and not useful so we need 8 bit

write a program which capitalize every character after full stopin a given sentence

Answers

Answer:

#include <bits/stdc++.h>//header file which includes most of the libraries..

using namespace std;

int main() {

   char st[500];//character array of length 500..

   cin.getline(st,499);//taking input of the text.

   for(int i=0;st[i];i++)

   {

       if((st[i]=='.')&& (i!=strlen(st)-1))//condition

       {

          st[i+1]= toupper(st[i+1]);//converting to upper case.

       }

   }

   cout<<st<<endl;//printing the string..

return 0;

}

Input:

i am .the .great .gambler.i am going gamble everything

Output:

i am .The .Great .Gambler.I am going gamble everything

Explanation:

I have taken a character array of size 500.

Taking input as a line.

If full stop encounters then converting the character to uppercase if it exists.

Printing the output.

A five-digit number is entered through the keyboard. Write a program to obtain the reversed number

Answers

Answer:

 #include<iostream>

using namespace std;

int main(){

   int number;

   cout<<"Enter the five-digit number: ";

   cin>>number;

   int result = 0;

   while(number != 0){

       int remainder = number % 10;

       result = result*10 + remainder;

       number = number/10;

   }

   cout<<"The reverse Number is: "<<result<<endl;

   return 0;

}

Explanation:

first, include the library iostream for using the input/output.

Then, create the main function and declare the variables.

Print the message on the screen by using the instruction cout.

Store the value enter by the user in the variable by using cin instruction.

Take the while which runs until the number not equal to zero.

In the while, first, take the remainder of the number by using the operator '%'.

for example:

number = 123 % 10, it gives the value 3 which is the remainder.

after that, we write logic to reverse the number:

initially, remainder =3 and result=0

result = result * 10 + remainder

so, the result will be 3

after that, suppose remainder =2 and result=3 (previous calculated)

result = 3* 10 +2.

so, the result will be 32. so the number is reversed. we store the number in reverse order.

This process continues until the condition is true.

After that, print the output.

what are the elements of a Software Process Improvement (SPI) modle?

Answers

Answer: Current Situation Evaluation, Improvement Planning, Improvement Implementation, Improvement Evaluation are the elements of SPI

Explanation:

SPI modle plans to achieve a desired task of software development in terms of Current Situation Evaluation, Improvement Planning, Improvement Implementation, Improvement Evaluation, with each having a specified and detailed role to play in the software development.

What will be the value of input_value if the value 5 is input at run time?
cin >> input_value;
if (input_value > 5)
input_value = input_value + 5;
else if (input_value > 2)
input_value = input_value + 10;
else
input_value = input_value + 15;

Answers

Answer:

15

Explanation:

The if else state is used for checking the condition and if the condition is TRUE and program can execute the statement  within the if else.

Initially input_value is 5

then the if statement check the condition 5>5, condition FALSE because 5==5

it not less than 5.

then program move to else if and check condition 5>2, condition TRUE.

then, input_value = 5 + 10=15 execute and update the value to 15.

After that, program terminate the if else statement.

Therefore, the answer is 15.

The condition that is tested by a while loop must be enclosed in parentheses and terminated with a semicolon



True False

Answers

Answer:

False

Explanation:

while loop is used to execute the statement again and again until the condition is TRUE.

Syntax:

initialization;

while(condition)

{

   statement;

}

we write condition within the parentheses but without terminate with the  semicolon.

Therefore., the answer is False

What is the difference between a sequential access tile and a random access file?

Answers

Answer: Sequential access file enables the computer system to read or write file in sequential manner whereas random access file enables to read or write randomly in a data file.

Explanation:

Sequential file access is faster than random file access, however random access uses index searches. In random access higher number of seek operations are involved whereas in sequential access the number of seek operation is less.

The following JavaScript program is supposed to print: 1 by 4 by 9
on a single line by itself. Unfortunately the program contains at least eight mistakes. Write the corrected line beside the line in error.

var N; // Text
N := 1;
document.writeln( N );
document.writeln( “ by “);
document.writeln( “N + 3”);
document.writeln( “ by “ );
document.writeln( N + 5);

Answers

Answer:

var N; // Text

N = 1;

document.write( N );

document.write(" by ");

document.write(N + 3);

document.write(" by ");

document.write(N + 8);

Explanation:

var N; // Text

N = 1;

document.write( N );

document.write(" by ");

document.write(N + 3);

document.write(" by ");

document.write(N + 8);

a. Is there any functional difference between the class being instantiated in the following two ways? Balanced bal = new Balanced ("abc", "xyz"); Balanced bal = new Balanced ("cab", "zxy"); b. Is there any functional difference between the class being instantiated in the following two ways? Balanced bal = new Balanced ("abc", "xyz"); Balanced bal = new Balanced ("abc", "zxy"); c. Is there any functional difference between the class being instantiated in the following two ways? Balanced bal = new Balanced ("abc", "xyz"); Balanced bal = new Balanced ("xyz", "abc"); d. What type is pushed onto the stack? A char? An int? An integer? explain. e. Under which circumstances is the first opeation performed on the stack (not counting the new operation) the top operation? f. What happens if the string expression, that is passed to the test method, is an empty string?

Answers

Answer:

A,B,C -NO

D-Value type like int,char..

E.pop

D. it throws null exception

Explanation:

(A,B,C)There is no functional difference but  as the values passed to the parameterized constructor is different so you will get different outputs but functionality of the class didn't change  

(D) stack is a data structure which stores value types where as heap stores object types.In.stack actual value of the variable stored and heap address of the object stored

(E)the top operation on stack is always pop once we inserted the elements in a stack.if there are no elements in stack pop results null

(D) if the string we passed is null or empty to the test method it returns exception we need to handle that

The Windows 8 file management interface is called _____.

A. Windows Manager

B. File Browser

C. File Manager

D. File Explorer

Answers

Answer:

D. File Explorer

Hope that helps!

What would display if the following pseudocode was coded and executed? Declare String user = "Martha and George" Declare Integer number Set number = length(user) Display number

Answers

Answer:

 17

Explanation:

length() is the function which is used to find the number of character the string.

character include space as well.

initially declare the string user with input  "Martha and George".

then call length function which count the character within the double quotes""

total number is 17 (15 letters and 2 spaces).

and it then store in the integer.

finally print the value.

Therefore, the output is 17.

How do you write a computer program to convert a decimal number into binary, octal, and hexadecimal?

Answers

Answer:

#include <iostream>

using namespace std;

void hexadecimal(int dec)

{    

   char hexa[100];// character array to store hexadecimal number.

   int i = 0;

   while(dec!=0)

   {  

       int digit  = 0;

       digit = dec % 16;// storing remainder.

       if(digit < 10)//condition

       {

           hexa[i] = digit + 48;//storing digit according to ascii values.

           i++;

       }

       else

       {

           hexa[i] = digit + 55; //storing respective character according to ascii values..

           i++;

       }

       dec = dec/16;

   }

     cout<<"The corresponding Hexadecimal number is :- ";

   for(int j=i-1; j>=0; j--)// printing in reverse order .

       cout << hexa[j];

       cout<<endl;

}

void Binary(int dec)

{

   int bin[32];// integer array to store binary values.

   int i = 0;

   while (dec > 0) {

 

       bin[i] = dec % 2;// storing remainder

       dec = dec / 2;

       i++;

   }

 cout<<"The corresponding Binary number is :- ";

   for (int j = i - 1; j >= 0; j--) // printing in reverse order

       cout << bin[j];

       cout<<endl;

}

void Octal(int dec)

{

   int oct[100];// integer array to store octal values.

   int i = 0;

   while (dec != 0) {

       oct[i] = dec % 8;// storing remainder

       dec = dec / 8;

       i++;

   }

 cout<<"The corresponding Octal number is :- ";

   for (int j = i - 1; j >= 0; j--) // printing in reverse order

       cout << oct[j];

       cout<<endl;

}

int main() {

   int d,bin,oct,hex;

   cout<<"Enter decimal number"<<endl;

   cin>>d;//taking input.

   Binary(d);

   Octal(d);

   hexadecimal(d);

   return 0;

}

OUTPUT:-

Enter decimal number

10

The corresponding Binary number is :- 1010

The corresponding Octal number is :- 12

The corresponding Hexadecimal number is :- A

Enter decimal number

256

The corresponding Binary number is :- 100000000

The corresponding Octal number is :- 400

The corresponding Hexadecimal number is :- 100

Explanation:

I have built 3 function of type void Hexadecimal,Binary,Octal all the functions take decimal integer as argument.They print their respective number after conversion.

So main approach is that :-

1.Take an array to store the digit on dividing.

2.Find the remainder on dividing it by corresponding number (for ex:- if binary divide by 2).

3.Store each remainder in the array.

4.Divide the number until it becomes 0.

5.Print the array in reverse.

Assume that x is an integer variable. Which of the following represents the memory address where x is stored? E) None of the Above A) x B) &x C) *x D) 2**

Answers

Answer: (B) &x

Explanation:

Here whenever any variable is stored let it be integer, char, float it is always stored in a memory location assigned as '&'. Here the location where x is stored is denoted as '&x' which means memory address of x. *x means the pointer which is pointing to the memory address of x.

Imagine you want to clean up your database and decide to delete all records from the Review table that have an Id of 100 or less. What does your SQL statement look like?

Answers

Answer: The query to delete rows for the given scenario is  

DELETE

FROM Review

WHERE Id < 100 OR Id = 100;

Explanation:

In SQL, the table can be removed using either DROP, TRUNCATE or DELETE commands.

DROP command is used to delete the whole structure of the table. The general syntax is given below.

DROP TABLE table_name;

After this command, the whole structure of the specified table will be deleted. This table will have to be created again in order to use it and put data in this table.

SELECT *

FROM table_name;

This command when executed after the DROP command, will show an error.

This command can be used to drop database objects like constraints, index and the others.

The TRUNCATE command removes all the rows from a table. The structure of the table remains intact and data can be put again in this table.

This command only removes the data currently present in the table.

The general syntax is given below.

TRUNCATE TABLE table_name;

The command below will compile but it will not return any rows.

SELECT *

FROM table_name;

Alternatively, DELETE keyword is used to drop only the rows from a given table.

The general syntax for deleting rows from a table is given below.

DELETE

FROM table_name

WHERE [condition];

The WHERE clause is optional in a DELETE query.

SELECT *

FROM table_name;

The above command will compile and return rows if rows are present in the table other than the deleted rows.

The table used in the given query is Review table. We assume that Id is the primary key for the Review table. The query becomes

DELETE

FROM Review;

The condition for this deletion is that Id should be less than or equal to 100. The final query is written as

DELETE

FROM Review

WHERE Id < 100 OR Id = 100;

The class at the top of exception class hierarchy is ..........................
A) ArithmeticException
B) Throwable
C) Class
D) Exception

Answers

Answer:

B) Throwable

Explanation:

Great question, it is always good to ask away and get rid of any doubts that you may be having.

There are a wide range of classes on the exception class hierarchy. All the way on the top is the Objects Class but since that is not an available answer we will move on to the next one. The next one is the Throwable class. therefore that is the answer.

**Exception is after Throwable , and Arithmetic Exception is at the bottom.... everything is a class so that is not a part of the hierarchy **

I hope this answered your question. If you have any more questions feel free to ask away at Brainly.

What operator is used to create a validation rule? A. – B. / C. < or > D. +

Answers

Answer:

A

Explanation:BECAUSE

Relational operators, specifically < and >, are used to create validation rules that data must satisfy when being entered or modified. They set conditions such as requiring a quantity to be at least one, as in >=1.

The operator used to create a validation rule is C. < or > which are relational operators. These operators are essential in forming expressions that set the conditions data must meet to be considered valid. For instance, a typical validation rule in an Order Entry form might be that the quantity entered must be equal to or greater than one. In this case, the rule would be represented as >=1.

In database systems and programming, the proper use of relational operators, such as <, >, <=, and >=, is critical for ensuring accurate querying and data integrity. These operators allow for comparison between values, ensuring that the entered data fits within the specified parameters defined by the validation rules.

Develop a program so that the output will produce the following :
the circumference of the circle is 33.912
the area of the circle is 91.5624.

Answers

Answer:

 #include <iostream>

using namespace std;

int main()

{

  float radius = 5.4;

  float circumference = 2 * 3.14 * radius;

  float area = 3.14 * radius * radius;

 

  cout<<"the circumference of the circle is "<<circumference<<endl;

  cout<<"the area of the circle is "<<area<<endl;

  return 0;

}

Explanation:

Include the library iostream for using the input/output instructions.

create the main function and define the variable with value. Then,

use the formula to calculate the circumference and are of circle.

[tex]circumference = 2*\pi *radius[/tex]

[tex]area = \pi * radius^{2}[/tex]

here, choose [tex]\pi = 3.14[/tex]

after that, display the result.

Note: All variable define in float type.

Write a JAVA program to sort a given array of integers (1 Dimensional) in ascending order (from smallest to largest). You can either get the array as input or hardcode it inside your program.

Answers

Answer:

import java.util.Arrays;

public class sort{

    public static void main(String []args){

       int[] arr = {2,6,9,1,5,3};

       int n = arr.length;

       Arrays.sort(arr);

       for(int i=0;i<n;i++){

          System.out.println(arr[i]);

       }    

    }

}

Explanation:

first import the library Arrays for using inbuilt functions.

create the main function and define the array with elements.

then, use the inbuilt sort function in java which sort the array in ascending order.

syntax:

Arrays.sort(array_name);

then, use for loop for printing the each sorting element on the screen.

Other Questions
The diagram below shows a square inside a regular octagon. The apothem is of the octagon is 13.28 units. To the nearest square unit, what is the area of the shaded region? A rigid, sealed tank initially contains 2000 kg of water at 30 C and atmospheric pressure. Determine: a) the volume of the tank (m3 ). Later, a pump is used to extract 100 kg of water from the tank. The water remaining in the tank eventually reaches thermal equilibrium with the surroundings at 30 C). Determine: b) the final pressure (kPa). a walking path across a park is represented by the equation y=-2x-7. A new path will be built perpendicular to this path.The paths will intersect at the point (-2,-3).Identify the equation that represents the new path. Which element allowed Britain to become a great power during the 18th century? A. Its involvement in the Revolutionary War B. Its advancement in the technologies of industry C. Its large naval fleet D. Its vast number of citizens2b2t Question 2 of 10 The asteroid belt is located where ? A. northern Canada B. between the orbits of mars and Jupiter c. outside the orbit of Neptune Reset Selection Clay minerals are light silicates that form ________. from molten rock from chemical weathering of igneous rocks from pressure and heat. from mechanical weathering of any rock If in right triangle ABC with right angle C, sin A = 3/5 then what is the value of sin B? How does the relationship between flying dragons and trees compare to that of iguanas and trees?A) Flying dragons rely on trees for a food source, but not for shelter while iguanas rely on trees for both food and shelter.B) Flying dragons live exclusively in trees except to lay eggs, while iguanas will venture to the ground more frequently.C) Flying dragons use trees for shelter, but not for food, while iguanas rely on trees for food but not for shelter.D) Flying dragons and iguanas have an identical relationship with trees. The governor has proposed to clean up all the trash on the side of the highway. The project is estimated to cost the tax payers and additional$15,000. The city will benefit by having a clean highway which will entice tourists to stop along their routes. The project is estimated to bring in$12,000 of revenue from the highway being cleaned. Should the governor continue with the project?A. Yes, the project will have $12,000 of benefits to the city folks.B. No, the project will not bring in enough benefit to cover the costs.C. Yes, the tax payers wanted the highway cleaned up.D. No, the benefit from the project will only be $3000. Consider three identical items in parallel. What is the system reliability if each item has a reliability of 98%? What is the equilibrium potential for Na? a. 60 mv b. +60 mv c. -90 mv d. 90 mv A little help on this math problem? I really need help with number 55 An early submersible craft for deep-sea exploration was raised and lowered by a cable from a ship. When the craft was stationary, the tension in the cable was 7000 N {\rm N}. When the craft was lowered or raised at a steady rate, the motion through the water added an 1800 N {\rm N} drag force.Part AWhat was the tension in the cable when the craft was being lowered to the seafloor?Express your answer to two significant figures and include the appropriate units.Part BWhat was the tension in the cable when the craft was being raised from the seafloor?Express your answer to two significant figures and include the appropriate units. From Abraham's Lincoln's life which would be an example from the old economy when compared to the newly transformed market economy? As a result of cold environmental temperatures. T3/T4 production _______:a. remains unchanged b. increases c. decreases Determine if checking 100 applicants to see if they were admitted to Park University is a binomial experiment or not. Explain Quadrilateral UVWX is reflected over the x-axis to form quadrilateral UVWX. If vertex U is located at (-4, 5) and vertex V is located at (-6, 2), then vertex U is located at blank and vertex V is located at blank ?Read this line from the passage:Mrs. De Ropp was the ground plan on which he based anddetested all respectability.What does this sentence reveal about Mrs. De Ropp?She is respectable.She is pretentious.She is well-meaning.She is not respectable. The exchange rate is the: