0% found this document useful (0 votes)
24 views3 pages

CS 6363 Final Exam Instructions

This document provides instructions for a final exam consisting of 6 questions to be completed in 2 hours and 30 minutes. Students are to write their name and NetID on the cover page and each additional page. Questions are of varying difficulty and should be read through before beginning. The exam is closed book with no notes or calculators permitted. Students should turn in all papers and scratch work at the end of the exam period and are allowed to ask for clarification on any problems.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views3 pages

CS 6363 Final Exam Instructions

This document provides instructions for a final exam consisting of 6 questions to be completed in 2 hours and 30 minutes. Students are to write their name and NetID on the cover page and each additional page. Questions are of varying difficulty and should be read through before beginning. The exam is closed book with no notes or calculators permitted. Students should turn in all papers and scratch work at the end of the exam period and are allowed to ask for clarification on any problems.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

CS 6363.

005 Final Exam—Problems and Instructions

May 9, 2019

Please read the following instructions carefully before you begin.

• Write your name and Net ID on the answer sheets cover page and your Net ID on each
additional page. Answer each of the six questions on the answer sheets provided. One
sheet was intentionally left blank to provide you with scratch paper.

• Questions are not necessary given in order of difficulty, so read through them all before
you begin writing!

• This exam is closed book. No notes or calculators are permitted.

• You have two hours and 30 minutes to take the exam.

• Please turn in these problem sheets, your answer sheets, and scratch paper at the end of
the exam period.

• Feel free to ask for clarification on any of the problems.

1
CS 6363.005 Final Exam (Problems) Spring 2019

1. (10 points) Describe and analyze an algorithm to determine in O(n) time whether an
arbitrary array of numbers A[1 .. n] contains more than n/4 copies of any value. You do
not need to justify correctness of your algorithm. An O(n log n) time algorithm is worth a
good amount of partial credit.
[Hint: Reduce to a procedure we discussed in class.]

2. A palindrome is any string that is exactly the same as its reversal, like I, or DEED, or
RACECAR, or AMANAPLANACATACANALPANAMA. Note that a palindrome may have an
odd number of characters.

(a) (5 out of 10) Let X [1 .. n] be an array of characters, and let M a x PalSub(i, j) be the
length of the longest subsequence of X [i .. j] that is also a palindrome. Fill in the
blanks to complete the following recursive definition of M a x PalSub(i, j).


 0 if i > j

if i = j



M a x PalSub(i, j) = 2 + M a x PalSub(i + 1, ) if i < j and X [i] = X [ j]
)
  

 M a x PalSub(i,
max

 otherwise
M a x PalSub( , j)

(b) (5 out of 10) Use dynamic programming to write an iterative algorithm that returns
the length of the longest palindrome subsequence in X [1 .. n] based on the above
recurrence. What is the running time of your algorithm? You may assume you filled
the blanks correctly in the previous part.

3. Suppose we are given an undirected graph G in which every vertex has a positive weight.

(a) (3 out of 10) Describe and analyze an algorithm to find a spanning tree of G with
minimum total weight. (The total weight of a spanning tree is the sum of the weights
of its vertices.) You do not need to justify correctness of your algorithm.
[Hint: This part is much easier than the next part.]
(b) (7 out of 10) Describe and analyze an algorithm to find a path in G from one given
vertex s to another given vertex t with minimum total weight. (The total weight of a
path is the sum of the weights of its vertices.) You do not need to justify correctness
of your algorithm.
[Hint: Reduce to standard single source shortest paths by modifying the graph.]

2
CS 6363.005 Final Exam (Problems) Spring 2019

4. (10 points) Suppose we need to broadcast a message to all nodes in an n-node binary tree.
Initially, only the root node knows the message. In a single round, any node that knows the
message can forward it to at most one of its children. See the figure below for an example
of a message being distributed in five rounds.

Describe and analyze a recursive or dynamic programming algorithm to compute the


minimum number of rounds required to broadcast the message to all nodes in the tree.
Your algorithm should run in O(n) time. You do not need to justify correctness of your
algorithm.

5. (10 points) Suppose we are given a bipartite graph with vertex set L ∪ R and edge set E
such that every edge joins a vertex in L to a vertex in R. Let n = |L| + |R| be the number of
vertices and m = |E| be the number of edges. Describe and analyze an algorithm to find
the size of the largest subset of edges such that every vertex in L is incident to at most
3 edges and every vertex in R is incident to at most 2 edges. You do not need to justify
correctness of your algorithm. (Note we want a subset of edges, meaning each edge is
included in the subset at most once.)

6. Both parts ask you to prove a problem is NP-hard. For both parts, you must argue that your
reduction is correct.

(a) (5 out of 10) Prove the following problem is NP-hard using a reduction from 3SAT.
Given a boolean formula Φ in conjunctive normal form with at most four literals per
clause, determine whether Φ has a satisfying assignment.
[Hint: Read the problem description carefully.]
(b) (5 out of 10) Prove the following problem is NP-hard using a reduction from Hamil-
tonianCycle in undirected graphs. Given a complete undirected graph Kn over n
vertices with non-negative weights on the edges, find a minimum weight cycle that
includes every vertex. (The weight of a cycle is the sum of its edge weights.)

Common questions

Powered by AI

An efficient algorithm for finding a minimum weight spanning tree in an undirected graph with positive vertex weights is to use Prim's or Kruskal's algorithm adapted for vertex weights instead of edge weights. The key adjustment involves treating vertex connections as unit connections with an additional layer of reassessment for vertex weights beyond adjacency. This minor adaptation enables Prim's/Kruskal's traversal or union-find strategies to compute the minimal spanning configuration.

To determine if any value appears more than n/4 times in an array in O(n) time, a possible approach is to reduce it to the problem of finding a majority element candidate, potentially using the Boyer-Moore Voting Algorithm. After identifying the candidate by counting relative to a threshold less than the true majority, validate the candidate by counting its actual occurrences. This approach works due to the threshold nature and efficient counting mechanism inherent in Boyer-Moore, making it applicable for thresholds like n/4.

Proving NP-hardness involves constructing a polynomial-time reduction from a known 3SAT instance to the problem. Map each clause of 3SAT to a corresponding structure in the new problem, maintaining satisfaction dependencies. Use additional constraints to simulate the combination by limiting literals per clause to four, ensuring task equivalency. This mapping certifies any satisfying assignment for a 3SAT instance aligns directly with a selection in the reduced form, thus proving NP-hard status .

Reduction from HamiltonianCycle involves mapping Hamiltonian cycle expectations to minimal cycle queries, adjusting tasks to simulate unique cycle weights by hypothesized weights that maintain completion and adjacency for each vertex. Defining these constraints allows cycle requirement equivalency tests, ensuring logical continuity between vertices within complete graphs. This justification demonstrates the problem's NP-Hardness, as solving Hamiltonian in reduced problem ensures applicable solutions are minimal cycles inclusive of weight adherence .

The recursive definition for calculating the longest palindromic subsequence MaxPalSub(i, j) in an array calls for a nested structure: MaxPalSub(i, j) = 0 if i > j; MaxPalSub(i, j) = 1 if i = j; MaxPalSub(i, j) = 2 + MaxPalSub(i + 1, j - 1) if X[i] = X[j]; otherwise, MaxPalSub(i, j) = max(MaxPalSub(i + 1, j), MaxPalSub(i, j - 1)). This accounts for single-character comparisons and adds known subproblems dynamically .

To modify an undirected graph G for finding the minimum total weight path from vertex s to vertex t, we transform it into an equivalent weighted edge graph, where the edge weights represent the sum of vertex weights incident on these edges. Then, apply Dijkstra's algorithm adjusting the traditional weight definitions to reflect vertex-related sums. This results in an optimal traversal strategy tailored for altered weight considerations .

The dynamic programming strategy involves recursively determining the minimum rounds required for each subtree. Starting from the leaves, calculate the round count as the larger of the children's required rounds plus one, since each parent node can forward the message to at most one child per round. By aggregating these values up to the root, the minimal broadcast span through the tree is computed efficiently in O(n) time .

One algorithm to determine such a subset involves greedy matching with edge constraint checks during standard bipartite matching extensions. Initialize a greedy matching in L, observing added constraint layers in assignment functions to enforce at most 3 incidences in L and 2 typically in R. Following initial setup, iteratively check through edge connections enforcing these limits, leveraging dynamic selectors to reintegrate edges if compliance holds, thus structuring a maximum subset under constraints .

You might also like