0% found this document useful (0 votes)
19 views

Tutorial 06

This document outlines 10 problems related to algorithms and data structures: 1) Arranging functions in order of asymptotic growth rate 2) Determining if statements about big O notation are true or false 3) Solving an 8x8 defective chessboard using triominoes with divide and conquer 4) Finding the position of an element in a sorted array in O(log n) time without knowing n 5) Comparing a binary search variant that splits the set unevenly to regular binary search 6) Comparing a ternary search algorithm to binary search 7) Designing O(n) algorithms to compute set union and intersection for sorted arrays 8) Checking if two sets of integers are

Uploaded by

f20211631
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Tutorial 06

This document outlines 10 problems related to algorithms and data structures: 1) Arranging functions in order of asymptotic growth rate 2) Determining if statements about big O notation are true or false 3) Solving an 8x8 defective chessboard using triominoes with divide and conquer 4) Finding the position of an element in a sorted array in O(log n) time without knowing n 5) Comparing a binary search variant that splits the set unevenly to regular binary search 6) Comparing a ternary search algorithm to binary search 7) Designing O(n) algorithms to compute set union and intersection for sorted arrays 8) Checking if two sets of integers are

Uploaded by

f20211631
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Tutorial 6, Design and Analysis of Algorithms, 2024

1. Take the following list of functions and arrange them in ascending order of growth rate (with
proof). That is, if function g(n) immediately follows function f (n) in your list, then it should
be the case that f (n) is O(g(n)).

(a) g1 (n) = 2 log n .

(b) g2 (n) = 2n .
4
(c) g3 (n) = n 3 .
(d) g4 (n) = n(log n)3 .
(e) g5 (n) = nlog n .
n
(f) g6 (n) = 22 .
2
(g) g7 (n) = 2n .

2. Assume you have functions f and g such that f (n) is O(g(n)). For each of the following
statements, decide whether you think it is true or false and give a proof or counterexample:

(a) log2 f (n) is O(log2 g(n)).


(b) 2 f (n) is O(2g(n) ).
(c) f (n)2 is O(g(n)2 ).

3. Tile the follwoing 8 × 8 defective chessboard using triominoes using the divide and conquer
algorithm, and draw the divide and conquer graph for the solution.

1
4. In an infinite array, the first n cells contain integers in sorted order and the rest of the cells
are filled with ∞. Present an algorithm that takes x as input and finds the position of x in the
array in O(log n) time. You are not given the value of n.

5. Device a “binary” search algorithm that splits the set not into two sets of (almost) equal
sizes but into two sets, one of which is twice the size of the other. How does this algorithm
compare with binary search?
n
6. Device a ternary search algorithm that first tests the element at position for equality with
3
2n
some value x, and then checks the element at and either discovers x or reduces the set
3
size to one-third the size of the original. Compare this with binary search.

7. The sets A and B have n elements each given in the form of sorted arrays. Design O(n)
algorithms to compute A ∪ B and A ∩ B.

8. Two sets A and B have n elements each. Assume that each element is an integer in the range
[0, n100 ]. These sets are not necessarily sorted. Design an agorithm to check whether these
two sets are disjoint in O(n) space and time.

9. Find 2345 × 5432 using Karatsuba’s Divide and Conquer Integer Multiplication Algorithm
showing the computations in a divide and conquer graph.

10. Consider an n-node complete binary tree T , where n = 2d − 1 for some d. Each node v of T
is labeled with a real number xv . You may assume that the real numbers labeling the nodes
are all distinct. A node v of T is a local minimum if the label xv is less than the label xw
for all nodes w that are joined to v by an edge. You are given such a complete binary tree
T , but the labeling is only specified in the following implicit way: for each node v, you can
determine the value xv by probing the node v. Show how to find a local minimum of T using
only O(log n) probes to the nodes of T . Give a proof of correctness of your algorithm and
also prove its time complexity.

You might also like