For all those who are wondering how vectorv[n] became a 2D vector this comment is for you !!! It creates a static array of N vectors of the first type i.e. v[0] is now a whole new and different vector than v[1] which is totally different than v[2] and so on. If you want to push a value into the 1st vector that is v[0] , you will do it by v[0].push _ back(val) . To access that element you will call it by v[0][0] (kind of a 2d matrix, isn't it?!). So, basically it is an array of initially empty vectors to which you can add elements. These are very useful while you want to implement graphs where each node has it's own vector and the nodes to which it is joined are pushed into that particular node's vector. I hope you get the point!
Thanks bhaiya.......we understand that the pace of course will decrease due to workload and Unacademy course too......but please don't let the consistency break Thanks again
vector v(N) creates a vector of integers with size N. This means that the vector v will have N elements, all initialized to the default value of the integer type (0). On the other hand, vector v [N] creates an array of N vectors. This means that you have an array of vectors, where each vector can have its own size and elements. In summary, vector v(N) creates a single vector of size N, while vector v [N] creates an array of N vectors.
00:04 Graph is a type of data structure. 02:19 Understanding the graph and its implications 06:27 Weighted and unweighted graph 08:44 Understanding cyclic graphs and their characteristics 13:22 Zero was invented and is globally recognized. 15:48 The video discusses various topics including the concept of free horse ads and the importance of Azhar and Zero collections. 20:16 The direction determines the path of the graph. 22:28 Print the list mentioned in the video 27:13 Create a graph using the given data 29:04 This is about columns and development bodies juice.
Most awaited topic kbhi kbhi lg rha tha beech mai bhaiya ab saare topics nhi krva payenge bcz of unacademy but this video bhaiya keep it up!! with your #imaandaari
Time and space complexity for adjacency matrix is O(n^2) where n is the no of vertices. while for adjacency list time complexity is O(m) and space complexity is O(n+m) where n is no of vertices and m is no of edges.
TC of print will be O(n*x) Because there are 'n' number of keys in the map and suppose that every node has an edge with 'x' nodes therefore we are traversing x times for every node therefore time complexity should be O(n*x)
@@RiteshKumar-lv6rf so is it a vector of lists? list of vectors? could you please forward a link that teaches the concept behind using the [ ] operator with data structures like vectors? Thank you
@@zohebahmad9633 vector Use of round brackets (n) decides the space of the 1-D vector ... Use of square brackets [n] decides the number of arrays in the vector, so actually ... vector ans [n] is a vector (synonym: list) of n lists (synonym: arrays) What i don't.. oh i got it We can make a 2D matrix using vector of vector, vector of arrays, arrays of arrays, and an unorder_map < T, list > and an ordered map < T, list > where T is from that 25:54 Typename which may later carry any data type
We can make a 2D matrix using vector of vector, vector of arrays, array of arrays, and an unorder_map < T, list > and an ordered map < T, list > where T is from that 25:54 Typename which may later carry any data type
i like ur videos but ur pace is very high u will talk about code like a fast running train and its not clear sometimes which demotivate me pls decrease ur speed
Bhaiya Time and space complexity of addEdge and printAdjList are O(1), O(N^2) and O(N^2),O(1) respectively as in addEdge function we are pushing back in unordered map's vector and both push_back and unordered map insertion takes time complexity of O(1) but here we are using space just like a 2D vector thus addEdge Time and space complexity is O(1), O(N^2) and in printAdjList function we are traversing whole map i.e. whole 2D vector and no space is used while doing this thus printAdjList Time and space complexity is O(N^2),O(1)
tc for addedge : O(m) tc for print : O(n^2) according to me sc must be O(1) as both of them use no extra space pls correct me if im wrong about the space complexity
the space will be n+m as the size of outer vector is set according to n and then sum of increases in size of vectors at each node equals to m so i think O(n + m)
concise approach vector printAdjacency(int n, int m, vector & edges) { vector ans(n); for(int i = 0; i < n; i++) { ans[i].push_back(i); } for(vector vect : edges) { int u = vect[0]; int v = vect[1]; ans[u].push_back(v); ans[v].push_back(u); } return ans; }
Hello is there any mistake while creating a function void addEdge where you are saying first edge and second edge. So my question is that it is number of edges(u) and number of vertex(v) or what?? time 20:07. Please clear the doubt.
I am having a doubt , since ans is initialised as 1D vector ans(n), then how we are accesing it as 2D vector at the end i.e., ans[i][j]?? Please help in clearing my concept
The description says about backtracking but the video is on graph and its implementation. Also the backtracking videos ended way too soon. Bhaiya can we practise more questions on backtracking??
Bhaiya I have facing some problem on printing when I try to print I get this type of printing 4->3,0, 0->1,4, 1->0,2,3, 2->1,3, 3->2,1,4, At first 4 is print then 0,1,2,3 print Why I get this type of print . Any one Suggest me
For all those who are wondering how vectorv[n] became a 2D vector this comment is for you !!!
It creates a static array of N vectors of the first type i.e. v[0] is now a whole new and different vector than v[1] which is totally different than v[2] and so on. If you want to push a value into the 1st vector that is v[0] , you will do it by v[0].push _ back(val) . To access that element you will call it by v[0][0] (kind of a 2d matrix, isn't it?!). So, basically it is an array of initially empty vectors to which you can add elements. These are very useful while you want to implement graphs where each node has it's own vector and the nodes to which it is joined are pushed into that particular node's vector.
I hope you get the point!
Bhai aapne mera dimaag kharaab hone se bcha liya thankyouu.🥰
thankssssss
bhai mere dimag ka dahi hone se bacha lia tune
thank you so much
thanxxx
Thanks bhaiya.......we understand that the pace of course will decrease due to workload and Unacademy course too......but please don't let the consistency break
Thanks again
Babbar Sir Plz🙏 continue adding notes 📝 as u were uploading previously becoz it makes more fast to understand video and also helps in revision.
Khud kuch toh karle
hamesha bhikh magna jaruri hai
@@tejasweekumarsingh4368 maine 2 register bhar diye likh likh k approach, code wagera
practice k samay kaam aata hai
apna notes khud se bnana chahiye
@@shiroyasha69 bhai drive ka link bhej de upload krke.
@@shiroyasha69 mera 4th register khtm hone wla hai😂
@@The_Shubham_Soni mere total 4 bne course khtm lrne k baad
vector v(N) creates a vector of integers with size N. This means that the vector v will have N elements, all initialized to the default value of the integer type (0).
On the other hand, vector v [N] creates an array of N vectors. This means that you have an array of vectors, where each vector can have its own size and elements.
In summary, vector v(N) creates a single vector of size N, while vector v [N] creates an array of N vectors.
Thanks bro
सर आपकी महेनत को सलाम हे सर आपकी चैनल से बहुत कुछ सीखना मिलता है ।👏👏😇😇😇😇😇😇😇😇💗 सर मेरी तरफ से आपकी वीटीयो को ⭐⭐⭐⭐⭐
00:04 Graph is a type of data structure.
02:19 Understanding the graph and its implications
06:27 Weighted and unweighted graph
08:44 Understanding cyclic graphs and their characteristics
13:22 Zero was invented and is globally recognized.
15:48 The video discusses various topics including the concept of free horse ads and the importance of Azhar and Zero collections.
20:16 The direction determines the path of the graph.
22:28 Print the list mentioned in the video
27:13 Create a graph using the given data
29:04 This is about columns and development bodies juice.
Most awaited topic kbhi kbhi lg rha tha beech mai bhaiya ab saare topics nhi krva payenge bcz of unacademy but this video bhaiya keep it up!! with your #imaandaari
time compl. for addEdge = O(m) and printing = O(n*m) jitna maine samjha abhi tak. Space complexity = O(m+n)
I am just speechless ...........Your course is just amazing bhaiya ...KEEP IT UP
Can you solve my doubt ? Does this course is sufficient and every concept of dsa ?
@shreeramtiwari6700 This is sufficient for making your concepts clear
@shivanshir7723 is it sufficient for cracking placements?
I watched both two ads, so that i contribute a lit bit to his income. amazing content.
Lmao, he has already earned more than enough.
Time and space complexity for adjacency matrix is O(n^2) where n is the no of vertices. while for adjacency list time complexity is O(m) and space complexity is O(n+m) where n is no of vertices and m is no of edges.
why space is n+m?
i think it will be m+m, right@@parthhh3589 ? because we are storing each edge twice for all the nodes connected.
Thank you bhaiya a lot!
On lecture 85 with full motivation !
0:10 did anyone notice the graph heading written in tricolor?
he always does that with every heading
tune kya kar liya notice kar ke
T.C - > O(N+E) where N -> time taken to visiting nodes, E -> for travelling through adj nodes
S.C -> O(N+E)
I think the Time Complexity would be O(E) where m denotes the number of edges in a graph as we are only using one for loop in the int main function
Greatest Video in UA-cam this is really true
Most awaited topic
Thanks sir 🙇♂
Thanks a lot bhaiya. Koi doubt nahi hai this is the best DSA course on yt
yesa
Bahut behtarin tarikese se sikhaya he. Great 👍
nice
For AdjList:-
Add Edge T.C: O(m) and S.C: O(n+m)
Print Edge T.C: O(n*m) and S.C: O(1)
space complexity of adding a single edge is o(1) while creating a graph is o(n+m)
@CodeHelp - by Babbar can tell us the difference between vectorans[ n ] ;and vector ans( n );
vector(n) is size of vector
but vector[n] is array of n vectors
@@082_harshitshukla4 oh okay thanks Harshit😇
@@082_harshitshukla4 thank bro for clearing my doubt❤
nice sir maza a gaya ekdum asani se samaj aya subkuch ...ekdum badhiyaa..thanku and love u sir...
time complexity: in printing edges o (n*m) in adding edges o(m) .. in both cases space complexity o(m)
T.C of adding edges = O(m) , S.C of adding edges = O(m)
T.C of printing edges = O(n*m) , S.C of printing edges = O(1)
much much respect for you what you have been doing.
last vale code me vectoradj(n) ; ke baad ka kuch samajh nahi aaya why we put adj[i] me pushback ?? why loop range ans(i).size();
bhai upar jo ans create kra hai vo vector nhi array of vector hai isliye har index pr ek vector hoga, that's why ans[i].size();
samagh aaya bhaiya. Thank you bhaiya .
but ans to galat aara h
AddEdge: TC = O(1), SC = O(1)
Print : TC = O(2*m), SC = O(1)
TC of print will be O(n*x)
Because there are 'n' number of keys in the map and suppose that every node has an edge with 'x' nodes therefore we are traversing x times for every node therefore time complexity should be O(n*x)
what is 28:04 , vector ans[n]; is ans a 1d vector or 2d
this is a vector which is containing "n" number of array. (for every node there is one array storing its neighbors)
basically this is a 2D vector.
32:28 line 2 m vector ans[n] 1-d array h lekin line 18 m usey as a 2-d array use kr rhe hai, how??
it is list denoted by []
@@RiteshKumar-lv6rf so is it a vector of lists? list of vectors? could you please forward a link that teaches the concept behind using the [ ] operator with data structures like vectors? Thank you
@@zohebahmad9633 vector
Use of round brackets (n) decides the space of the 1-D vector ...
Use of square brackets [n] decides the number of arrays in the vector, so actually ...
vector ans [n] is a vector (synonym: list) of n lists (synonym: arrays)
What i don't.. oh i got it
We can make a 2D matrix using vector of vector, vector of arrays, arrays of arrays, and an unorder_map < T, list > and an ordered map < T, list >
where T is from that 25:54
Typename which may later carry any data type
We can make a 2D matrix using vector of vector, vector of arrays, array of arrays, and an unorder_map < T, list > and an ordered map < T, list >
where T is from that 25:54
Typename which may later carry any data type
confused 🤡
vector < vector < int >> printAdjacency(int n, int m, vector < vector < int >> & edges) {
vectorans(n);
for(int i=0;i
Bhai meri to gand fat gai code dekh kar 😂
sch main yrr ye kya kiya acha se bataya bhi nii
THANK YOU SIR, IT'S IIT MADRAS MATH SYLLABUS ❤
vectoradj(n);
for(int i=0;i
i like ur videos but ur pace is very high u will talk about code like a fast running train and its not clear sometimes which demotivate me pls decrease ur speed
Right
Yes u are righ
Bade badmosh ho ap toh free course me bhi gya pel dete ho
@@Strcsds54691 lmao
😂😂😂@@Strcsds54691
Bhaiya Time and space complexity of addEdge and printAdjList are O(1), O(N^2) and O(N^2),O(1) respectively as in addEdge function we are pushing back in unordered map's vector and both push_back and unordered map insertion takes time complexity of O(1) but here we are using space just like a 2D vector thus addEdge Time and space complexity is O(1), O(N^2) and in printAdjList function we are traversing whole map i.e. whole 2D vector and no space is used while doing this thus printAdjList Time and space complexity is O(N^2),O(1)
#aptitude & resonaning 🙏🏾🙏🏾
we want aptitude plz babbar bhaiya
tc for addedge : O(m)
tc for print : O(n^2)
according to me sc must be O(1) as both of them use no extra space
pls correct me if im wrong about the space complexity
the space will be n+m as the size of outer vector is set according to n and then sum of increases in size of vectors at each node equals to m so i think O(n + m)
@@cybetheusofficial but i meant that no extra space is used so the space is constant O(1)
babbar bhaiya thoda samjha diya kro na ki array of vectors banaya h. Kitni problem hui kya batau!
//Implementation of graph
#include
using namespace std;
class graph
{
public:
unordered_map adj;
void addEdge(int u, int v, bool direction)
{
adj[u].push_back(v);
if(direction == 0)
{
adj[v].push_back(u);
}
}
void printAdjList()
{
for(auto i : adj)
{
cout
bhai next videos k ebhi bhej de code yarr]
Insta use krte ho???
@@_kucial_ yes I do .. @skyquake._
@@whatsnext7778 next kaunsa ?
@@The_Animated_Spirit garapgh itna enough h
time : O(E), space : O(V+E)
here u asked number of nodes also, for what purpose u asked nodes, as I didn't saw that variable used in program anywhere
32:47 why ans[i][j] is used why not only ans[i] is used please explain me why j is used ?
can anyone tell me where are the codes of graph series as i am not able to find them in gihub link provided.?
Loved the attitude and pace of video. Generally UA-cam videos are long and covering only single topic.
Bahut time se wait kar raha tha 🤩
concise approach
vector printAdjacency(int n, int m, vector & edges) {
vector ans(n);
for(int i = 0; i < n; i++) {
ans[i].push_back(i);
}
for(vector vect : edges) {
int u = vect[0];
int v = vect[1];
ans[u].push_back(v);
ans[v].push_back(u);
}
return ans;
}
Thank You so Much BHRATA SHREE !!!!!!!
t.c for addition o(1) t.c for print o(n*m)
space o(n+m).......
Thanks bhaiya for efforts ♥️♥️♥️♥️
time complexity: O(m+n*n) space complexity: O(n*n) aur bhaiya maza aa raha hai
Jai ho babbar bhai ki 👏
Hello is there any mistake while creating a function void addEdge where you are saying first edge and second edge. So my question is that it is number of edges(u) and number of vertex(v) or what??
time 20:07. Please clear the doubt.
Sir pls decrease your speed during code session and pls explain the code after execution pls🙏🙏🙏
@CodeHelp - by Babbar
Bhaiya Adjancy Matrix Implemented.
int n,m;
cin >> n >> m;
vector ans(n,vector(m,0));
for(int i=0;i> u >> v;
ans[u][v] = 1;
}
for(int i=0;i
I think it should be vector ans(n,vector(n,0));
in the second line bcoz it is n*n matrix. But good solution
@@shresthbhakta7337 yaa but it can be implemented
Thank you bhayya 🙏🙏🙏
Absolutely amazing series ❤️
//tc - O(n*e) - where e is the edge of each node
//sc - O(m*n)
Can you plz explain?
14:56 Adjacency matrix++
Very well explained!! Thank you :)
Anybody can lemme know
Why we use vector in adjacency matrix?
we are given all the edges in edges matrix so all the edges are stored in vectorans remember those are multiple vectors .
I am having a doubt , since ans is initialised as 1D vector ans(n), then how we are accesing it as 2D vector at the end i.e., ans[i][j]?? Please help in clearing my concept
vector ans[n];
Bro this is a 1D vector but this is a vector of arrays
Each row is an array and number of rows is n.
I hope you got it..
TC -> O(n*m)
SC -> O(n*m)
Right ▶️
what is difference between vectoradj(n) and vector adj ? because I got error when I use vector adj in this code .
Time complexity for adding edge in the adjaceny list is O(1). I dont know why many people are commenting O(m).
Thank you Sir👍🏼
Graph series DSA codes are not uploaded
The description says about backtracking but the video is on graph and its implementation. Also the backtracking videos ended way too soon. Bhaiya can we practise more questions on backtracking??
Love Babar 450 mein se wo, questions nikaalo aur GFG pe dekho
bhaiya humne nodes enter krwaya uska kam kya h.?
bina n k bhi code chal rha h.
GitHub me codes nhi mil rhe hai graph ke ??
Graphs padhne ke liye ..heaps aur hashmap anaa chiye kya ....only tree tak padhne ke baad direct graph dekh skte hai kya..?
Ha
Thanks sir
but ans to galat aara h
24:00 why we have taken no of nodes as input in implementation part, we even don't use it .. ?
yes we can discard it
but at times we also need no of nodes count like in vector implementatiiion we need it
so thats come handy there
Ab mzza aega.....bhiya Hashmap m question nhi karwaye h.....ek video uska bna dijiye n❤️
adjacency matrix impplemented ++ && TC is O(N+E) SC is O(n).
sir,ham bina degree k software company me kaam kar sakte hai jaisi ki google,microsoft,amazon.......
Thank you so much bhaiya this was best graph explanation
last wale question me directly nhi bna skte kya adj list without storing neighbours ?
Thank you
Thanks for the amazing video... 🔥🔥
starting graphs today
Thanks a lot for this awesome content bhaiya
Ans[5] is 1-D , if 0,3 push_back kiya to 0,2 push_back karne pe overwrite ho jaega , or fir ans[I][j] kaise access kr sakte hai 1-d hai to
It vector of array
Just like
Int a[n];
Vectora[n];
a small correction, i think there should be vector ans(n) in code and after correction also it is passing the test case and i think might help someone
looks good as you debug live
BOSS OF CODE
Great explaination
Worthy content ❤️
Bhaiya samj aa gaya
Suppose we have given nodes in this format then how we can implement 12,34,32,21,7,3 .
Amazing video 🔥
Thanks a lot bhaiya.....RESPECT++;
I did not understand this line for
(auto i: adj)
{
for(auto j:i.second)
Bhaiya I have facing some problem on printing when I try to print I get this type of printing
4->3,0,
0->1,4,
1->0,2,3,
2->1,3,
3->2,1,4,
At first 4 is print then 0,1,2,3 print
Why I get this type of print .
Any one
Suggest me
it is unordered map so your keys of map can come in any order
Thanks u❤
Quality content👌
Thankyou Sir❤
Sir, plz upload the codes of graph series lecture...
What is the use of 'n' here? n is not used in the program 😯
14:20 / 33:28
awesome
best as usual!!!