Algorithm Design and Analysis Homework #1 Due: 5pm, Friday, October 4, 2013 TA email: ada@csie.ntu.edu.tw. === Homework submission instructions ===

Similar documents
Algorithms. Margaret M. Fleck. 18 October 2010

Activity 1: Using base ten blocks to model operations on decimals

Closest Pair Problem

5.4 Closest Pair of Points

Many algorithms, particularly divide and conquer algorithms, have time complexities which are naturally

Selected practice exam solutions (part 5, item 2) (MAT 360)

BALTIC OLYMPIAD IN INFORMATICS Stockholm, April 18-22, 2009 Page 1 of?? ENG rectangle. Rectangle

Near Optimal Solutions

Introduction to Algorithms March 10, 2004 Massachusetts Institute of Technology Professors Erik Demaine and Shafi Goldwasser Quiz 1.

WORK SCHEDULE: MATHEMATICS 2007

From Last Time: Remove (Delete) Operation

CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis. Linda Shapiro Winter 2015

Patterns in Pascal s Triangle

First programming project: Key-Word indexer

Data Structures and Algorithms Written Examination

Math Games For Skills and Concepts

Factorizations: Searching for Factor Strings

Dynamic Programming. Lecture Overview Introduction

Shortest Path Algorithms

A Note on Maximum Independent Sets in Rectangle Intersection Graphs

Grade 6 Mathematics Performance Level Descriptors

Equations Involving Lines and Planes Standard equations for lines in space

The program also provides supplemental modules on topics in geometry and probability and statistics.

ALGEBRA. sequence, term, nth term, consecutive, rule, relationship, generate, predict, continue increase, decrease finite, infinite

Numeracy Targets. I can count at least 20 objects

7 Gaussian Elimination and LU Factorization

F.IF.7b: Graph Root, Piecewise, Step, & Absolute Value Functions

Solving Quadratic Equations

Grade 6 Math Circles. Binary and Beyond

Computational Geometry. Lecture 1: Introduction and Convex Hulls

Practice Book. Practice. Practice Book

Which two rectangles fit together, without overlapping, to make a square?

Data Structure [Question Bank]

Outline BST Operations Worst case Average case Balancing AVL Red-black B-trees. Binary Search Trees. Lecturer: Georgy Gimel farb

Graphing calculators Transparencies (optional)

Lesson Plan. N.RN.3: Use properties of rational and irrational numbers.

1. A student followed the given steps below to complete a construction. Which type of construction is best represented by the steps given above?

2. (a) Explain the strassen s matrix multiplication. (b) Write deletion algorithm, of Binary search tree. [8+8]

Linear Programming Notes V Problem Transformations

MA 408 Computer Lab Two The Poincaré Disk Model of Hyperbolic Geometry. Figure 1: Lines in the Poincaré Disk Model

Access Code: RVAE4-EGKVN Financial Aid Code: 6A9DB-DEE3B-74F

CSC148 Lecture 8. Algorithm Analysis Binary Search Sorting

8 Square matrices continued: Determinants

Extra Credit Assignment Lesson plan. The following assignment is optional and can be completed to receive up to 5 points on a previously taken exam.

CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team

HW4: Merge Sort. 1 Assignment Goal. 2 Description of the Merging Problem. Course: ENEE759K/CMSC751 Title:

Mathematical Induction. Lecture 10-11

Section 1.1. Introduction to R n

Vectors 2. The METRIC Project, Imperial College. Imperial College of Science Technology and Medicine, 1996.

Answer Key for California State Standards: Algebra I

The University of the State of New York REGENTS HIGH SCHOOL EXAMINATION MATHEMATICS B. Thursday, January 29, :15 a.m. to 12:15 p.m.

1.3. DOT PRODUCT If θ is the angle (between 0 and π) between two non-zero vectors u and v,

3. Mathematical Induction

PES Institute of Technology-BSC QUESTION BANK

Mathematics. ( : Focus on free Education) (Chapter 5) (Complex Numbers and Quadratic Equations) (Class XI)

Computer Science 281 Binary and Hexadecimal Review

Why? A central concept in Computer Science. Algorithms are ubiquitous.

Analysis of Algorithms I: Optimal Binary Search Trees

Automata and Formal Languages

Connections Across Strands Provides a sampling of connections that can be made across strands, using the theme (fractions) as an organizer

Class Overview. CSE 326: Data Structures. Goals. Goals. Data Structures. Goals. Introduction

Unit 6 Direction and angle

Research Tools & Techniques

Accentuate the Negative: Homework Examples from ACE

Dynamic Programming Problem Set Partial Solution CMPSC 465

15 Prime and Composite Numbers

The Prime Numbers. Definition. A prime number is a positive integer with exactly two positive divisors.

Introduction to Programming System Design. CSCI 455x (4 Units)

Chapter 3. Cartesian Products and Relations. 3.1 Cartesian Products

FACTORING QUADRATICS and 8.1.2

CHAPTER 5 Round-off errors

Pseudo code Tutorial and Exercises Teacher s Version

CSCI 1301: Introduction to Computing and Programming Summer 2015 Project 1: Credit Card Pay Off

Analysis of a Search Algorithm

Current Standard: Mathematical Concepts and Applications Shape, Space, and Measurement- Primary

Randomized algorithms

Shortest Inspection-Path. Queries in Simple Polygons

1 Review of Least Squares Solutions to Overdetermined Systems

Common Core Unit Summary Grades 6 to 8

In this section, you will develop a method to change a quadratic equation written as a sum into its product form (also called its factored form).

ALGORITHMS AND FLOWCHARTS. By Miss Reham Tufail

CHAPTER 5. Number Theory. 1. Integers and Division. Discussion

Mathematics standards

Analysis of Binary Search algorithm and Selection Sort algorithm

Unit 8 Angles, 2D and 3D shapes, perimeter and area

SMT 2014 Algebra Test Solutions February 15, 2014

Math Placement Test Study Guide. 2. The test consists entirely of multiple choice questions, each with five choices.

6.4 Normal Distribution

1. Define: (a) Variable, (b) Constant, (c) Type, (d) Enumerated Type, (e) Identifier.

The Set Data Model CHAPTER What This Chapter Is About

8 th Grade Task 2 Rugs

A Concrete Introduction. to the Abstract Concepts. of Integers and Algebra using Algebra Tiles

The Tower of Hanoi. Recursion Solution. Recursive Function. Time Complexity. Recursive Thinking. Why Recursion? n! = n* (n-1)!

Geometric Transformations

(67902) Topics in Theory and Complexity Nov 2, Lecture 7

Lecture 3: Finding integer solutions to systems of linear equations

Section IV.1: Recursive Algorithms and Recursion Trees

4. How many integers between 2004 and 4002 are perfect squares?

Florida Math for College Readiness

Transcription:

Algorithm Design and Analysis Homework #1 Due: 5pm, Friday, October 4, 2013 TA email: ada@csie.ntu.edu.tw === Homework submission instructions === For Problem 1, commit your source code and a brief documentation to the SVN server (katrina.csie.ntu.edu.tw). You should create a new folder hw1 and put these two files in it. The filenames of the source code, Makefile, and the documentation file should be main.c and report.txt, respectively; you will get some penalties in your grade if your submission does not follow the naming rule. The documentation file should be in plain text format (.txt file). In the documentation file you should explain how your code works, and anything you would like to convey to the TAs. You have to login to judgegirl system (http://katrina.csie.ntu.edu.tw/judgegirl) to initiate the juding process of your program. For Problem 2 through 5, submit the answers via the SVN server (electronic copy) or to the TA at the beginning of class on the due date (hard copy). Except the programming assignment, each student may only choose to submit the homework in only one way; either all in hard copies or all via SVN. If you submit your homework partially in one way and partially in the other way, you might only get the score of the part submitted as hard copies or the part submitted via SVN. If you choose to submit the answers of the writing problems through SVN, please combine the answers of all writing problems into only ONE file in the pdf format, with the file name in the format of hw1 [student ID].pdf (e.g. hw1 b01902888.pdf ); otherwise, you might only get the score of one of the files (the one that the grading TA chooses). Discussions with others are encouraged. However, you should write down your solutions with your own words. In addition, for each problem you have to specify the references (the Internet URL you consulted with or the people you discussed with) on the first page of your solution to that problem. NO LATE SUBMISSION IS ALLOWED for the homework submission in hard copies - no score will be given for the part that is submitted after the deadline. For submissions via SVN (including the programming assignment and electronic copies of the writing problems), up to one day of delay is allowed; however, the score of the part that is submitted after the deadline will get some penalties according to the following rule (the time will be in seconds): LATE SCORE = ORIGINAL SCORE (1 DelayT ime/86400) 1

Problem 1. Rectangle Man (30%) According to the latest news, the archaeologists have found the monument left from the aliens called Rectangle Man. They have left a puzzle in the monument. People who are able to solve the puzzle may found the treasure left behind by the aliens. The monument says, You should know that a rectangle can be determined by four points. But does it really needs up to four points to determine a rectangle? No! In fact, only two points on the diagonal are needed. We have left a map of points. As long as you can determine the maximum number of rectangles those points can form, you can find the treasure we left. There is one last thing you should know: we only care about rectangles whose edges are parallel or perpendicular to the x axis. The following illustration reveals the only two ways a valid rectangle can be formed: You can see that two imaginary points and two points selected from the given map of points are sufficient to form a rectangle. Note: For a rectangle to be valid, there can be no points inside the boundary of that rectangle. The following figures illustrates whether a few valid and invalid rectangles. Invalid Rectangle Valid Rectangle Invalid Rectangle Your goal is to write a program that utilizes a divide-and-conquer algorithm to solve the problem and retrieve the treasure left by the aliens. Hint 1: Sorting the points by their coordinates and dividing them into two groups would help a lot. Hint 2: When you want to find the possible points which can form rectangles with a specific point, you can find that there may be some points blocking all the points behind them from forming rectangles. It may be beneficial to use some kind of data structure to maintain those blocking 2

points. In the following figure, when we consider the rectangles the red point can form with points on the right side, those grey points cannot be the ones to form valid rectangles since they are blocked by the blue point, while the pink point is certainly an option. Blocking point. The specific point Report(10%) Please write down how you derived the algorithm, how you implemented it, and analyze the running time of your algorithm using asymptotic notations. Coding(20%) Input format: The first line contains the total number of points, n, 0 < n 50000. And the following n lines contains each point s coordinate. For any pair of points a, b in the map, a.x b.x and a.y b.y where a.x and a.y are the X and Y coordinates of a, respectively, and b.x and b.y are the X and Y coordinates of b, respectively. In addition, the X and Y coordinates of the points can all be represented in integer. Output format: Please output the maximum possible number of rectangles in a single line. Sample input: 5 4 4 1 2 2 3 5 5 3 1 Sample output: 6 3

Problem 2. Solving Recurrences (16%) a. (2%) T (n) = 2T ( n 2 ) + n Use the substitution method to prove that T (n) = O(n log n) ( n ) ( n ) b. (2%) T (n) = T + T + 1 2 2 Use the substitution method to prove that T (n) = O(n) ( n ) ( ) 2n c. (2%) T (n) = T + T + Θ(n) 3 3 Draw a recursion tree, and use it to prove that T (n) = Ω(nlgn) For the following subproblems, give tight asymptotic bounds ( i.e. corresponding proofs. You can use whatever methods you want. d. (3%) T (n) = 3T e. (2%) T (n) = 7T f. (3%) T (n) = 2T ( ) n 1 3 + log n ( n 4 ) + Θ(n 2 ) ( n 2 ) + n log 2 n Θ(n 2 ), Θ(nlgn) ) and the g. (2%) T (n) = 2T (n 1) + 1 Assume that T(1)=1 for all recurrences. 4

(a) The board for n = 4 (b) The piece to be filled in the board (c) The board covered by the pieces for n = 4 Figure 1: The tiling problem Problem 3. (15%) Assume that n is a positive integer which is a power of two. We have a triangular board which is composed of equilateral trangles, and one triangle on the edge gets randomly removed (see Figure 1(a)). You are asked to cover the entire board with the trapezoical piece shown in Figure 1(b). See Figure 1(c) for an example. Note that the piece can be rotated. All tiles on the board except the one taken way have to be covered, and no tiles can be left outside of the board. In this problem, we ask you to design an algorithm to solve this problem with the divide-and-conquer strategy. Analyze the running time of your algorithm by using the recurrences. Problem 4. Selection in two lists (15%) Given two sorted list with length m and n, design an O(log m+log n)-time algorithm to compute the k-th smallest element in the union of the two given lists. Please give the pseudo code of your algorithm in detail (10%), and explain why the time complexity of your algorithm satisfies the requirement (5%). 5

Problem 5. (24%) 1. (8%)The following pseudo code implements a function that multiplies two very large numbers stored in two binary strings. 1 multiply ( value1, value2 ) 2 length1 = number of digits of value1 3 length2 = number of digits of value2 4 i f length1 < 5 && length2 < 5 5 // It s small enough that we can do 6 // arithmetic operations in constant time. 7 return value1 * value2 8 k = max ( length1, length2 ) / 2 + max ( length1, length2 ) % 2 9 value1_ high = first length1 - k digits of value1 10 value1_ low = last k digits of value1 11 value2_ high = first length2 - k digits of value2 12 value2_ low = last k digits of value2 13 z1 = multiply ( value1_ high, value2_ high ) 14 z2 = multiply ( value1_ high, value2_ low ) 15 z3 = multiply ( value1_ low, value2_ high ) 16 z4 = multiply ( value1_ low, value2_ low ) 17 add 2* k trailing 0 s to z1 18 add k trailing 0 s to z2 and z3 19 return z1+z2+z3+z4 Assume that the larger number of the two has n digits. The running time of the procedure 4T ( n 2 ) + O(n), if n 5 would be T (n) =. Therefore, the procedure runs in O(n 2 ) time. Θ(1), if n < 5 Please modify the procedure and justify that your procedure can run in O(n log 2 3 ) time. 2. (8%)Please give a pseudo code for power_of_ten_to_binary(n) which returns a binary string representing 10 n where n is a positive integer. You have to give the recurrences to represent its running time and justify that your procedure runs in O(n log 2 3 ) time. 3. (8%)Please give a pseudocode for decimal_to_binary(x) which returns a binary string representing the n-digit decimal integer x and justify that your procedure runs in O(n log 2 3 ) time. 6