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
Question
Chapter 8, Problem 2P
(a)
Program Plan Intro
To give an
(b)
Program Plan Intro
To give an algorithm of running time of
(c)
Program Plan Intro
To give a stable sorting element that uses constant amount of storage space.
(d)
Program Plan Intro
To give RADIX-SORT algorithm that sorts n -records with b -bits keys in
(e)
Program Plan Intro
To describe the counting sort so that it sorted the records in
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
The search algorithm developed will be used for users to search the catalog for all items matching the search keyword(s), and there are a
total of 15000 items in the catalog. During development, three different algorithms were created.
• Algorithm A runs in constant time, with a maximum runtime of 1.10 seconds and returns all matching results.
●
Algorithm B runs in logarithmic time, with a maximum runtime of 0.3 seconds, and returns only the first result.
●
Algorithm C runs in linear time, with a maximum runtime of 1.50 seconds and returns all matching results.
Which algorithm would be the least suitable for the requirements stated? In your answer, justify your choice by explaining why you picked that
algorithm, and why you did not pick the other two algorithms.OND OND OND DAD
Consider an n by n matrix, where each of the n2 entries is a
positive integer.
If the entries in this matrix are unsorted, then determining
whether a target number t appears in the matrix can only be done
by searching through each of the n2 entries. Thus, any search
algorithm has a running time of O(n²).
However, suppose you know that this n by n matrix satisfies the
following properties:
• Integers in each row increase from left to right.
• Integers in each column increase from top to bottom.
An example of such a matrix is presented below, for n=5.
4 7 11 15
2 5 8 12 19
3 6 9 16 22
10 13 14 17 24
1
18 21 23 | 26 | 30
Here is a bold claim: if the n by n matrix satisfies these two
properties, then there exists an O(n) algorithm to determine
whether a target number t appears in this matrix.
Determine whether this statement is TRUE or FALSE. If the
statement is TRUE, describe your algorithm and explain why your
algorithm runs in O(n) time. If the statement is FALSE, clearly
explain why no…
Write a psuedo algorithm that solves the coin-row problem with dynamic programming, as a result, returns the maximum value of money that can be collected from the table under the specified conditions, but did not tell which coins should be taken from the table to reach this value (i.e. which elements of the array that comes as input to the algorithm). . Make the necessary changes in the algorithm that solves the Sequential Money problem with dynamic programming, make the algorithm return the values of the coins included in the maximum solution it finds in a series or a list. What are the time and space complexities of your algorithm, specify them separately.
Chapter 8 Solutions
Introduction to Algorithms
Knowledge Booster
Similar questions
- Consider the following problem: You have a large collection of music files (e.g., MP3 files), and for each file you know the artist name (as a string) and the song title (also as a string). You wish to find the name of the artist who has the largest number of songs featured in the collection. Describe an algorithm for this problem.the algorithm should be as efficient as possible. State the running time of your algorithm, assuming that there are in total n songs, across t different artistsarrow_forward1. Suppose you are responsible for organizing and determining the results of an election. An election has a winner if one person gets at least half of the votes. For an election with n voters and k candidates, design a divide and conquer algorithm to determine if the election has a winner and finds that winner. Your algorithm should run in O(nlogn) and is allowed to use 0(1) extra memory.arrow_forwardJava: Consider the following algorithm for searching in an unsorted array. If the size of the array is 1, then check if it contains the element to be searched. Otherwise, divide the array into two halves, and recursively search both halves. Which of (a)–(c) is false? The running time of this algorithm is O(N) The actual running time of this algorithm is likely to be better than sequential search. This is an example of a divide‐and‐conquer algorithm all of the above are true none of the above is truearrow_forward
- PSEUDOCODE - (ONLY PSEUDOCODE) Write an algorithm that takes a vector of integers A[1..n] and an integer x and, in O(n log n) time, determines if there are indices 1 ≤ i < j ≤ n such that A[i] + A[j] = x. proof the correctness and time consumption of your algorithm.arrow_forwardSorting algorithms are incredibly important and used by us on a daily basis. In this course we haveinvestigated and analyzed numerous sorting algorithms.In each of the following questions, you are given an input array A with n elements, where n is a very largepositive integer. You will then compare two sorting algorithms and justify which of the two algorithmsis faster in sorting this array A.In your responses, you must clearly explain which of the two algorithms runs faster. Make sure yourigorously justify your answer, carefully proving whether each algorithm is O(n), O(n log n), or O(n2).(a) Let A = [5, 5, 5, 5, 5, . . . , 5] be an array where all of the elements are equal to 5.Determine whether Selection Sort or Insertion Sort sorts this array faster. (b) Let A = [n, n -1, n - 2, . . . . 3, 2, 1] be an array where the rst n positive integers are listed indecreasing order.Determine whether Heapsort or Quicksort sorts this array faster.For this question, assume the Quicksort pivot is…arrow_forwardGiven an input parameter n, Alice has an unsorted array A of n n items, and she needs to perform O(log n) search operations on A. She has two algorithms in mind to achieve this: • Algorithm 1: Sort A using MERGE SORT and then perform all of O(logn) search operations using binary search. • Algorithm 2: Perform all of O(log n) search operations directly on A using linear search.Present the running times of each of the two algorithms separately, and select the algorithm you would suggest to Alice by determining which one is asymptotically faster.arrow_forward
- Problem 2: Search an Array (v1, v2, · .. Vn). We want Considering the search problem, we have a list of n integers A = to design an algorithm to check whether an item v exists or not such that it should return either the index, i, if it was found or -1 otherwise, when not found. a) Implement the algorithm in Python b) Empirically, show the performance curve of the algorithm using time measurements. c) Using the basics of the theoretical analysis, write the complexity of its worst-case time. d) Prove your algorithm is correct-it terminates with the valid output in every casearrow_forwardAn algorithm for searching a large sorted array for a specific value x compares every third item in the array to x until it finds one that is greater than or equal to x. When a larger value is found, the algorithm compares x to the previous two items. If the array is sorted in increasing order, which of the following de- scribes all cases when this algorithm uses fewer comparisons to find x than would a binary search? (A) It will never use fewer comparisons. (B) When x is in the middle position of the array (C) When x is very close to the beginning of the array (D) When x is very close to the end of the array (E) When x is not in the arrayarrow_forwardConsider the following algorithm: function MYSTERY(A, n) /Input: Array A and integer n. A has size of least n if n <1 then return 0 else temp + 3 x A[n – 1]+ MYSTERY(A,n – 2) return temp (a) Write down recurrence equations that describe the running time of the algorithm. Assume the base operation has a cost k. (b) Solve these recurrence equations and give the asymptotic time complexity of the algorithm. Use Big-O notation for your answer.arrow_forward
- Question 2: Implement sequential search and binary search algorithms on your computer. Note down run time for each algorithm on arrays of size (1, 250, 500, 750, 1000, 1250, 1500, 5000). For both algorithms, store the values 0 through n - 1 in order in the array, and use a variety of random search values in the range 0 to n - 1 on each size n. Graph the resulting times. When is sequential search faster than binary search for a sorted array? Solution: Input Size(N) Search Element Execution Time for Execution Time for Sequential Search(n) Binary Search(logn)arrow_forwardConsider array A of n numbers. We want to design a dynamic programming algorithm to find the maximum sum of consecutive numbers with at least one number. Clearly, if all numbers are positive, the maximum will be the sum of all the numbers. On the other hand, if all of them are negative, the maximum will be the largest negative number. The complexity of your dynamic programming algorithm must be O(n2). However, the running time of the most efficient algorithm is O(n). Design the most efficient algorithm you can and answer the following questions based on it. To get the full points you should design the O(n) algorithm. However, if you cannot do that, still answer the following questions based on your algorithm and you will get partial credit. Write the recursion that computes the optimal solution recursively based on the solu- (a) tion(s) to subproblem(s). Briefly explain how it computes the solution. Do not forget the base case(s) of your recursion.arrow_forwardProblem 2: Search an ArrayConsidering the search problem, we have a list of n integers A = ⟨v1, v2, · · · vn⟩. We wantto design an algorithm to check whether an item v exists or not such that it should returneither the index, i, if it was found or −1 otherwise, when not found.a) Implement the algorithm in Pythonb) Empirically, show the performance curve of the algorithm using time measurements.c) Using the basics of the theoretical analysis, write the complexity of its worst-casetime.d) Prove your algorithm is correct—it terminates with the valid output in every casearrow_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