This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: CS3230 Tutorial 5 1. Give an algorithm which finds the distance between closest pair of points, when all the points lie on a straight line (though not necessarily all on the x axis). Try to make the algorithm simpler than the one done in class. Ans: (A) Sort the points based on xcoordinate (as long as the points are not on a line perpen dicular to x axis). (B) Find distances between adjacent points in the above sorted order, and report the shortest distance among these. In case the points are on a line perpendicular to x axis, then sort them based on y axis, and do (B) above. 2. Suppose we are sorting an array consisting of integers ≥ 0. Explain how one may mod ify the inputs (in linear time) so that any sorting algorithm becomes a stable sorting algorithm. Your modification of the numbers should be such that one can easily obtain the original numbers back from the modification. Ans: (A) Suppose there are n integers in the array A ....
View
Full
Document
This note was uploaded on 01/06/2012 for the course CS 3230 taught by Professor Sanjay during the Fall '10 term at National University of Singapore.
 Fall '10
 sanjay
 Algorithms

Click to edit the document details