You are on page 1of 1

CSE523

Assignment No. 2

S. Description
No.
1. a.) Specify and Illustrate with examples at least two advantages and
disadvantages of recursion over iterative algorithms.
b.) Code a problem of your choice with both recursive and iterative
version and report the time complexity of both the versions for
different input sizes.

2. Imagine a binary Tree with following abstract operations:

a.) getRoot() -> gives the reference of the root Node of the tree.
b.) left() -> gives the reference to the left child a node. If there is no left
child, left() returns NULL reference.
c.) right() -> gives the reference to the right child of a node. If there is no
right child, right() returns NULL reference.

With these abstract functions model an algorithm to find the height of the
tree.

3. a.) For a given Array of Integers devise an algorithm ,


that returns Kth smallest element in the array. The algorithm
should be essentially recursive. Code the algorithm and report
running times for various problem sizes.

b.) Also find Kth Smallest element both by sorting the array and by
maintaining the array as a Heap and extracting root K times.

c.) Report the execution time of all three techniques for various
problem sizes and specify the reasons for superiority of one
algorithm over other.

4. Imagine a grid of 100 horizontal and vertical lines having 100x100 points. A
rectangle is then specified by two points, Upper_Left and Lower_Right. The
rectangle is visualized by the diagonal connecting these two points and lines
parallel to grid axes. Given two arbitrary rectangles specify an algorithm to
find rectangle defined by intersection of the two rectangles.

5. a.) Implement a recursive algorithm to find all 2N- 1 binary


numbers for a given N.
b.) Implement a recursive algorithm to find all permutations of a
given Word.
c.) Given an array of N random integers, find all subsets of the
array having numbers summing up to a number M.

You might also like