Python Programming: An Introduction to Computer Science, 3rd Ed.
3rd Edition
ISBN: 9781590282755
Author: John Zelle
Publisher: Franklin, Beedle & Associates
expand_more
expand_more
format_list_bulleted
Expert Solution & Answer
Chapter 13, Problem 1D
Explanation of Solution
- The order of algorithm from fastest to slowest is
log n, n, n log n, n2, 2n
- “log n” is less than n because “log (100) = 2” and 2 is less than 100. Hence growth of n is faster than log n.
- “n” is less than “n log n” because 100 is less than “100 * log (100) = 200”...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Place these algorithm classes in order from fastest to slowest: n log n, n,n2, log n, 2n.
Design a type of sieve algorithm that would (1) Create a list of consecutive integers from 1 to n. (2) Initially, let k=2. (3) Consider each of the multiples of k less than or equal to n and either place or remove a mark on it as follows:
- If you encounter an unmarked multiple, mark it with a zero.
- If you encounter a multiple that has already been marked, remove the mark by restoring to its original value.
(4) Increase k by one. (5) Repeat steps (3) and (4) as long as k <= n.
Algorithm Prime2 (n: integer):{T,F};
prime = F;
d=2;
while d < n/2 and prime = F do
if n mod d = 0 then prime = T
else d = d+1
return prime;
How many times is the operation "n mod d" performed, when the input for Algorithm Prime 2 is n=123?
Group of answer choices
1
4
3
2
None of these.
Chapter 13 Solutions
Python Programming: An Introduction to Computer Science, 3rd Ed.
Ch. 13 - Prob. 1TFCh. 13 - Prob. 2TFCh. 13 - Prob. 3TFCh. 13 - Prob. 4TFCh. 13 - Prob. 5TFCh. 13 - Prob. 6TFCh. 13 - Prob. 7TFCh. 13 - Prob. 8TFCh. 13 - Prob. 9TFCh. 13 - Prob. 10TF
Ch. 13 - Prob. 1MCCh. 13 - Prob. 2MCCh. 13 - Prob. 3MCCh. 13 - Prob. 4MCCh. 13 - Prob. 5MCCh. 13 - Prob. 6MCCh. 13 - Prob. 7MCCh. 13 - Prob. 8MCCh. 13 - Prob. 9MCCh. 13 - Prob. 10MCCh. 13 - Prob. 1DCh. 13 - Prob. 2DCh. 13 - Prob. 3DCh. 13 - Prob. 4DCh. 13 - Prob. 5DCh. 13 - Prob. 1PECh. 13 - Prob. 2PECh. 13 - Prob. 3PECh. 13 - Prob. 4PECh. 13 - Prob. 5PECh. 13 - Prob. 6PECh. 13 - Prob. 7PE
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
- def function(n): while n>0: n=(n/2) can n be ever equal to 0? What is the time complexity of this function? What if it's n=(n/2) + 1arrow_forwardLet A be an algorithm which has an execution time O (N5), where N is the size of the entry. Which of the following statements is NOT true about Algorithm A? Question 3 options: For any N, there may be entries for which the execution time is greater than N4 seconds. For any N, there may be entries for which the execution time is greater than N6 seconds. For any N, there may be entries for which the execution time is less than N4 seconds. For any N, there may be entries for which the execution time is less than N6 seconds. There are constants A and B such that for all N the execution time is less than A × N5 + B seconds.arrow_forward1.Consider the pseudocode below. Algorithm Total(n) total = 5 for i = 1 to n + 1 for j = i to n for k = 1 to 3 total= total+ i ∗ j ∗ k end for end for end for return total What is the asymptotic class of the above algorithm as a function of n? Prove your assertions! 2. Consider the pseudocode below. Algorithm Total(n) total = 1 for i = 1 to n j = 0 while j < i total = 3 + total end while end for return total What is the asymptotic class of the above algorithm? O(1) O(n) O(n log n) O(n2) None of the above. Which of the following is a negation of the statement: A ∨ B′ ? A’ ∧ B A’ ∨ B A ∧ B′ A → B′ None of the above.arrow_forward
- 1- Suppose a genetic algorithm uses chromosomes of the form X = abcdefgh with a fixed length of eight genes. Each gene can be any digit between 0 and 9. Let the fitness of individual X be calculated as: f(X) = (a + b)−(c+d) + (e+f) - (g+h) Let the initial population consist of 6 following chromosomes: X1 65413532 X2=87126601 X3 239 21285 X4=41852094 X5 83931775 X6=52769863 Evaluate the fitness of each individual (show all stages). Then select 4 of them for next generation and write chromosomes which are selected. (Consider maximization.) I. II. III. Perform the following crossover operation on the initial population: Do crossover on X2 and X6 (parents) and name offspring as X7 and X8. Consider one-point crossover and the crossover point between "c" and "d". Write chromosomes X7 and X8. Evaluate offspring generated by crossover operation above (Chromosomes X7 and X8). Do their fitness are better than their parents?arrow_forwardDevelop Pseudo-code (English-like) for: In the Find Largest pseudo-code algorithm of Figure 2.14, listed below, if the numbers in our list were not unique and therefore the largest number could occur more than once. Modify the algorithm below to find all the occurrences of the largest number and their position in the list.arrow_forwardA certain computer algorithm executes twice as many operations when it is run with an input of size k as when it is run with an input of size k - 1 (where k is an integer that is greater than 1). When the algorithm is run with an input of size 1, it executes seven operations. How many operations does it execute when it is run with an input of size 24? For each integernz 1, let s,-1 be the number of operations the algorithm executes when it is run with an input of size n. Then for each integer 2 1. Therefore, So, S3. Sz. is -Select- and s,= with constant Select- ,which is . So, for every integer n 2 0, s, = It follows that for an input of size 24, the number of operations executed by the algorithm is s -Select-v which equals Need Heln? Desdarrow_forward
- 5. State g(n)'s runtime complexity: int f(int n){ if(n <= 1){ return 1; } return 1 + f(n/2); } int g(int n){ for(int i f(i); } 1; i < n; i *= 2){arrow_forwardA certain computer algorithm executes twice as many operations when it is run with an input of size k as when it is run with an input of size k – 1 (where k is an integer that is greater than 1). When the algorithm is run with an input of size 1, it executes seven operations. How many operations does it execute when it is run with an input of size 26? For each integer n 2 1, let s, -1 be the number of operations the algorithm executes when it is run with an input of size n. Then s, = and s = for each integer k 2 1. Therefore, So, S1, S21 -Select--- with constant Select--- |, which is So, for every integer n 2 0, s, It follows that for an input of size 26, the number of ... is operations executed by the algorithm is s which equals ---Select--- varrow_forwarddefine iteration.arrow_forward
- 3. Find the running time function of the following algorithms as we learned in the class and then the tightest big-O notation. a) AlgorithmX(n) 1. x=1 2. for il to n² 3. 4. 5. x-max(x,i) for j← 1 to n² x=max(x,j) 6. return x b) Algorithm Y(n) 1. x1 2. for i←1 to n³ 3. 4. 5. 6. 7. j←I while jarrow_forwardYou want to design an algorithm, called minMax(A,p,r), that takes an array of integers and indexes of the first and last elements, and returns the minimum and maximum values in that range. Now write the pseudo code of a divide and conquer (and therefore, recursive) algorithm with the same time complexity (Θ(n)). You can assume that p ≤ r. Also, in your code, you can return two numbers by returning a pair, e.g. “return (a, b)”, and can save the output in a similar way, e.g. “(a, b) = minMax(parameters)”. (Short answer please)arrow_forwardThe doubling test will result in the hypothesis that the running time is a N for a constant a when an algorithm's order of development is N log N. Is that an issue, then?arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Introduction to Big O Notation and Time Complexity (Data Structures & Algorithms #7); Author: CS Dojo;https://www.youtube.com/watch?v=D6xkbGLQesk;License: Standard YouTube License, CC-BY