• Home
  • Textbooks
  • Introduction to the Design and Analysis of Algorithms
  • Transform-and-Conquer

Introduction to the Design and Analysis of Algorithms

Anany Levitin

Chapter 6

Transform-and-Conquer - all with Video Answers

Educators


Section 1

Presorting

08:23

Problem 1

Consider the problem of finding the distance between the two closest numbers in an array of $n$ numbers. (The distance between two numbers $x$ and $y$ is computed as $|x-y|$.)
a. Design a presorting-based algorithm for solving this problem and determine its efficiency class.
b. Compare the efficiency of this algorithm with that of the brute-force algorithm (see Problem 9 in Exercises 1.2).

Bryan Lynn
Bryan Lynn
Numerade Educator
02:51

Problem 2

Let $A=\left\{a_1, \ldots, a_n\right\}$ and $B=\left\{b_1, \ldots, b_m\right\}$ be two sets of numbers. Consider the problem of finding their intersection, i.e., the set $C$ of all the numbers that are in both $A$ and $B$.
a. Design a brute-force algorithm for solving this problem and determine its efficiency class.
b. Design a presorting-based algorithm for solving this problem and determine its efficiency class.

Aman Gupta
Aman Gupta
Numerade Educator

Problem 3

Consider the problem of finding the smallest and largest elements in an array of $n$ numbers.
a. Design a presorting-based algorithm for solving this problem and determine its efficiency class.
b. Compare the efficiency of the three algorithms: (i) the brute-force algorithm, (ii) this presorting-based algorithm, and (iii) the divide-and-conquer algorithm (see Problem 2 in Exercises 5.1).

Check back soon!

Problem 4

Estimate how many searches will be needed to justify time spent on presorting an array of $10^3$ elements if sorting is done by mergesort and searching is done by binary search. (You may assume that all searches are for elements known to be in the array.) What about an array of $10^6$ elements?

Check back soon!
06:48

Problem 5

To sort or not to sort? Design a reasonably efficient algorithm for solving each of the following problems and determine its efficiency class.
a. You are given $n$ telephone bills and $m$ checks sent to pay the bills $(n \geq m)$. Assuming that telephone numbers are written on the checks, find out who failed to pay. (For simplicity, you may also assume that only one check is written for a particular bill and that it covers the bill in full.)
b. You have a file of $n$ student records indicating each student's number, name, home address, and date of birth. Find out the number of students from each of the 50 U.S. states.

Bryan Lynn
Bryan Lynn
Numerade Educator

Problem 6

Given a set of $n \geq 3$ points in the Cartesian plane, connect them in a simple polygon, i.e., a closed path through all the points so that its line segments (the polygon's edges) do not intersect (except for neighboring edges at their common vertex). For example,
(FIGURE CANT COPY)
a. Does the problem always have a solution? Does it always have a unique solution?
b. Design a reasonably efficient algorithm for solving this problem and indicate its efficiency class.

Check back soon!

Problem 7

You have an array of $n$ real numbers and another integer $s$. Find out whether the array contains two elements whose sum is $s$. (For example, for the array 5 , $9,1,3$ and $s=6$, the answer is yes, but for the same array and $s=7$, the answer is no.) Design an algorithm for this problem with a better than quadratic time efficiency.

Check back soon!

Problem 8

You have a list of $n$ open intervals $\left(a_1, b_1\right),\left(a_2, b_2\right), \ldots,\left(a_n, b_n\right)$ on the real line. (An open interval $(a, b)$ comprises all the points strictly between its endpoints $a$ and $b$, i.e., $(a, b)=\{x \mid a<x<b\}$.) Find the maximum number of these intervals that have a common point. For example, for the intervals $(1,4)$, $(0,3),(-1.5,2),(3.6,5)$, this maximum number is 3 . Design an algorithm for this problem with a better than quadratic time efficiency.

Check back soon!
00:18

Problem 9

Number placement Given a list of $n$ distinct integers and a sequence of $n$ boxes with pre-set inequality signs inserted between them, design an algorithm that places the numbers into the boxes to satisfy those inequalities. For example, the numbers $4,6,3,1,8$ can be placed in the five boxes as shown below:
$1<8>3<4<6$

Michelle Nguyen
Michelle Nguyen
Numerade Educator

Problem 10

Maxima search
a. A point $\left(x_i, y_i\right)$ in the Cartesian plane is said to be dominated by point $\left(x_j, y_j\right)$ if $x_i \leq x_j$ and $y_i \leq y_j$ with at least one of the two inequalities being strict. Given a set of $n$ points, one of them is said to be a maximum of the set if it is not dominated by any other point in the set. For example, in the figure below, all the maximum points of the set of 10 points are circled.
(FIGURE CANT COPY)
Design an efficient algorithm for finding all the maximum points of a given set of $n$ points in the Cartesian plane. What is the time efficiency class of your algorithm?
b. Give a few real-world applications of this algorithm.

Check back soon!
02:37

Problem 11

Anagram detection
a. Design an efficient algorithm for finding all sets of anagrams in a large file such as a dictionary of English words [Ben00]. For example, eat, ate, and tea belong to one such set.
b. Write a program implementing the algorithm.

Tarandeep Singh
Tarandeep Singh
Numerade Educator