ASSIGNMENT 1. Due on March 24, 2017 (23:59:59)

Similar documents
Sorting. Chapter 11. CSE 2011 Prof. J. Elder Last Updated: :11 AM

Comp 11 Lectures. Mike Shah. July 26, Tufts University. Mike Shah (Tufts University) Comp 11 Lectures July 26, / 45

Central Algorithmic Techniques. Iterative Algorithms

Data Structure and Algorithm Homework #1 Due: 2:20pm, Tuesday, March 12, 2013 TA === Homework submission instructions ===

Advanced Analysis of Algorithms - Midterm (Solutions)

Lecture 1: Asymptotics, Recurrences, Elementary Sorting

1 Closest Pair of Points on the Plane

Lecture 14: Nov. 11 & 13

Fundamental Algorithms

CSE613: Parallel Programming, Spring 2012 Date: May 11. Final Exam. ( 11:15 AM 1:45 PM : 150 Minutes )

Fundamental Algorithms

Ch 01. Analysis of Algorithms

CSE373: Data Structures and Algorithms Lecture 2: Math Review; Algorithm Analysis. Hunter Zahn Summer 2016

Sorting and Searching. Tony Wong

Review Of Topics. Review: Induction

Homework 1 Solutions

LED Lighting Facts: Manufacturer Guide

LED Lighting Facts: Product Submission Guide

Ch01. Analysis of Algorithms

Homework Assignment 4 Root Finding Algorithms The Maximum Velocity of a Car Due: Friday, February 19, 2010 at 12noon

CS 170 Algorithms Spring 2009 David Wagner Final

IE418 Integer Programming

ACCESS TO SCIENCE, ENGINEERING AND AGRICULTURE: MATHEMATICS 1 MATH00030 SEMESTER / Lines and Their Equations

Class Note #14. In this class, we studied an algorithm for integer multiplication, which. 2 ) to θ(n

CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis. Catie Baker Spring 2015

Insertion Sort. We take the first element: 34 is sorted

CSE 241 Class 1. Jeremy Buhler. August 24,

csci 210: Data Structures Program Analysis

Announcements. CSE332: Data Abstractions Lecture 2: Math Review; Algorithm Analysis. Today. Mathematical induction. Dan Grossman Spring 2010

Topic 17. Analysis of Algorithms

Data Structures and Algorithms

CS446: Machine Learning Spring Problem Set 4

Homework 1 Submission

Algorithms and Their Complexity

Design and Analysis of Algorithms March 12, 2015 Massachusetts Institute of Technology Profs. Erik Demaine, Srini Devadas, and Nancy Lynch Quiz 1

Algorithms. Jordi Planes. Escola Politècnica Superior Universitat de Lleida

Discrete Mathematics and Probability Theory Fall 2014 Anant Sahai Homework 5. This homework is due October 6, 2014, at 12:00 noon.

Exam 1. March 12th, CS525 - Midterm Exam Solutions

csci 210: Data Structures Program Analysis

The grade on this summer packet will count as your first journal grade and points will be deducted for late submissions.

Week 5: Quicksort, Lower bound, Greedy

Fall 2016 Test 1 with Solutions

Algorithms: COMP3121/3821/9101/9801

CSE 373: Data Structures and Algorithms Pep Talk; Algorithm Analysis. Riley Porter Winter 2017

Algorithms. Algorithms 2.2 MERGESORT. mergesort bottom-up mergesort sorting complexity divide-and-conquer ROBERT SEDGEWICK KEVIN WAYNE

Remainders. We learned how to multiply and divide in elementary

Asymptotic Running Time of Algorithms

Growth of Functions. As an example for an estimate of computation time, let us consider the sequential search algorithm.

Divide and conquer. Philip II of Macedon

It ain t no good if it ain t snappy enough. (Efficient Computations) COS 116, Spring 2011 Sanjeev Arora

Assignment 4. CSci 3110: Introduction to Algorithms. Sample Solutions

Extending the Number System

Lecture 4. Quicksort

CS Data Structures and Algorithm Analysis

Homework 1 Solutions Probability, Maximum Likelihood Estimation (MLE), Bayes Rule, knn

8 th Grade Honors Variable Manipulation Part 3 Student

Fast Sorting and Selection. A Lower Bound for Worst Case

Algorithm Design and Analysis (NTU CSIE, Fall 2017) Homework #3. Homework #3. Due Time: 2017/12/14 (Thu.) 17:20 Contact TAs:

Math 308 Midterm Answers and Comments July 18, Part A. Short answer questions

Analysis of Algorithms CMPSC 565

CISC 235: Topic 1. Complexity of Iterative Algorithms

9.1 HW (3+3+8 points) (Knapsack decision problem NP-complete)

How many hours would you estimate that you spent on this assignment?

Calculator Exam 2009 University of Houston Math Contest. Name: School: There is no penalty for guessing.

Solutions to the Mathematics Masters Examination

CSED233: Data Structures (2017F) Lecture4: Analysis of Algorithms

Reductions, Recursion and Divide and Conquer

Mat Week 6. Fall Mat Week 6. Algorithms. Properties. Examples. Searching. Sorting. Time Complexity. Example. Properties.

Outline. 1 Introduction. 3 Quicksort. 4 Analysis. 5 References. Idea. 1 Choose an element x and reorder the array as follows:

Computer Algorithms in Systems Engineering Spring 2010 Problem Set 8: Nonlinear optimization: Bus system design Due: 12 noon, Wednesday, May 12, 2010

Student Responsibilities Week 6. Mat Properties of Algorithms. 3.1 Algorithms. Finding the Maximum Value in a Finite Sequence Pseudocode

CS 161 Summer 2009 Homework #2 Sample Solutions

Loop Invariants and Binary Search. Chapter 4.4, 5.1

Overlake School Summer Math Packet Algebra 2 Honors

COS 341: Discrete Mathematics

In this lesson, students model filling a rectangular

CSE548, AMS542: Analysis of Algorithms, Spring 2014 Date: May 12. Final In-Class Exam. ( 2:35 PM 3:50 PM : 75 Minutes )

Park School Mathematics Curriculum Book 9, Lesson 2: Introduction to Logarithms

Quicksort (CLRS 7) We previously saw how the divide-and-conquer technique can be used to design sorting algorithm Merge-sort

Question Points Score Total: 76

MAT300/500 Programming Project Spring 2019

Asymptotic Algorithm Analysis & Sorting

1 Terminology and setup

5 + 9(10) + 3(100) + 0(1000) + 2(10000) =

GRADE 7 MATH LEARNING GUIDE. Lesson 26: Solving Linear Equations and Inequalities in One Variable Using

CMSC 389T MIDTERM SOLUTION

Data Structures and Algorithms CSE 465

Algebra. Here are a couple of warnings to my students who may be here to get a copy of what happened on a day that you missed.

Algorithms. Quicksort. Slide credit: David Luebke (Virginia)

ORF 363/COS 323 Final Exam, Fall 2017

Dynamic Programming: Shortest Paths and DFA to Reg Exps

Kartsuba s Algorithm and Linear Time Selection

CSE 21 Practice Exam for Midterm 2 Fall 2017

Divide-Conquer-Glue. Divide-Conquer-Glue Algorithm Strategy. Skyline Problem as an Example of Divide-Conquer-Glue

Design and Analysis of Algorithms

Designing Information Devices and Systems I Spring 2018 Homework 11

CS 231: Algorithmic Problem Solving

Any student who registers as a new attendee of Teaneck High School after August 15 th will have an extra week to complete the summer assignment.

Inf 2B: Sorting, MergeSort and Divide-and-Conquer

Concrete models and tight upper/lower bounds

Transcription:

ASSIGNMENT 1 Due on March 24, 2017 (23:59:59) Instructions. In this assignment, you will analyze different algorithms and compare their running times. You are expected to measure running times of the algorithms which are listed below (in Section 1), and comment about the results. Also you will implement Finding N th Nearest Touristic Places algorithm described in Section 2. Background Analysis of algorithms is the area of computer science that provides tools and methodologies to analyze the efficiency of different methods of solutions. Efficiency of an algorithm depends on different parameters; how much time, memory space, disk space etc. it requires. Analysis of algorithms is necessary for lots of reasons but mainly used to predict performance and compare algorithms that are developed for the same task. Also it provides guarantees for performance and helps to understand theoretical basis. A complete analysis of the running time of an algorithm involves the following steps: Implement the algorithm correctly. Determine the time required for each basic operation. Identify unknown quantities that can be used to describe the frequency of execution of the basic operations. Develop a realistic model for the input to the program. Analyze the unknown quantities, assuming the modelled input. Calculate the total running time by multiplying the time by the frequency for each operation, then adding all the products. On these experiments, you will measure time requirements of the algorithms and compare their time complexities. A time complexity analysis should focus on gross differences in the efficiency of algorithms that are likely to dominate the overall cost of a solution. You can analyze the example below: Unit Cost Times i :=1 c1 1 sum = 0 c2 1 while ( i <= n ) c3 n+1 begin j :=1; c4 n while ( j <= n ) c5 n ( n+1) begin sum = sum + i c6 n n 1

j := j + 1 c7 n n end i := i + 1 c8 n end Total Cost = c1 + c2 + (n+1)*c3 + n*c4 + n*(n+1)*c5+n*n*c6 + n*n*c7 + n*c8. The time required for this algorithm is proportional to n 2 which is determined as growth rate and it is usually denoted as O(n 2 ). The details of the notations are not given in this assignment paper, you should research and use it for your comments. Part I: Running Time Analysis The solutions of the problems mentioned in this section should be explained in the form of a report. 1 Analyze the algorithm below and show the total cost of this algorithm. Also find tilde notation. Unit Cost Times j :=n c1 while j >=1 do c2 begin i := j c3 while i >=1 do c4 begin x:=x + 1 c5 i := floor ( i /2) c6 end j := floor ( j /2) c7 end 2

2 You are given 5 different algorithms for different purposes and their pseudocodes that are listed below. (a) Finding second largest element in an array at most n+lgn-2 comparisons (b) Stooge sort algorithm : An optimized version of merge sort algorithm s pseudocode func s t o o g e s o r t ( array L, i = 0, j = length (L) 1) i f L [ j ] < L [ i ] then Exchange L [ i ]? L [ j ] i f j i > 1 then t := ( j i + 1) /3 s t o o g e s o r t (L, i, j t ) s t o o g e s o r t (L, i+t, j ) s t o o g e s o r t (L, i, j t ) return L end func (c) Radix sort algorithm func RadixSort (A, d ) for j = 1 to d do //A[] I n i t i a l Array to Sort i n t count [ 1 0 ] = { 0 } ; // Store the count o f keys in count [ ] // key i t i s number at d i g i t p l a c e j for i = 0 to n do count [ key o f (A[ i ] ) in pass j ]++ end func for k = 1 to 10 do count [ k ] = count [ k ] + count [ k 1] // Build the r e s u l t i n g array by checking //new p o s i t i o n o f A[ i ] from count [ k ] for i = n 1 downto 0 do r e s u l t [ count [ key o f (A[ i ] ) ] ] = A[ j ] count [ key o f (A[ i ] ) ] //Now main array A [ ] c o n t a i n s s o r t e d numbers // a c c o r d i n g to c u r r e n t d i g i t p l a c e for i =0 to n do A[ i ] = r e s u l t [ i ] 3

(d) Shaker sort algorithm (for the details, visit <https://en.wikipedia.org/wiki/cocktail_shaker_sort> ) func c o c k t a i l S h a k e r S o r t ( A : l i s t o f s o r t a b l e items ) d e f i n e d as : do swapped := f a l s e for each i i n 0 to length ( A ) 2 do : // t e s t whether the two elements are i n the wrong order i f A[ i ] > A[ i + 1 ] then // l e t the two elements change p l a c e s swap ( A[ i ], A[ i + 1 ] ) swapped := t r u e end i f end for i f not swapped then // we can e x i t the outer loop here i f no swaps occurred. break do while loop end i f swapped := f a l s e for each i i n length ( A ) 2 to 0 do : i f A[ i ] > A[ i + 1 ] then swap ( A[ i ], A[ i + 1 ] ) swapped := t r u e end i f end for // i f no elements have been swapped, then the l i s t i s s o r t e d while swapped end func (e) Maximum subarray algorithm : divide and conquer func maxsub ( i n t [ ] S ; low, high : i n t ) i f low = high then return ( low, high, S ( low ) ) else mid = ( low + high ) / 2 ( llow, lhigh, lsum ) = maxsub (S, low, mid ) ( rlow, rhigh, rsum ) = maxsub (S, mid+1, high ) ( mlow, mhigh, msum) = middlemaxsub ( S, low, mid, high ) end i f ; return t r i p l e with h i g h e s t sum end maxsub func middlemaxsub ( i n t [ ] S ; low, high, i n t ) s t a r t at mid and find b e s t l e f t and l e f t s u m s t a r t at mid and find b e s t r i g h t and rightsum return ( b e s t l e f t, b e s t r i g h t, rightsum+l e f t s u m ) end middlemaxsub 4

You must execute this algorithms on randomly generated integer numbers. purpose, you must carry out the following main steps. Generate n random integer numbers. Construct a table and save execution time for each algorithms.(see Table 1) You must carry out these steps for different n number. For this Finally, you will plot a graph that will show relation between n and execution time Algorithms /n 100 300 500 700 1100 1300 1500 1700 1900 2100 2300 2500 Finding second largest element Stooge sort algorithm Radix sort algorithm Shaker sort algorithm Maximum subarray algorithm Table 1: Exemplary Table 3 Suppose that the execution of a particular algorithm requires carrying out T(N) operations, where N is the number of inputs that must be processed and T (N) = NlogN + 9N + 55 (1) Assume the algorithm will be executed on hardware capable of performing 10 6 operations per second and an input of size 220. How long will it take (in seconds)? (Pick the closest answer.) 1) 1 2) 10 3) 20 4) 30 5) 40 6) 50 7) 60 8) 120 9) 1000 10) 10000 5

Spring 2017 Part II: Finding N th nearest touristic places Alice visits Barceolana in Spain as a tourist. Since she will be there for a one day and her time is very restricted, she decided to look for only first the nearest N touristic places to herself. Places and Alice s location are situated 2-dimensional which are represented (x,y) and (a,b) respectively. In this problem, you are expected to answer the booster distance of N th nearest touristic places from Alice s coordinate. The coordinates of the places and Alice s location will randomly be generated in each execution. N will be entered from the keyboard. Also in each execution 100 touristic places coordinate pairs and only one Alice s location will randomly be generated which is represented x,y and a,b respectively. But if the nearest place of visit fee is high, she decided to visit the second nearest place whose visit fee is cheaper than the other and so on. So low-cost touristic place has a prioity for Alice. Booster distance is calculated as p (x a)2 + (y b)2 (2) If the result of the distance exceeds 200, the visit fee of the place doesn t be considered. Write an algorithm for Alice to visit nearest and low-cost touristic place. Show Alice s prefered coordinates, booster distances and visit fees according to N number as an output. (Use priority queue to implement this algorithm and consider the exceptions ex. you generated 100 coordinates but you entered 180 for N, the program must give a warning and inform user) Constraints 103 a,b 103 103 x,y 103 0 visit fee 60 6

Sample Input: N=2 (entered from the keyboard) Generate Alice s location randomly. e.g. (-7,10) Generate 100 randomly touristic places coordinates.. e.g. (10,10), (50,-160), (0,3), (- 200,1000) etc. Generate 100 randomly fees for these places respectively. e.g. 30, 20, 40, 4 (Euro) etc. Calculate the Booster distances! ( 7 10) 2 + (10 10) 2 = 18 Second nearest distance ( 7 50) 2 + (10 + 160) 2 = 179 First nearest distance, because the location fee is less than the other calculated distances fee, so it must be in priority queue! ( 7 0) 2 + (10 3) 2 = 10 Third nearest distance ( 7 + 200) 2 + (10 1000) 2 = 10008 ignore low-cost, because it is greater than 200 Sample Output: The booster distances are found! 1 th nearest distance calculated with the second generated coordinate is 179 Coordinates of touristic place is (50,-160), location fee is 20 2 th nearest distance calculated with the first generated coordinate is 18 Coordinates of touristic place is (10,10), location fee is 30 Reports You must argue the algorithms in terms of time complexity and memory requirements You must show your analysis in detail for each algorithm in your report Your report will include table,graph and your analysis for the experiment. There are no special requirements for the report. If you use a document, code, solution etc. you have to refer related documents. Notes You are required to submit all your code (all your code should be written in Java) along with a report in PDF format (should be prepared using L A TEX). The codes you will submit should be well commented. Your report should be self-contained and should contain a brief overview of the problem and the details of your implemented solution. You can include pseudocode or figures to highlight or clarify certain aspects of your solution. Save all your work until the 7

assignment is graded.you can ask your questions about the experiment on Piazza. You will only submit your report file in the given format below studentid.zip <report> report.pdf <src> main.java *.java Your assignment will not be marked if you do not prepare a table and graph. The ZIP file will be submitted via the department s submission system. Grading The assignment will be graded out of 100 points: 0 (no submission), 20 (an attempt at a solution), 40 (a partially correct solution), 60 (a mostly correct solution), 80 (a correct solution), 100 (a particularly creative or insightful solution) Note: Preparing good report is important as well as your solutions! Late Policy You may use up to four extension days (in total) over the course of the semester for the four assignments you will take. Any additional unapproved late submission will be weighted by 0.5. Academic Integrity All work on assignments must be done individually unless stated otherwise. You are encouraged to discuss with your classmates about the given assignments, but these discussions should be carried out in an abstract way. That is, discussions related to a particular solution to a specific problem (either in actual code or in the pseudocode) will not be tolerated. In short, turning in someone else s work, in whole or in part, as your own will be considered as a violation of academic integrity. Please note that the former condition also holds for the material found on the web as everything on the web has been written by someone else. 8