Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134670942
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
How many numbers between 1 and 10000 have digits that sum to 15? For example, 69, 1275, and 7008 are all valid numbers. Again, leading zeroes do not add digits.
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)
Design 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.
Chapter 22 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th 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
- 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_forwardThe number of permutations of a set of n items taken r at a time is given by the following formulan!/r!(n−r)!: where n! is the factorial of n, r! is the factorial of r, and (n-r)! is the factorial of the result of n-r. The factorial of a number n can be solved using the following formula: n !=e−n nn √ 2 πn. If there are 18 people in your class and you want to divide the class into programming teams of 3 members, you can compute the number of different teams that can be arranged using this formula (n!/r!(n−r)!). When writing a C++ program that determines the number of potential team arrangements. You will need to use the double type for this computation.arrow_forwardPlease helparrow_forward
- Write 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_forwardWhich 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_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
- given 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_forwardOn the planet Tatooine, droids do computations in base-6. What is the greatest base-6 number with three different digits? (Your base-6 number must have a separate digit for each digit.) Make a decimal out of your answer (base-10).arrow_forwardThe following code implements Newton's algorithm for finding the square root of a number using repetition: n = 17 # we want the square root of 17 for exampleg = 4 # our guess is 4 initiallyerror = 0.0000000001 # we want to stop when we are this closewhile abs(n - (g**2)) > error: g = g - ((g**2 - n)/(2 * g))# g holds the square root of n at this point Implement this algorithm in a function sqRoot(n), that returns the square root using recursion. Assume that the function will be called with positive numbers only. Note: Your initial guess cannot be zero!arrow_forward
- The Fibonacci sequence is defined as follows: ϕ0=0, ϕ1=1, ϕn=ϕn−1+ϕn−2. ϕ0=0, ϕ1=1, ϕn=ϕn−1+ϕn−2. Given an integer a, determine its index among the Fibonacci numbers, that is, print the number n such that ϕn=a. If a is not a Fibonacci number, print -1 . WRITE THE CODE IN PYTHON PLEASEarrow_forwardCan you please help me I don’t understand how to solve this with the trading off algorithm, and also I did it once and my teacher said that I got it wrong so she said that I need to try to make 1 number end with 0, and not end with 5 because its easier to add the number that ends with 0 so we don’t need to worry about the carry over. Can you please help me understand what she meant and also help me solve this problem correctly like my teacher wanted it.arrow_forwardThe 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: 1. Compute the remainder of dividing the larger number by the smaller number. 2. Replace the larger number with the smaller number and the smaller number with the remainder. 3. 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_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