You are given a string S of length n. Each character is from an alphabet \Sigma of size k. Devise an algorithm that counts the number of distinct subsequences in S. Give a correctness proof and analyze the runtime. Hint: The running time should be a function with both n and k as parameters. Hint 2: There exists a polynomial time algorithm.
Added by Michael G.
Step 1
Let's think step by step. Show more…
Show all steps
Your feedback will help us improve your experience
Adi S and 84 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
Problem 15.68. (a) Give a combinatorial proof of the following identity by letting S be the set of all length-n sequences of letters a, b and a single c and counting |S| is two different ways. n2^{n-1} = sum_{k=1}^{n} k inom{n}{k} (15.27) (b) Now prove (15.27) algebraically by applying the Binomial Theorem to (1 + x)^n and taking derivatives.
Adi S.
Let n and k be integers with 3 ≤ k ≤ n. How many cycles of length k are there in the complete graph Kn? Hint: we can select a cycle of length k from Kn by choosing a sequence of k distinct vertices v1, v2, ..., vk and then selecting the cycle with vertex set {v1, ..., vk} and edge set {{v1, v2}, ..., {vk-1, vk}, {vk, v1}}. Determine for each cycle of length k how many sequences select this cycle.
(b) Give an algorithm in part (a) that runs in O(mn2) (Hint: let f(s,i) denote the number of length-i valid sequences with sum equal to s. Consider defining the function g(s, i) := E=1 f(t, i))
Aarya B.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
Transcript
18,000,000+
Students on Numerade
Trusted by students at 8,000+ universities
Watch the video solution with this free unlock.
EMAIL
PASSWORD