Data Structures and Algorithms - Assignment 3 | CMPSC 465, Assignments of Computer Science

Material Type: Assignment; Class: Data Structures and Algorithms; Subject: Computer Science; University: Penn State - Main Campus; Term: Spring 2008;

Typology: Assignments

Pre 2010

Uploaded on 09/24/2009

koofers-user-4ji
koofers-user-4ji 🇺🇸

10 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CMPSC 465, Spring 2008, Homework 3
Due: Friday,February 6, in class or before noon on the following Saturday.
Problem 1.
Youare givenpoints p0,p1,...,pn,and pihas coordinates x[i], y[i]. Assume that
x[0] =y[0] =0.
a. Assume that all points other than point 0 are in quadrant I (x[i]>0 and y[i]>0)or
in quadrant III (x[i]<0 and y[i]<0). Describe howtotest if p0is extreme in this
set using O(n)steps.
b. Modify your test so it still uses O(n)steps, but it does a bit more: if p0is extreme, it
finds neighbors of p0on the polyline of the convex hull of our point set (see Figure
3.5, where p1has neighbors: p3and p6.
Problem 2.
Youhav e array of numbers A[0], ...,A[n1], and target number t.Check if for
some i<n/2 and jn/2 wehav e A[i]+A[j]=t.
a. Describe areasonable brute force algorithm. What is the running time?
b. Using sorting and binary search, describe howtofind the answer in time O(nlog n).
Problem 6 on page 119.
Idonot knowhow one can reduce the number of sets to consider in brute force
approach. Instead, explain howproblem 2 can be used to reduce the time needed to
O(2n/2)(or O(n2n/2).
Problem 7 on page 119.
Additionally,explain whythe clique problem has an algorithm that runs in time
O(2n/2).

Partial preview of the text

Download Data Structures and Algorithms - Assignment 3 | CMPSC 465 and more Assignments Computer Science in PDF only on Docsity!

CMPSC 465, Spring 2008, Homework 3

Due: Friday, February 6, in class or before noon on the following Saturday.

Problem 1.

You are given points p 0 , p 1 ,... , pn , and pi has coordinates x [ i ], y [ i ]. Assume that x [0] = y [0] = 0.

a. Assume that all points other than point 0 are in quadrant I ( x [ i ] > 0 and y [ i ] > 0) or in quadrant III ( x [ i ] < 0 and y [ i ] < 0). Describe how to test if p 0 is extreme in this set using O ( n ) steps.

b. Modify your test so it still uses O ( n ) steps, but it does a bit more: if p 0 is extreme, it finds neighbors of p 0 on the polyline of the convex hull of our point set (see Figure 3.5, where p 1 has neighbors: p 3 and p 6.

Problem 2.

You have array of numbers A [0],... , A [ n − 1], and target number t. Check if for some i < n /2 and jn /2 we have A [ i ] + A [ j ] = t.

a. Describe a reasonable brute force algorithm. What is the running time?

b. Using sorting and binary search, describe how to find the answer in time O ( n log n ).

Problem 6 on page 119.

I do not know how one can reduce the number of sets to consider in brute force approach. Instead, explain how problem 2 can be used to reduce the time needed to O (2 n /2) (or O ( n 2 n /2).

Problem 7 on page 119.

Additionally, explain why the clique problem has an algorithm that runs in time O (2 n /2).