Personal Website and Computer Science TUR EN

Sub Set of Given Size of an Array

Last update: 5/7/2020 12:34:00 AM

Written by: Fatih Kabakci

The problem is to figure out sub sets of an set in a given size. A recursive approach will fit to this problem.

Solution in Java:

public class Test {
    private static void print(int[] subSet, int n) {
        for(int i = 0; i < n; i++) {
            System.out.print(subSet[i] + " ");
    private static void sub(int[] set, int i, int[] subSet, int j, int n) {
        if(j == n) {
            print(subSet, n);
        if(i >= set.length)
        subSet[j] = set[i];
        sub(set, i + 1, subSet, j + 1, n);
        sub(set, i + 1, subSet, j, n);
    public static void subSet(int[] a, int n) {             
       int subSet[] = new int[n];
       sub(a, 0, subSet, 0, n);

    public static void main(String[] args) {
        int[] set = {1, 2, 3, 4};
        subSet(set, 3);


1 2 3 
1 2 4 
1 3 4 
2 3 4
There has been no comment yet


   Please verify the image

The Topics in Computer Science

Search this site for


Software & Algorithms


In mathematics and computer science, an algorithm is a step-by-step procedure for calculations. Algorithms are used for calculation, data processing, and automated reasoning.

Programming Languages


A programming language is a formal constructed language designed to communicate instructions to a machine, particularly a computer. It can be used to create programs to control the behavior of a machine. Java,C, C++,C#



A database is an organized collection of data. The data are typically organized to model aspects of reality in a way that supports processes requiring information.



Computer hardware is the collection of physical elements that constitutes a computer system. Computer hardware refers to the physical parts or components of a computer such as the monitor, memory, cpu.

Web Technologies


Web development is a broad term for the work involved in developing a web site for the Internet or an intranet. Html,Css,JavaScript,ASP.Net,PHP are one of the most popular technologies. J2EE,Spring Boot, Servlet, JSP,JSF, ASP

Mobile Technologies


Mobile application development is the process by which application software is developed for low-power handheld devices, such as personal digital assistants, enterprise digital assistants or mobile phones. J2ME



A computer network or data network is a telecommunications network that allows computers to exchange data. In computer networks, networked computing devices pass data to each other along data connections.

Operating Systems


An operating system is software that manages computer hardware and software resources and provides common services for computer programs. The OS is an essential component of the system software in a computer system. Linux,Windows

Computer Science


Computer science is the scientific and practical approach to computation and its applications.A computer scientist specializes in the theory of computation and the design of computational systems.