Power set in lexicographic order

Here given code implementation process.

import java.util.Arrays;
/*
   Java Program 
   Power set in lexicographic order
*/

class LexicographicOrder
{

    public void subSequence(String text, String result, int index, int n)
    {
        if(index <= n)
        {
            // Display calculated result
            System.out.println("["+result+"]");

            for (int i = index ; i < n ; ++i) 
            {
                // Find the subsequence using recursively
                subSequence(text,result+text.charAt(i), i+1, n);
            }
        }
    }

    public void findSubSequence(String data)
    {
        int n = data.length();

        if (n <= 0)
        {
            return;
        }
        // Sort given data sequence
        char[] s = data.toCharArray();
        Arrays.sort(s);
        String text = new String(s);

        // Test
        subSequence(text, "", 0, n);
    }
    public static void main(String[] args)
    {
        LexicographicOrder task = new LexicographicOrder();
        
        task.findSubSequence("MASTER");
    }
}

Output

[]
[A]
[AE]
[AEM]
[AEMR]
[AEMRS]
[AEMRST]
[AEMRT]
[AEMS]
[AEMST]
[AEMT]
[AER]
[AERS]
[AERST]
[AERT]
[AES]
[AEST]
[AET]
[AM]
[AMR]
[AMRS]
[AMRST]
[AMRT]
[AMS]
[AMST]
[AMT]
[AR]
[ARS]
[ARST]
[ART]
[AS]
[AST]
[AT]
[E]
[EM]
[EMR]
[EMRS]
[EMRST]
[EMRT]
[EMS]
[EMST]
[EMT]
[ER]
[ERS]
[ERST]
[ERT]
[ES]
[EST]
[ET]
[M]
[MR]
[MRS]
[MRST]
[MRT]
[MS]
[MST]
[MT]
[R]
[RS]
[RST]
[RT]
[S]
[ST]
[T]
// Include header file
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;
/*
   C++ Program 
   Power set in lexicographic order
*/
class LexicographicOrder
{
	public: void subSequence(string text, string result, int index, int n)
	{
		if (index <= n)
		{
			// Display calculated result
			cout << "[" << result << "]" << endl;
			for (int i = index; i < n; ++i)
			{
				// Find the subsequence using recursively
				this->subSequence(text, result  +  
                                  (text[i]), i + 1, n);
			}
		}
	}
	void findSubSequence(string text)
	{
		int n = text.length();
		if (n <= 0)
		{
			return;
		}
		sort(text.begin(), text.end());
		// Test
		this->subSequence(text, "", 0, n);
	}
};
int main()
{
	LexicographicOrder *task = new LexicographicOrder();
	task->findSubSequence("MASTER");
	return 0;
}

Output

[]
[A]
[AE]
[AEM]
[AEMR]
[AEMRS]
[AEMRST]
[AEMRT]
[AEMS]
[AEMST]
[AEMT]
[AER]
[AERS]
[AERST]
[AERT]
[AES]
[AEST]
[AET]
[AM]
[AMR]
[AMRS]
[AMRST]
[AMRT]
[AMS]
[AMST]
[AMT]
[AR]
[ARS]
[ARST]
[ART]
[AS]
[AST]
[AT]
[E]
[EM]
[EMR]
[EMRS]
[EMRST]
[EMRT]
[EMS]
[EMST]
[EMT]
[ER]
[ERS]
[ERST]
[ERT]
[ES]
[EST]
[ET]
[M]
[MR]
[MRS]
[MRST]
[MRT]
[MS]
[MST]
[MT]
[R]
[RS]
[RST]
[RT]
[S]
[ST]
[T]
// Include namespace system
using System;
/*
   Csharp Program 
   Power set in lexicographic order
*/
public class LexicographicOrder
{
	public void subSequence(String text, String result, int index, int n)
	{
		if (index <= n)
		{
			// Display calculated result
			Console.WriteLine("[" + result + "]");
			for (int i = index; i < n; ++i)
			{
				// Find the subsequence using recursively
				this.subSequence(text, result + text[i], i + 1, n);
			}
		}
	}
	public void findSubSequence(String data)
	{
		int n = data.Length;
		if (n <= 0)
		{
			return;
		}
		// Sort given data sequence
		char[] s = data.ToCharArray();
		Array.Sort(s);
		String text = new String(s);
		// Test
		this.subSequence(text, "", 0, n);
	}
	public static void Main(String[] args)
	{
		LexicographicOrder task = new LexicographicOrder();
		task.findSubSequence("MASTER");
	}
}

Output

[]
[A]
[AE]
[AEM]
[AEMR]
[AEMRS]
[AEMRST]
[AEMRT]
[AEMS]
[AEMST]
[AEMT]
[AER]
[AERS]
[AERST]
[AERT]
[AES]
[AEST]
[AET]
[AM]
[AMR]
[AMRS]
[AMRST]
[AMRT]
[AMS]
[AMST]
[AMT]
[AR]
[ARS]
[ARST]
[ART]
[AS]
[AST]
[AT]
[E]
[EM]
[EMR]
[EMRS]
[EMRST]
[EMRT]
[EMS]
[EMST]
[EMT]
[ER]
[ERS]
[ERST]
[ERT]
[ES]
[EST]
[ET]
[M]
[MR]
[MRS]
[MRST]
[MRT]
[MS]
[MST]
[MT]
[R]
[RS]
[RST]
[RT]
[S]
[ST]
[T]
package main
import "strings"
import "sort"
import "fmt"
/*
   Go Program 
   Power set in lexicographic order
*/

func subSequence(text string, 
	result string, 
	index int,
	n int) {
	if index <= n {
		// Display calculated result
		fmt.Println("["+result+"]")
		for i := index ; i < n ; i++ {
			// Find the subsequence using recursively
			subSequence(text, 
				result + string(text[i]), i + 1, n)
		}
	}
}
func findSubSequence(data string) {
	var n int = len(data)
	if n <= 0 {
		return
	}
	// Sort given data sequence
	s := strings.Split(data, "")
    sort.Strings(s)
    text := strings.Join(s, "")
	// Test
	subSequence(text, "", 0, n)
}
func main() {
	
	findSubSequence("MASTER")
}

Output

[]
[A]
[AE]
[AEM]
[AEMR]
[AEMRS]
[AEMRST]
[AEMRT]
[AEMS]
[AEMST]
[AEMT]
[AER]
[AERS]
[AERST]
[AERT]
[AES]
[AEST]
[AET]
[AM]
[AMR]
[AMRS]
[AMRST]
[AMRT]
[AMS]
[AMST]
[AMT]
[AR]
[ARS]
[ARST]
[ART]
[AS]
[AST]
[AT]
[E]
[EM]
[EMR]
[EMRS]
[EMRST]
[EMRT]
[EMS]
[EMST]
[EMT]
[ER]
[ERS]
[ERST]
[ERT]
[ES]
[EST]
[ET]
[M]
[MR]
[MRS]
[MRST]
[MRT]
[MS]
[MST]
[MT]
[R]
[RS]
[RST]
[RT]
[S]
[ST]
[T]
<?php
/*
   Php Program 
   Power set in lexicographic order
*/
class LexicographicOrder
{
	public	function subSequence($text, $result, $index, $n)
	{
		if ($index <= $n)
		{
			// Display calculated result
			echo("[".$result."]"."\n");
			for ($i = $index; $i < $n; ++$i)
			{
				// Find the subsequence using recursively
				$this->subSequence($text, 
                                   $result.strval($text[$i]), 
                                   $i + 1, $n);
			}
		}
	}
	public	function findSubSequence($data)
	{
		$n = strlen($data);
		if ($n <= 0)
		{
			return;
		}
		// Sort given data sequence
		$s = str_split($data);
		sort($s);
		$text = implode($s);
		// Test
		$this->subSequence($text, "", 0, $n);
	}
}

function main()
{
	$task = new LexicographicOrder();
	$task->findSubSequence("MASTER");
}
main();

Output

[]
[A]
[AE]
[AEM]
[AEMR]
[AEMRS]
[AEMRST]
[AEMRT]
[AEMS]
[AEMST]
[AEMT]
[AER]
[AERS]
[AERST]
[AERT]
[AES]
[AEST]
[AET]
[AM]
[AMR]
[AMRS]
[AMRST]
[AMRT]
[AMS]
[AMST]
[AMT]
[AR]
[ARS]
[ARST]
[ART]
[AS]
[AST]
[AT]
[E]
[EM]
[EMR]
[EMRS]
[EMRST]
[EMRT]
[EMS]
[EMST]
[EMT]
[ER]
[ERS]
[ERST]
[ERT]
[ES]
[EST]
[ET]
[M]
[MR]
[MRS]
[MRST]
[MRT]
[MS]
[MST]
[MT]
[R]
[RS]
[RST]
[RT]
[S]
[ST]
[T]
/*
   Node JS Program 
   Power set in lexicographic order
*/
class LexicographicOrder
{
	subSequence(text, result, index, n)
	{
		if (index <= n)
		{
			// Display calculated result
			console.log("[" + result + "]");
			for (var i = index; i < n; ++i)
			{
				// Find the subsequence using recursively
				this.subSequence(text, result + text.charAt(i), 
                                 i + 1, n);
			}
		}
	}
	findSubSequence(data)
	{
		var n = data.length;
		if (n <= 0)
		{
			return;
		}
		// Sort given data sequence
		var text = data.split('').sort().join('');
		// Test
		this.subSequence(text, "", 0, n);
	}
}

function main()
{
	var task = new LexicographicOrder();
	task.findSubSequence("MASTER");
}
main();

Output

[]
[A]
[AE]
[AEM]
[AEMR]
[AEMRS]
[AEMRST]
[AEMRT]
[AEMS]
[AEMST]
[AEMT]
[AER]
[AERS]
[AERST]
[AERT]
[AES]
[AEST]
[AET]
[AM]
[AMR]
[AMRS]
[AMRST]
[AMRT]
[AMS]
[AMST]
[AMT]
[AR]
[ARS]
[ARST]
[ART]
[AS]
[AST]
[AT]
[E]
[EM]
[EMR]
[EMRS]
[EMRST]
[EMRT]
[EMS]
[EMST]
[EMT]
[ER]
[ERS]
[ERST]
[ERT]
[ES]
[EST]
[ET]
[M]
[MR]
[MRS]
[MRST]
[MRT]
[MS]
[MST]
[MT]
[R]
[RS]
[RST]
[RT]
[S]
[ST]
[T]
#   Python 3 Program 
#   Power set in lexicographic order
class LexicographicOrder :
	def subSequence(self, text, result, index, n) :
		if (index <= n) :
			#  Display calculated result
			print("[", result ,"]",sep="")
			i = index
			while (i < n) :
				#  Find the subsequence using recursively
				self.subSequence(text, 
                                 result + str(text[i]), 
                                 i + 1, n)
				i += 1
			
		
	
	def findSubSequence(self, data) :
		n = len(data)
		if (n <= 0) :
			return
		
		#  Sort given data sequence
		text =''.join(sorted(data)) 
		#  Test
		self.subSequence(text, "", 0, n)
	

def main() :
	task = LexicographicOrder()
	task.findSubSequence("MASTER")

if __name__ == "__main__": main()

Output

[]
[A]
[AE]
[AEM]
[AEMR]
[AEMRS]
[AEMRST]
[AEMRT]
[AEMS]
[AEMST]
[AEMT]
[AER]
[AERS]
[AERST]
[AERT]
[AES]
[AEST]
[AET]
[AM]
[AMR]
[AMRS]
[AMRST]
[AMRT]
[AMS]
[AMST]
[AMT]
[AR]
[ARS]
[ARST]
[ART]
[AS]
[AST]
[AT]
[E]
[EM]
[EMR]
[EMRS]
[EMRST]
[EMRT]
[EMS]
[EMST]
[EMT]
[ER]
[ERS]
[ERST]
[ERT]
[ES]
[EST]
[ET]
[M]
[MR]
[MRS]
[MRST]
[MRT]
[MS]
[MST]
[MT]
[R]
[RS]
[RST]
[RT]
[S]
[ST]
[T]
#   Ruby Program 
#   Power set in lexicographic order
class LexicographicOrder 
	def subSequence(text, result, index, n) 
		if (index <= n) 
			#  Display calculated result
			print("[", result ,"]", "\n")
			i = index
			while (i < n) 
				#  Find the subsequence using recursively
				self.subSequence(text, 
                                 result + text[i].to_s, 
                                 i + 1, n)
				i += 1
			end

		end

	end

	def findSubSequence(data) 
		n = data.length
		if (n <= 0) 
			return
		end

		#  Sort given data sequence
		text = (data.chars.sort.join)
		#  Test
		self.subSequence(text, "", 0, n)
	end

end

def main() 
	task = LexicographicOrder.new()
	task.findSubSequence("MASTER")
end

main()

Output

[]
[A]
[AE]
[AEM]
[AEMR]
[AEMRS]
[AEMRST]
[AEMRT]
[AEMS]
[AEMST]
[AEMT]
[AER]
[AERS]
[AERST]
[AERT]
[AES]
[AEST]
[AET]
[AM]
[AMR]
[AMRS]
[AMRST]
[AMRT]
[AMS]
[AMST]
[AMT]
[AR]
[ARS]
[ARST]
[ART]
[AS]
[AST]
[AT]
[E]
[EM]
[EMR]
[EMRS]
[EMRST]
[EMRT]
[EMS]
[EMST]
[EMT]
[ER]
[ERS]
[ERST]
[ERT]
[ES]
[EST]
[ET]
[M]
[MR]
[MRS]
[MRST]
[MRT]
[MS]
[MST]
[MT]
[R]
[RS]
[RST]
[RT]
[S]
[ST]
[T]
import scala.collection.mutable._;
/*
   Scala Program 
   Power set in lexicographic order
*/
class LexicographicOrder()
{
	def subSequence(
      text: String, 
      result: String, 
      index: Int, 
      n: Int): Unit = {
		if (index <= n)
		{
			// Display calculated result
			println("[" + result + "]");
			var i: Int = index;
			while (i < n)
			{
				// Find the subsequence using recursively
				subSequence(text, 
                            result + text.charAt(i).toString(), 
                            i + 1, n);
				i += 1;
			}
		}
	}
	def findSubSequence(data: String): Unit = {
		var n: Int = data.length();
		if (n <= 0)
		{
			return;
		}
		// Sort given data sequence
		var s: Array[Char] = data.toCharArray();
		// Sort element
		s = s.sorted;
		var text = new String(s);
		// Test
		subSequence(text, "", 0, n);
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var task: LexicographicOrder = new LexicographicOrder();
		task.findSubSequence("MASTER");
	}
}

Output

[]
[A]
[AE]
[AEM]
[AEMR]
[AEMRS]
[AEMRST]
[AEMRT]
[AEMS]
[AEMST]
[AEMT]
[AER]
[AERS]
[AERST]
[AERT]
[AES]
[AEST]
[AET]
[AM]
[AMR]
[AMRS]
[AMRST]
[AMRT]
[AMS]
[AMST]
[AMT]
[AR]
[ARS]
[ARST]
[ART]
[AS]
[AST]
[AT]
[E]
[EM]
[EMR]
[EMRS]
[EMRST]
[EMRT]
[EMS]
[EMST]
[EMT]
[ER]
[ERS]
[ERST]
[ERT]
[ES]
[EST]
[ET]
[M]
[MR]
[MRS]
[MRST]
[MRT]
[MS]
[MST]
[MT]
[R]
[RS]
[RST]
[RT]
[S]
[ST]
[T]
import Foundation;
/*
   Swift 4 Program 
   Power set in lexicographic order
*/
class LexicographicOrder
{
	func subSequence(
  	 _ text: [Character], 
     _ result: String, 
     _ index: Int, _ n: Int)
	{
		if (index <= n)
		{
			// Display calculated result
			print("[", result ,"]");
			var i: Int = index;
			while (i < n)
			{
				// Find the subsequence using recursively
				self.subSequence(text, 
                     result + String(text[i]), i + 1, n);
				i += 1;
			}
		}
	}
	func findSubSequence(_ data: String)
	{
		let n: Int = data.count;
		if (n <= 0)
		{
			return;
		}
		// Sort given data sequence
		var s: [Character] = Array(data);
		// Sort element
		s = s.sorted();
		
		// Test
		self.subSequence(s, "", 0, n);
	}
}
func main()
{
	let task: LexicographicOrder = LexicographicOrder();
	task.findSubSequence("MASTER");
}
main();

Output

[  ]
[ A ]
[ AE ]
[ AEM ]
[ AEMR ]
[ AEMRS ]
[ AEMRST ]
[ AEMRT ]
[ AEMS ]
[ AEMST ]
[ AEMT ]
[ AER ]
[ AERS ]
[ AERST ]
[ AERT ]
[ AES ]
[ AEST ]
[ AET ]
[ AM ]
[ AMR ]
[ AMRS ]
[ AMRST ]
[ AMRT ]
[ AMS ]
[ AMST ]
[ AMT ]
[ AR ]
[ ARS ]
[ ARST ]
[ ART ]
[ AS ]
[ AST ]
[ AT ]
[ E ]
[ EM ]
[ EMR ]
[ EMRS ]
[ EMRST ]
[ EMRT ]
[ EMS ]
[ EMST ]
[ EMT ]
[ ER ]
[ ERS ]
[ ERST ]
[ ERT ]
[ ES ]
[ EST ]
[ ET ]
[ M ]
[ MR ]
[ MRS ]
[ MRST ]
[ MRT ]
[ MS ]
[ MST ]
[ MT ]
[ R ]
[ RS ]
[ RST ]
[ RT ]
[ S ]
[ ST ]
[ T ]
/*
   Kotlin Program 
   Power set in lexicographic order
*/
class LexicographicOrder
{
	fun subSequence(
  	text: String, 
    result: String, 
    index: Int, 
    n: Int): Unit
	{
		if (index <= n)
		{
			// Display calculated result
			println("[" + result + "]");
			var i: Int = index;
			while (i < n)
			{
				// Find the subsequence using recursively
				this.subSequence(text, 
                                 result + text.get(i).toString(), 
                                 i + 1, n);
				i += 1;
			}
		}
	}
	fun findSubSequence(data: String): Unit
	{
		val n: Int = data.length;
		if (n <= 0)
		{
			return;
		}
		// Sort given data sequence
		val s: Array < Char > = data.toCharArray().toTypedArray();
		s.sort();
		var v = "";
		var i: Int = 0;
		// Append text characters into ans    
		while (i < s.count())
		{
			v += s[i];
			i += 1;
		}
		// Test
		this.subSequence(v, "", 0, n);
	}
}
fun main(args: Array < String > ): Unit
{
	val task: LexicographicOrder = LexicographicOrder();
	task.findSubSequence("MASTER");
}

Output

[]
[A]
[AE]
[AEM]
[AEMR]
[AEMRS]
[AEMRST]
[AEMRT]
[AEMS]
[AEMST]
[AEMT]
[AER]
[AERS]
[AERST]
[AERT]
[AES]
[AEST]
[AET]
[AM]
[AMR]
[AMRS]
[AMRST]
[AMRT]
[AMS]
[AMST]
[AMT]
[AR]
[ARS]
[ARST]
[ART]
[AS]
[AST]
[AT]
[E]
[EM]
[EMR]
[EMRS]
[EMRST]
[EMRT]
[EMS]
[EMST]
[EMT]
[ER]
[ERS]
[ERST]
[ERT]
[ES]
[EST]
[ET]
[M]
[MR]
[MRS]
[MRST]
[MRT]
[MS]
[MST]
[MT]
[R]
[RS]
[RST]
[RT]
[S]
[ST]
[T]


Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment







© 2021, kalkicode.com, All rights reserved