Introduction to Algorithms
3rd Edition
ISBN: 9780262033848
Author: Thomas H. Cormen, Ronald L. Rivest, Charles E. Leiserson, Clifford Stein
Publisher: MIT Press
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 14.1, Problem 8E
Program Plan Intro
To describe an
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Correct answer will be upvoted else downvoted. Computer science.
Allow us to signify by d(n) the amount of all divisors of the number n, for example d(n)=∑k|nk.
For instance, d(1)=1, d(4)=1+2+4=7, d(6)=1+2+3+6=12.
For a given number c, track down the base n to such an extent that d(n)=c.
Input
The principal line contains one integer t (1≤t≤104). Then, at that point, t experiments follow.
Each experiment is characterized by one integer c (1≤c≤107).
Output
For each experiment, output:
"- 1" in case there is no such n that d(n)=c;
n, in any case.
Consider the problem of counting, in a given text, the number of substrings that start with an A and end with a B. For example, there are four such substrings in CABAAXBYA.a. Design a brute-force algorithm for this problem and determine its efficiency class.b. Design a more efficient algorithm for this problem with complexity O (n)
Let n be a positive integer, and consider the following algorithm segment.
for i := 1 to n
for j := 1 to i
[Statements in body of inner loop.
None contain branching statements
that lead outside the loop.]
next j
next i
How many times will the inner loop be iterated when the algorithm is implemented and run?
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
- When the order of increase of an algorithm's running time is N log N, the doubling test leads to the hypothesis that the running time is a N for a constant a. Isn't that an issue?arrow_forwardGiven is a strictly increasing function, f(x). Strictly increasing meaning: f(x)< f(x+1). (Refer to the example graph of functions for a visualization.) Now, define an algorithm that finds the smallest positive integer, n, at which the function, f(n), becomes positive. The things left to do is to: Describe the algorithm you came up with and make it O(log n).arrow_forwardGive an example of an algorithm that is O(1), an algorithm that is O(n) and an algorithm that is O(n2). Discuss the difference between them.arrow_forward
- Create an algorithm that can conduct a sequence of m union and find operations on a Universal set of n items in time O(m + n), consisting of a sequence of unions followed by a sequence of finds.arrow_forwardConsider a function f: N → N that represents the amount of work done by some algorithm as follow: f(n) = {(1 if n is oddn if n is even)┤ Prove or disprove. f(n) is O(n). Please show proof or disproofarrow_forwardCall a sequence X[1 · · n] of numbers oscillating if X[i] < X[i + 1] for all even i, and X[i] > X[i + 1] for all odd i. Describe an efficient algorithm to compute the length of the longest oscillating subsequence of an arbitrary array A of integers.arrow_forward
- An array A[1 . . n] of integers is a mountain if it consists of an increasing sequence followed by a decreasing sequence, or more precisely,If there is an index m ∈ {1, 2, . . . , n} such that• A[i] < A[i + 1] for all 1 ≤ i < m, and• A[i] > A[i + 1] for all m ≤ i < n.In particular, A[m] is the maximum element, and it is the unique “locally maximum” element surrounded by smaller elements (A[m − 1] and A[m + 1]).Give an algorithm to compute the maximum element of a mountain input array A[1 . . n] in O(log(n)) time.arrow_forwardGive an O.n lg n/-time algorithm to find the longest monotonically increasing subsequence of a sequence of n numbers. (Hint: Observe that the last element of a candidate subsequence of length i is at least as large as the last element of a candidate subsequence of length i 1. Maintain candidate subsequences by linking them through the input sequence.)arrow_forwardGive a big-O estimate for the number of additionsused in this segment of an algorithm.t := 0for i := 1 to 3for j := 1 to 4t := t + ijarrow_forward
- If a is a symbol and n > 0, then an denotes a···a, or in words, the string of length n consisting of only a’s. Now consider the coding with two code words 0n and 1n, for some natural number n > 0. Show that this coding is perfect if and only if n is odd.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_forwardConsider a divide-and-conquer algorithm that calculates the sum of all elements in a set of n numbers by dividing the set into two sets of n/2 numbers each, finding the sum of each of the two subsets recursively, and then adding the result. What is the recurrence relation for the number of operations required for this algorithm? Answer is f(n) = 2 f(n/2) + 1. Please show why this is the case.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_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