C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN: 9781337102087
Author: D. S. Malik
Publisher: Cengage Learning
expand_more
expand_more
format_list_bulleted
Question
error_outline
This textbook solution is under construction.
Students have asked these similar questions
Here is my question that my professor gave to me as a homework from my algorithm's class.
Use asymptotic notations to describe the running times of the nested loops below. You may assume that n is a power of 2.
i =1
while i <= n
j =i
while j >= 1
<body of the inner while loop> // Needs Θ(1) time.
j =j / 2
i= i * 2
Write a program that makes an X using loops. The X should look like this
*-----*
-*---*-
--*-*--
---*---
--*-*--
-*---*-
*-----*
What is the output for the following pseudocode segment? For your answer list all outputs (not just the final values of s, t, and u). Is Y output, how many times? If Z output, how many times?
s = 1
t = 6
u = 8
while s < t
s = s + 1
output “Y”
while s < u
output “Z”
u = u – 1
endwhile
endwhile
output s, t, u
Knowledge Booster
Similar questions
- Here is my question that my professor gave to me as a homework from my algorithm's class. Use asymptotic notations to describe the running times of the nested loops below. You may assume that n is a power of 2.arrow_forwardWrite a Java program that uses the nested-while loops to produce the following output: 1 2 3 4 5 (diagonal)arrow_forwardSimplistic Algorithms with a Fixed Number of Integers (with C++) Write a program that takes three integers and outputs them in reverse order of how they were entered. For example, if the user enters 39, 51, 16 then the program should output 16, 51, 39.arrow_forward
- Exercise H for the Nested Loop Nested Loop Problems Write the program that would generate the multiplication table for numbers 1 to 10. For example: Result 1 2 3 4 5 6 7 8 9 10 2 4 6 8 10 12 14 16 18 20 3 6 9 12 15 18 21 24 27 30 4 8 12 16 20 24 28 32 36 40 5 10 15 20 25 30 35 40 45 50 6 12 18 24 30 36 42 48 54 60 7 14 21 28 35 42 49 56 63 70 8 16 24 32 40 48 56 64 72 80 9 18 27 36 45 54 63 72 81 90 10 20 30 40 50 60 70 80 90100arrow_forwardWrite a program that reads in five integers using loops and then determines and printsthe largest and smallest integers in the group. Use only the techniques you have learnt so far, andmake sure that the program only uses three variables. (Hint: use two of the variables to hold thecurrent largest and smallest integers.)arrow_forwardThe time complexity for the loop with elementary operations: Assuming these operations take unit time for execution. This unit time can be denoted by O(1). If the loop runs for N times without any comparison. Below is the illustration for the same: // C++ program to illustrate time // complexity for single for-loop #include <bits/stdc++.h> using namespace std; // Driver Code int main() { int a = 0, b = 0; int N = 4, M = 4; // This loop runs for N time for (int i = 0; i < N; i++) { a = a + 10; } // This loop runs for M time for (int i = 0; i < M; i++) { b = b + 40; } cout << a << ' ' << b; return 0; } Create an ipo, then analyze it until you get a big O1. Determine the problem to be solved with a particular algorithm2. Develop algorithms (in the algorithm there must be at least 1 iteration operation, 1 selection operation and several assignment operations)3. Algorithm analysis4. Determine the…arrow_forward
- Suppose I have 50 strings. At every step, I randomly pick 2 ends of strings(they could be the ends of the same string) and tie them together. At each step, I couldmake either a longer string or a loop.a) What is the expected number of steps it takes me to turn all the strings into loops?b) What is the expected number of loops? (Express this as a sum)arrow_forwardModify the given program to use a loop to output an arrow base of width arrowBaseWidth. Use a nested loop in which the inner loop draws the *’s, and the outer loop iterates a number of times equal to the height of the arrow base.arrow_forwardWhat is the output for the following pseudocode segment? For your answer list all outputs (notjust the final values of s, t, and u). Is Y output, how many times? If Z output, how many times?s = 1t = 4u = 6while s < ts = s + 1output “Y”while s < uoutput “Z”u = u – 1endwhileendwhileoutput s, t, uarrow_forward
- Please use java Using two nested loops, initialize the board so that zeros and ones’ alternate, as on a checkerboard:0 1 0 1 0 1 0 11 0 1 0 1 0 1 00 1 0 1 0 1 0 11 0 1 0 1 0 1 00 1 0 1 0 1 0 1…1 0 1 0 1 0 1 0Hint: check whether i + j is evenarrow_forwardThis assignment does not exactly match the one in the textbook on which it is based. I don't want any counter-controlled loops in your solution. Your solution should be able to detect when the accuracy isn't improving and then display the results of the work (as outlined below): Look at Programming Exercise **5.25 in the textbook on approximating the value of π. It is described as: π = 4 ( 1 - 1/3 + 1/5 - 1/7 + 1/9 - 1/11 + ... + (-1)^(i+1)/(2i-1) ) Notice that Java has the best possible value of π that can be stored as a type double available as Math.PI (part of the java.lang package). See how close you can get to the best value of π using a loop with the above technique. Notice that the above implies you are testing the value of your own estimate as it approaches the best value available in Java (as a type double). This would not be a pre-determined, counter-controlled loop. You are testing the results (sentinel-controlled) until you reach a value with the minimum discrepancy…arrow_forwardWrite this using java Write a complete version of the Bresenham Midpoint algorithm to handle ALL slope values. m = 0 m > 0 m < 0 m = 1 m > 1 swap the rolls of x and y m < 1 m = infinity ( needs special test case) Include appropriate tests for ‘special case’ conditions. Insteadof “WritePixel” write to the screen the coordinates of the pixel that would be drawn.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning