Q1. Consider the problem of generating all the possible permutations of length n. For example, the permutations of length 3 are: {1,2,3}, {2,1,3},{2,3,1}, {1,3,2}, {3,1,2}, {3,2,1}. In this question, you will provide:
b) Well documented pseudocode of a non-recursive algorithm that computes all the permutations of size n. The only data structure allowed is a stack (you may use maximum up to two stacks). Any other memory usage should be O(1). Calculate the time complexity of your algorithm using the big-Oh notation. Show all calculations
Note: Here i am Providing pseudocode of a non-recursive algorithm using Stack for generating all the possible permutations of length n and i am also provided java program for better understanding.

Copiable code:
Algorithm findPermutations(n)
Input: n is integer that represents length of the permutation
Output: Displaying all possible permutations
startStr ← "";
//create inital string of length n
for i: 1 to n do
startStr ← startStr+ "" + i
end for
// Create a stack using to store permutations
Stack<String> stack;
// Add first characeter of the startStr into stack
stack.push(String.valueOf(startStr.charAt(0)));
// Add all the characters into queue for permutations
// do for every character of the specified string
for i ← 1 to n do
/* consider previously constructed stack
* permutation one by one*/
for x ← stack.size() – 1 to 0 do
//remove current stack permutation
//from the stack
String str ← stack.remove(x);
/*Insert next character of the specified string
* in all possible positions of current stack
* permutation. Then insert each of these
* newly constructed string in the list*/
for y ← 0 to str.length() do
/*Please note that String concatenation*/
stack.push(str.substring(0, y) +
startStr.charAt(i) +
str.substring(y));
end for
End for
End for
//Print All permutations of the string length n
Print(stack)

Screenshots of the java program:


Sample output:

Code to copy: Generat_All_Permutations.java
import java.util.Scanner;
import java.util.Stack;
public class Generat_All_Permutations
{
/*function name: permutations
* parameters: n- size
* non-recursive algorithm that computes all
* the permutations of size n
*/
public static void findPermutations(int n)
{
String startStr = "";
//create inital string of length
n
for (int i = 1; i <= n;
i++)
{
startStr += "" +
i;
}
// create an empty Stack to store
permutations
// and initialize it with first
character of the string
Stack<String> stack = new
Stack<>();
stack.push(String.valueOf(startStr.charAt(0)));
// do for every character of the
specified string
for (int i = 1; i < n;
i++)
{
/* consider
previously constructed stack
* permutation
one by one(we're iterating
* backwards in
the list to avoid
*
ConcurrentModificationException)*/
for (int x =
stack.size() - 1; x >= 0; x--)
{
//remove current stack permutation
//from the stack
String str = stack.remove(x);
/*Insert next character of the specified
string
* in all possible positions of current
stack
* permutation. Then insert each of these
* newly constructed string in the list*/
for (int y = 0; y <= str.length(); y++)
{
/*Please note that String
concatenation*/
stack.push(str.substring(0,
y) +
startStr.charAt(i) +
str.substring(y));
}
}
}
//call method to print
permutations
printPermutations(stack);
}
public static void
printPermutations(Stack<String> stack)
{
// Print All permutations of the
string length n
while (!stack.isEmpty())
{
// remove
current partial permutation from the stack
String str =
stack.pop();
System.out.print("{");
for (int k = 0;
k < str.length(); k++)
{
if (k == str.length() - 1)
System.out.print(str.charAt(k) + "} ");
else
System.out.print(str.charAt(k) + ",");
}
}
}
/* program to generate all permutations of a
String
* using single Stack and non-recursive
*/
public static void main(String[] args)
{
//Scanner object to read N
value
Scanner sc=new
Scanner(System.in);
//Prompt n value
System.out.print("Enter Length of
the starting String: ");
int n = sc.nextInt();//read n
value
System.out.println("\nAll
permutations: ");
//call method findPermutations
to
//print all permutations
findPermutations(n);
}
}
Q1. Consider the problem of generating all the possible permutations of length n. For example, the...
. Consider the problem of generating all the possible permutations of length n. For example, the permutations of length 3 are: {1,2,3}, {2,1,3},{2,3,1}, {1,3,2}, {3,1,2}, {3,2,1}. Write a Well documented pseudocode of a non-recursive algorithm that computes all the permutations of size n. The only data structure allowed is a queue. Any other memory usage should be O(1). Calculate the time complexity of your algorithm using the big-Oh notation. Show all calculations. (The code should be written in Java!!)
Write an algorithm for generating all the permutations of(1,2,3,...,n) exactly once.
python code,please!
Task 3:N ns Brute For In mathematics, the notion of permutation relates to the act of arranging all the members of a set into some sequence or order, or if the set is already ordered, rearranging (reordering) its elements, a process called permuting. The number of permutations on a set of n elements is given by n! (Read as n factorial). For example, there are 2!2 x 1- 2 permutations of 11,2), 2,1) and 3!-3x2x16 permutations of (1,2,3),...
Q2. Answer the following questions assignment, you will develop a well-documented pseudocode that generates all possible subsets of a given set T (i.e. power set of T) containing n elements with the following requirements: your solution must be non-recursive, and must use a stack and a queue to solve the problem. For example: ifT- {2, 4, 7,9; then your algorithm would generate: U, t2), (4;, {7), {9;, 12,4), 12,7;, 12.9;, 14,7), 14,9), 17,9;, ...etc. (Note: your algorithm's output need not...
Backtracking is a computing algorithm using stack to “remember” user-generated events when using a program. A user event may be “pressing the Enter key on keyboard” or “clicking a mouse button”. Stack is a data structure with the Last-In-First-Out property (LIFO). If we push the aforesaid user events into a stack, a computer program using that data structure can “rewind” user events by popping them out of stack one at a time. This backtracking feature is available as Edit ->...
This assignment is comprised of 3 parts: All files needed are located at the end of the directions. Part 1: Implementation of Dynamic Array, Stack, and Bag First, complete the Worksheets 14 (Dynamic Array), 15 (Dynamic Array Amortized Execution Time Analysis), 16 (Dynamic Array Stack), and 21 (Dynamic Array Bag). These worksheets will get you started on the implementations, but you will NOT turn them in. Do Not Worry about these, they are completed. Next, complete the dynamic array and...