Write code to build explicitly all combinations of k 1s

Assignment Help Computer Engineering
Reference no: EM132931364

Assignment 1: Write code to build explicitly all combinations of k 1s in n boxes
k=4, n=12

Recursion: Invoke fun(0.-1)

Define fun(bit_num, prev_bit_pos):
1) If bit_num-k,
(a) Print current combination;
(b) return (exit);

2) Otherwise
for(i-prev_bit_pos+1, i<=n-k+bit_num, i++){
(a) Place 1 at position i;
(b) invoke fun(bit_num+1,1);
(c) clear bit at position i;}

Iteration:
1) Consider all integer numbers from 0 to 2"n-1
2) Convert each int number to binary form
3) Compute the popcount (no. of 1s)
4) If popcount-k. this is one of the desired combination

Complexity: O(2^n)

Complexity: O(n! /( k!(n - k)!)))

Reference no: EM132931364

Questions Cloud

Would you recommend borrowing from a bank : Would you recommend borrowing from a bank at an 18 percent annual interest rate to take advantage of the cash discount offer
Write a subroutine which checks the content : Write a subroutine which checks the content of 20H. If it is a positive number, the subroutine find its two's complement and store it in same location
Find the interest paid during the first year : For tax purposes, she needs to know the amount of interest paid during each year of the loan. Find the interest paid during the first year
What is the book value of the right-of-use asset : What is the book value of the Right-of-use asset and what is the balance in the Lease Liability account on December 31, 2020, respectively
Write code to build explicitly all combinations of k 1s : Write code to build explicitly all combinations of k 1s in n boxes
What is the net cash provided by operating activities : Twin Company provided the following information during the current year. What is the net cash provided by operating activities
Are corporate outreach and company sponsored volunteer : Are corporate outreach and company sponsored volunteer programs a good idea for organizations to implement? Why? From an ethical leadership perspective
How much should JERK absorb : AYK is personally insolvent, but the other two partners are able to meet any indebtedness to the firm. How much should JERK absorb
Why diversity and discrimination are two important ethical : Why diversity and discrimination are two important ethical factors that leaders should focus on while attempting to manage their workforce?

Reviews

Write a Review

Computer Engineering Questions & Answers

  Implementations of the adt bag

Compare the array-based and link-based implementations of the ADT bag operation remove(anEntry). Suppose the different locations of anEntry within the array or chain.

  What are some advantages and disadvantages of using

1. before designing a network one must understand what?2. technical goals in a top down network design consists of

  Make perl script in order to display a basic web page

design a Perl script in order to display a basic Web page and display system information that is dynamic using Perl on the screen such as date and time as well as the host and how long system has been up.

  Select an open-source development effort

Select an open-source development effort (other than Linux), and present a brief history of its evolution and relative success.

  Compute the total delay of the message

Suppose 4 packets of a message, each of L bits arrive at a switch (router) and traverse a link with rate R bps to the destination.

  What is an artificial neural network

What is an artificial neural network and for what types of problems can it be used? Compare artificial and biological neural networks.

  Design an fir linear-phase filter

Use MATLAB to design an FIR linear-phase filter that models a low pass band limited channel that has a 1/2 -dB ripple in the pass band I ƒ I = 3000 Hz.

  Outline a brief business continuity plan

Outline a brief business continuity plan, including controls to reduce the risks in advance as well as a disaster recovery plan

  Questiona declare principles behind object oriented

questiona declare principles behind object oriented software development and describe why it is considered better than

  What is the significance of nevis island

What is the significance of Nevis Island? Did the significance sway your decision? If yes why? If no why? How to proceed in the litigation?

  Prove that the fifth root of 2 is irrational

Use contraposition to prove that if n^5 is even so is n where n is an integer. The contra positive would be if n is odd, then n^5 is odd.

  Clear standards are important as developing a website

can you please list the reasons why using clear standards are important when developing a website. In what areas should these standards be applied.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd