[Solved] COMP9101 Homework1-Array A of n distinct integers

$25

File Name: COMP9101_Homework1-Array_A_of_n_distinct_integers.zip
File Size: 461.58 KB

SKU: [Solved] COMP9101 Homework1-Array A of n distinct integers Category: Tag:
5/5 - (1 vote)
  1. You are given an array A of n distinct integers.
    • You have to determine if there exists a number (not necessarilyin A) which can be written as a sum of squares of two distinct numbers from A in two different ways (note: m2 +n2 and n2 +m2 counts as a single way) and which runs in time n2 logn in the worst case Note that the brute force algorithm would examine all quadruples of elements in A and there are O(n4) such quadruples.
    • Solve the same problem but with an algorithm which runs in theexpected time of O(n2). (
  2. Suppose that you bought a bag of n bolts with nuts screwed on them. Your 5 year old nephew unscrewed all the nuts from the bolts and put both the nuts and the bolts back into the bag. The bolts are all of similar quite large size but are actually of many different diameters, differing only by at most a few millimetres, so the only way to see if a nut fits a bolt is to try to screw it on and determine if the nut is too small, if it fits or if it is too large. Design an algorithm for matching each bolt with a nut of a fitting size which runs in the expected time O(nlogn).
  3. You are given 1024 apples, all of similar but different sizes and a smallpan balance which can accommodate only one apple on each side. Your task is to find the heaviest and the second heaviest apple while making at most 1032 weighings.
  4. You are in an orchard which has a quadratic shape of size 4n by 4n with equally spaced trees. You purchased apples from n2 trees which also form a square, but the owner is allowing to choose such a square anywhere in the orchard. You have a map with the number of apples on each tree. Your task is to chose such a square which contains the largest total number of apples and which runs in time O(n2). Note that the brute force algorithm would run in time (n4).

1

  1. Determine if f(n) = O(g(n)) or g(n) = O(f(n) or both (i.e., f(n) = (g(n))) or neither of the two, for the following pairs of functions
  • f(n) = (log2(n))2; g(n) = log2(nlog2n)2;

10

  • f(n) = n10; g(n) = 2 n; (6 points)
  • f(n) = n1+(1)n; g(n) =

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] COMP9101 Homework1-Array A of n distinct integers
$25