CPP

CPP

Permutations has 9 Questions

What is meant by permutation in c++?

To find all the values in the range
To find all the combination of the range
Both a & b
None of the mentioned
How the different permutations are ordered in c++?

Compare lexicographicaly to each other elements
By finding the highest element in the range
By finding the lowest element in the range
None of the mentioned
Pick out the correct statement about permutation.

If the function can determine the next higher permutation, Returns false.
If the function can determine the next higher permutation, Returns true.
If the function can't determine the next higher permutation, Returns true.
None of the mentioned
What is the output of this program?
  1.     #include 
  2.     #include 
  3.     using namespace std;
  4.     void string_permutation( string& orig, string& perm )
  5.     {
  6.         if (orig.empty())
  7.         {
  8.             cout<<perm<<endl;
  9.             return;
  10.         }
  11.         for (int i = 0; i < orig.size(); ++i)
  12.         {
  13.             string orig2 = orig;
  14.             orig2.erase(i, 1);
  15.             string perm2 = perm;
  16.             perm2 += orig.at(i);
  17.             string_permutation(orig2, perm2);
  18.         }
  19.     }
  20.     int main()
  21.     {
  22.         string orig = "ter";
  23.         string perm;
  24.         string_permutation(orig, perm);
  25.         return 0;
  26.     }

ter
ert
ret
Returns all the combination of ter
What is the output of this program?
  1.     #include 
  2.     using namespace std;
  3.     int array[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
  4.     void swap(int x, int y)
  5.     {
  6.         int temp = array[x];
  7.         array[x] = array[y];
  8.         array[y] = temp;
  9.         return;
  10.     }
  11.     void printArray(int size)
  12.     {
  13.         int i;
  14.         for (i = 0; i < size; i++)
  15.             cout << array[i] << " ";
  16.         cout << endl;
  17.         return;
  18.     }
  19.     void permute(int k, int size)
  20.     {
  21.         int i;
  22.         if (k == 0)
  23.             printArray(size);
  24.         else
  25.         {
  26.             for (i = k - 1;i >= 0;i--)
  27.             {
  28.                 swap(i, k - 1);
  29.                 permute(k - 1, size);
  30.                 swap(i, k - 1);
  31.             }
  32.         }
  33.         return;
  34.     }
  35.     int main()
  36.     {
  37.         permute(3, 3);
  38.         return 0;
  39.     }

0 1 2 1 0 2
0 2 1 2 0 1
2 1 0 1 2 0
All of the mentioned
What is the output of this program?
  1.     #include 
  2.     #include 
  3.     #include 
  4.     using namespace std;
  5.     void show(const vector<int>& vi)
  6.     {
  7.         for (size_t i = 0; i < vi.size(); ++i)
  8.             cout << vi[i];
  9.         cout << endl;
  10.     }
  11.     int main()
  12.     {
  13.         vector<int> vi;
  14.         vi.push_back(3);
  15.         vi.push_back(5);
  16.         vi.push_back(5);
  17.         sort(vi.begin(), vi.end());
  18.         show(vi);
  19.         while(next_permutation(vi.begin(), vi.end()))
  20.             show(vi);
  21.         return 0;
  22.     }

355
535
553
All of the mentioned
What is the header file for vector permutation?

vector_permutation.h
vector_perm
< algorithm >
vector_permutation
How many parameters are required for next_permutation?

1
2
2 or 3
3
What is the output of this program?
  1.     #include 
  2.     #include 
  3.     #include 
  4.     using namespace std;
  5.     void Display(const vector<int>& vi)
  6.     {
  7.         for (size_t i = 0; i < vi.size(); ++i)
  8.             cout << vi[i];
  9.         cout<<endl;
  10.     }
  11.     int main()
  12.     {
  13.         vector<int> vi;
  14.         vi.push_back(3);
  15.         vi.push_back(5);
  16.         sort(vi.begin(), vi.end());
  17.         Display(vi);
  18.         while(next_permutation(vi.begin(), vi.end()))
  19.         Display(vi);
  20.         return 0;
  21.     }

3 5
5 3
Both a & b
None of the mentioned