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

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

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