Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7532281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:24:23+00:00 2026-05-30T05:24:23+00:00

If you are given the set L={1,2,3,…,N} and an integer k , is it

  • 0

If you are given the set L={1,2,3,...,N} and an integer k, is it possible to efficiently calculate the number of “non-adjacent” subsets of size k? A subset S is non-adjacent if for each x in S, neither x-1 nor x+1 are in S.

As an example, for L={1,2,3,4} and k=2 the answer is 3, because we have
{1,3},{1,4},{2,4}. For k=3 the answer is zero.

One way to go would be to generate all size 2 non-adjacent subsets, then trying all possible unions (since a non-adjacent set has the property that all its subsets are non-adjacent), but that strikes me as very wasteful, and probably there is a sweet elegant efficient solution.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T05:24:25+00:00Added an answer on May 30, 2026 at 5:24 am

    Denote by S(m,n) the number of non-adjacent subsets of size m in {1,...,n}. Then the following holds:

    S(m,n) = S(m,n-1) + S(m-1,n-2)
    

    So one can solve it by DP in O(Nk), by adding the boundary conditions

    S(1,n) = n
    S(m,1) = I(m==1)
    S(m,2) = 2*I(m==1)
    

    where I() is the indicator function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to calculate word frequencies of a given set of adjectives in a
Working with PHP for this. From a given set of items, each with its
Is it possible to do clustering in gensim for a given set of inputs
Given set of elements n[1], n[2], n[3], .... n[x] and a number V. (Elements
I'm looking for a way to calculate a useful average for a given set
Each time a function is called, if it's result for a given set of
In Clearcase I can generate a label for a given set of files and
I can see that Collections.unmodifiableSet returns an unmodifiable view of the given set but
Is there an application , which can parse a given set of stored procedures
Given a set of words, we need to find the anagram words and display

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.