Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Pseudocode - Data Structures - Problems, Exams of Data Structures and Algorithms

Main points of this past exam are: Pseudocode, Young Tableau, Minimum Element, Provide a Pseudocode, Algorithm Sorts, Storate Space, Query Operations

Typology: Exams

2012/2013

Uploaded on 04/07/2013

seshu_lin3
seshu_lin3 🇮🇳

4

(3)

59 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSE3358 Problem Set 5
02/11/05
Due 02/18/05
Problem 1: Young tableau
An m×nYoung tableau is an m×nmatrix such that the entries of each row are in sorted order
from left to right and the entries of each column are in sorted order from top to bottom. Some of the
entries of a Young tableau may be , which we treat as nonexistent elements. Thus a Young tableau
can be used to hold rmn numbers.
Here’s an example of a 4x4 Young tableau containing the elements {9,16,3,2,4,8,5,14,12}. Note that
this is not unique.
2 4 9
3 8 16
5 14
12
(a) (5 points) Argue that an m×nYoung tableau Yis empty if Y[1,1] = . Argue that Yis full
(contains mn elements) if Y[m, n]<.
(b) (5 points) Argue that the minimum element of a Young tableau Yis always in Y[1,1].
(c) (10 points) Give an algorithm to implement EXTRACT-MIN on a nonempty m×nYoung tableau
that runs in O(m+n) time. Your algorithm should use a recursive subroutine that solves an m×n
problem by recursively solving either an (m1)×nor an m×(n1) subproblem. Define T(p), where
p=m+n, to be the maximum running time of EXTRACT-MIN on any m×nYoung tableau. Give
and solve a recurrence for T(p) that yields the O(m+n) time bound.
(d) (10 points) Show how to insert a new element into a nonfull m×nYoung tableau in O(m+n)
time.
(d) (10 points) Using no other sorting method as subroutine, show how to use an n×nYoung tableau
to sort n2numbers in O(n3) time. Based on this, describe a sorting algorithm that has an O(n1.5)
worst-case running time.
(e) (0 points) I will not ask: given ndistinct elements, how many Young tableaus can you make?
1
pf2

Partial preview of the text

Download Pseudocode - Data Structures - Problems and more Exams Data Structures and Algorithms in PDF only on Docsity!

CSE3358 Problem Set 5 02/11/ Due 02/18/

Problem 1: Young tableau An m × n Young tableau is an m × n matrix such that the entries of each row are in sorted order from left to right and the entries of each column are in sorted order from top to bottom. Some of the entries of a Young tableau may be ∞, which we treat as nonexistent elements. Thus a Young tableau can be used to hold r ≤ mn numbers.

Here’s an example of a 4x4 Young tableau containing the elements { 9 , 16 , 3 , 2 , 4 , 8 , 5 , 14 , 12 }. Note that this is not unique.

(^2 4 9) ∞

(^3 8 16) ∞

5 14 ∞ ∞

12 ∞ ∞ ∞

(a) (5 points) Argue that an m × n Young tableau Y is empty if Y [1, 1] = ∞. Argue that Y is full (contains mn elements) if Y [m, n] < ∞.

(b) (5 points) Argue that the minimum element of a Young tableau Y is always in Y [1, 1].

(c) (10 points) Give an algorithm to implement EXTRACT-MIN on a nonempty m × n Young tableau that runs in O(m + n) time. Your algorithm should use a recursive subroutine that solves an m × n problem by recursively solving either an (m − 1) × n or an m × (n − 1) subproblem. Define T (p), where p = m + n, to be the maximum running time of EXTRACT-MIN on any m × n Young tableau. Give and solve a recurrence for T (p) that yields the O(m + n) time bound.

(d) (10 points) Show how to insert a new element into a nonfull m × n Young tableau in O(m + n) time.

(d) (10 points) Using no other sorting method as subroutine, show how to use an n × n Young tableau to sort n^2 numbers in O(n^3 ) time. Based on this, describe a sorting algorithm that has an O(n^1.^5 ) worst-case running time.

(e) (0 points) I will not ask: given n distinct elements, how many Young tableaus can you make?

Problem 2: Sometimes you just have to count (10 points) Describe an algorithm that, given n integers in the rangle 0 to k, preprocesses its input and then answers any query about how many of the n integers fall into a rangle [a..b] in O(1) time. Your algorithm should use Θ(n + k) prepreocessing time. For full credit you should

  • Describe your algorithm in english
  • Provide a pseudocode
  • Provide arguments for the correctness of your algorithm
  • Provide arguments for the running times of the preprocessing and the query operations

Problem 3: S0rt1ing revisited Suppose that we have an array of n data records to sort and that the key of each record has the value 0 or 1. An algorithm for sorting such a set of records might possess some subset of the following three desirable properties:

  1. The algorithm runs in O(n) time
  2. The algorithm is stable
  3. The algorithm sorts in place, using no more than a constant amount of storate space in addition to the original array

(a) (5 points) Describe an algorithm that possesses properties (1) and (2).

(b) (5 points) Describe an algorithm that possesses properties (2) and (3).

(c) (10 points) Describe an algorithm that possesses properties (1) and (3).

For full credit you should in each case:

  • Describe your algorithm in english
  • Provide a pseudocode, unless you are describing an algorithm for which we have seen the pseu- docode in class
  • Provide arguments that your algorithm possesses the desired properties