Permutation - Return all possible permutations | C++ Placement Course | Lecture 17

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

This lecture is enough to demoralise the beginner coders.

ayushkejriwal
Автор

whenever this tutor comes, he makes me feel that i got the worst brain in the world. He just code without explaining the topic. And vector was not taught before.After every 4-5 videos, there is an abrupt videos like this one in this playlist. Hope they would rework on this

md.ualiurrahmanrahat
Автор

after watching this video me like " Are Kahena Kya chahtee ho? "😂😂

gauravsinghrathore
Автор

It becomes difficult to follow up some codes when someone else teaches jn between, Not like this Sir is bad, But certain topics like vectors and the use of "bits/stdc++.h" have not been taught to us before.
So if you can teach the problems including the old concepts and not including anything new...it would be great help.

jyothishkamal
Автор

Bhaiye we don't even know syntax of vector, please upload that🙏

chiragjani
Автор

the way they are taking the syllabus is like for an person who has studied all the topics at least one time it can never be for beginners.
The video is good enough to demoralize the beginner coders.

Nishant-mjir
Автор

Yeh ek dum jindagi badal gyi, jajbaat badal diye, time badal diya 😂😂

SurajYadav-qbyu
Автор

Didi is best actually 😊😊 we learn things easily if she teaches

signaturecomics
Автор

for those people who dont understand the vector part yet and still want to attempt this problem, heres a hint, think of the array as an string and print out all the permutations using the previous method taught earlier....

heres the code for this:
#include<bits/stdc++.h>

using namespace std;


void permute(string s, string s1)

{
if(s.size()==0)
{
for(int i=0;i<s1.size();i++)
{
cout<<s1[i]<<" ";
}
cout<<endl;
return;
}

for(int i=0;i<s.size();i++)
{
char ch=s[i];

string s2=s.substr(0, i)+s.substr(i+1);
permute(s2, s1+ch);
}



}



int main()
{
int n;cin>>n;
int arr[n];string s, s1;
for(int i=0;i<n;i++)
{
cin>>arr[i];
int x=arr[i];
s += to_string(x);
}

permute(s, s1);




}


not the correct waty but it works.... xD xD.

pratyayamrit
Автор

In the 2nd code pay attention that the vector is taken as a copy rather than using & references as input(vector a) in function due to which 2nd swap is not necessary

Shobhitchoudhary
Автор

vector has not been taught yet !! and we are working on it, so kindly help us with a vector lecture.🙏

ankitgupta
Автор

first question alternative to vector
#include<bits/stdc++.h>
using namespace std;

void Perms(int arr[], int n, int idx){
if(idx==n-1){
for(int i=0;i<n;i++){
cout<<arr[i]<<" ";
}
cout<<endl;
return;
}

for(int i=idx;i<n;i++){
int temp=arr[i];
arr[i]=arr[idx];
arr[idx]=temp;
Perms(arr, n, idx+1);
temp=arr[i];
arr[i]=arr[idx];
arr[idx]=temp;

}
return;
}



int main()
{
cout<<"Enter size:"<<endl;
int n;
cin>>n;
int arr[n];
cout<<"Enter elements"<<endl;
for(int i=0;i<n;i++){
cin>>arr[i];
}
Perms(arr, n, 0);
}
😄😄

sameeppaudel
Автор

Permutation without using vectors :

/* logic : fix one element at first positon and find permutation of others
(by recusively fixing others too one by one then printing array)

remember to roll back chages too for next recursion ie again swapping at last
we do roll back changes as we provide above logic for our original array only

*/



#include<iostream>

using namespace std;

void permute(int arr[], int index, int n)
{
if( index == n-1)
{
for(int i=0;i<n;i++)
cout<<arr[i]<<" ";

cout<<endl;

return;
}


for(int i=index;i<n;i++)
{
swap(arr[i], arr[index]);
permute(arr, index +1, n);
swap(arr[i], arr[index]);
}

return;
}

int main()
{
int arr[]={1, 2, 3};
int n =sizeof(arr)/sizeof(arr[0]);

permute(arr, 0, n);

return 0;
}

sunnyrawat
Автор

Let Me Clear Some Doubts :-

1. Why we need to swap i when i==idex?
-> we need that combination for at least one time. So It Doesnt Matter You swap or not for first time. but if you skip recursion at first time u will end up missing permutations. So We need to start from i = idx.

2. Why We need to sort when using in-built method?
-> next_permutation function finds out first index where a[i]<a[i+1]. then it swap i with i+1 and put new i +1 to next sort order.

3. Why There is No second swap in duplicates code?
-> Notice that here vector a passed as value and not by address, so it doesnt matter now that you swap it back or not, because it is not used in any other recursion function. Try to remove second swap with change &a to a from permute function from first code and see result still same.

HAPPY LEARNING :)

rutvikrana
Автор

i feel so confused.. they directly jump to coding part without explaining the algo properly . a stack floe diagram or flow chart is well appreciated for understanding these type of problems

ishitavashisht
Автор

On time stamp: 14:10
line number 14 :- we have to backtrack the swap operation ( swap (a, ans, idx);
)

Mandeepsingh-jocf
Автор

animation ✔ BGM ✔ graphics ✔ unnecessary beats ✔asmr level mic quality ✔
Explanation ❌ rather Copy paste code ✔

pryansh_
Автор

i think tthat his tutor feels that everyone know the logic by explaining 2 lines without any dry run or explaining code or how recursion works ....
it is same feeling as when someone ask you to copy your answer in exam without understading properly what are you writing ..
i feel that it should be improved..

sunnyrawat
Автор

Your explanation is very much complex.

mehedishuvo
Автор

NOTES are a must, especially for this lecture as it was not explained in detail, we can analyse the code to gain insights! pls make notes available as soon as possible

hargunanikhushi