Introduction to Java Programming and Data Structures: Brief Version (11th Global Edition)
11th Edition
ISBN: 9780134671710
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 22.3, Problem 22.3.2CP
How many stars are displayed in the following code if n is 10? How many if n is 20? Use the Big O notation to estimate the time complexity.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Suppose n is a positive integer.
What does the set of irrational numbers consist of? Give an example of an irrational number.
Correct answer will be upvoted else downvoted.
number is called 2050-number if it is 2050, 20500, ..., (2050⋅10k for integer k≥0).
Given a number n, you are asked to represent n as the sum of some (not necessarily distinct) 2050-numbers. Compute the minimum number of 2050-numbers required for that.
Input
The first line contains a single integer T (1≤T≤1000) denoting the number of test cases.
The only line of each test case contains a single integer n (1≤n≤1018) denoting the number to be represented.
Output
For each test case, output the minimum number of 2050-numbers in one line.
If n cannot be represented as the sum of 2050-numbers, output −1 instead.
Chapter 22 Solutions
Introduction to Java Programming and Data Structures: Brief Version (11th Global Edition)
Ch. 22.2 - Prob. 22.2.1CPCh. 22.2 - What is the order of each of the following...Ch. 22.3 - Count the number of iterations in the following...Ch. 22.3 - How many stars are displayed in the following code...Ch. 22.3 - Prob. 22.3.3CPCh. 22.3 - Prob. 22.3.4CPCh. 22.3 - Example 7 in Section 22.3 assumes n = 2k. Revise...Ch. 22.4 - Prob. 22.4.1CPCh. 22.4 - Prob. 22.4.2CPCh. 22.4 - Prob. 22.4.3CP
Ch. 22.4 - Prob. 22.4.4CPCh. 22.4 - Prob. 22.4.5CPCh. 22.4 - Prob. 22.4.6CPCh. 22.5 - Prob. 22.5.1CPCh. 22.5 - Why is the recursive Fibonacci algorithm...Ch. 22.6 - Prob. 22.6.1CPCh. 22.7 - Prob. 22.7.1CPCh. 22.7 - Prob. 22.7.2CPCh. 22.8 - Prob. 22.8.1CPCh. 22.8 - What is the difference between divide-and-conquer...Ch. 22.8 - Prob. 22.8.3CPCh. 22.9 - Prob. 22.9.1CPCh. 22.9 - Prob. 22.9.2CPCh. 22.10 - Prob. 22.10.1CPCh. 22.10 - Prob. 22.10.2CPCh. 22.10 - Prob. 22.10.3CPCh. 22 - Program to display maximum consecutive...Ch. 22 - (Maximum increasingly ordered subsequence) Write a...Ch. 22 - (Pattern matching) Write an 0(n) time program that...Ch. 22 - (Pattern matching) Write a program that prompts...Ch. 22 - (Same-number subsequence) Write an O(n) time...Ch. 22 - (Execution time for GCD) Write a program that...Ch. 22 - (Geometry: gift-wrapping algorithm for finding a...Ch. 22 - (Geometry: Grahams algorithm for finding a convex...Ch. 22 - Prob. 22.13PECh. 22 - (Execution time for prime numbers) Write a program...Ch. 22 - (Geometry: noncrossed polygon) Write a program...Ch. 22 - (Linear search animation) Write a program that...Ch. 22 - (Binary search animation) Write a program that...Ch. 22 - (Find the smallest number) Write a method that...Ch. 22 - (Game: Sudoku) Revise Programming Exercise 22.21...Ch. 22 - (Bin packing with smallest object first) The bin...Ch. 22 - Prob. 22.27PE
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Show a snippet of PHP code for creating a recordset. Explain the meaning of the code.
Database Concepts (8th Edition)
How does a command line interface work?
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
A file that contains a Flash animation uses the __________ file extension. a. .class b. .swf c. .mp3 d. .flash
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
What Java data types correspond with the following SQL types? INTEGER INT REAL CHAR CHARACTER VARCHAR DOUBLE
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Why might doctors and nutritionists be interested in a device like DietSensor?
Using MIS (10th Edition)
Compute the weakest precondition for each of the following assignment statements and postconditions: a. a = 2 ...
Concepts Of Programming Languages
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- For each number n from 1 to 4, compute n2 mod 5. Then for each n, compute n3 mod 5 and finally n4 mod 5. Do you notice anything surprising? (You may need to go past n = 4 to see a pattern)arrow_forwardDesign an algorithm to find the kth number such that the only prime factors are 3, 5, and 7. Note that 3, 5, and 7 do not have to be factors, but it should not have any other prime factors. For example, the first several multiples would be (in order) 1, 3, 5, 7, 9, 15, 21.arrow_forwardCalculate the number of ways to get from A to B moving right and down only.arrow_forward
- The greatest common divisor of two positive integers, A and B, is the largest number that can be evenly divided into both of them. Euclid’s algorithm can be used to find the greatest common divisor (GCD) of two positive integers. You can use this algorithm in the following manner: Compute the remainder of dividing the larger number by the smaller number. Replace the larger number with the smaller number and the smaller number with the remainder. Repeat this process until the smaller number is zero. The larger number at this point is the GCD of A and B. Write a program that lets the user enter two integers and then prints each step in the process of using the Euclidean algorithm to find their GCD. An example of the program input and output is shown below: Enter the smaller number: 5 Enter the larger number: 15 The greatest common divisor is 5arrow_forwardExercise: Find the function s(n) that indicates the number of sums performed by the following segment of an algorithm: for i = 2 to n+1 do for j = 1 to i+2 do p = p + n +jarrow_forwardFor example, multiply 100110 by 1011: 100110 x 1011 100110 (10011011) 100110 (10011012) 000000 (10011004, but we skip this step in the algorithm) (10011018) 100110 110100010 This algorithm requires log b additions (the number of bits in b). This is the algorithm you will implement in your program. First your program will prompt the user and read the numbers a and b to be multiplied. Remember that a and b are converted to 2's complement when you read them. Your program will multiply the numbers as shown above, by adding shifted versions of a. For each digit of b you will need to determine whether it is 0 or 1, because (as shown above) if a digit is O then nothing is added for that digit. To simplify, you can assume that both a and b are positive.arrow_forward
- You are asked to sort n English words alphabetically. What is the best achievable complexity? (Note: we are talking about actual English words that can be found in a Marriam-Webster dictionary.) Describe the algorithm that achieves the best complexity.arrow_forwardWrite an algorithm to count how many integers from 1 to n (where n is inputted by the user) are not perfect squares, perfect cubes, or perfect fifth powers.arrow_forwardgiven k positive integer, if k is even we divide it by 2, if odd we multiply it by 3 and add 1. and we reach 1 eventually. and it stops after 1000 iterations. below is the code to this algorithm, find the errors from the pseudocode and correct them.arrow_forward
- Which one of the following is NOT true? Because time is so complicated, it needs more CPU cycles. The complexity of space makes it easier to remember. Time complexity is measured by the number of operations. The worst case for an algorithm is when it needs to do the most work.arrow_forwardWrite the python code for the given pattern Given ‘n’, the number of rows, design an algorithm and write a Python code to draw a pattern. If n is ‘5’, the pattern looks as shown below: ** **** ****** ******** **********arrow_forwardUsing the digits 1, 2, 3, 5, 6, 7, 8 and 9, how many three-digit numbers can be made. three-digit numbers can be made without repeating digits. five-digit numbers can be made. five-digit numbers can be made without repeating digits.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Computational Software for Intelligent System Design; Author: Cadence Design Systems;https://www.youtube.com/watch?v=dLXZ6bM--j0;License: Standard Youtube License