Sir interview me web project ke liye kis type ke project se kaam chl sakta h or jada problem na ho. 1. Complete mern stack project. 2. Any simple react project 3. Simple With html,css or javascript. 4. Any dsa project 5. Or any dbms. Inme se konse rakha acha rhega or sirf kitno se kaam ho jayega pls reply.
From this code it seems, "p->next->next = p" is getting executed only once. But it should be executed number of times recursive function is executed. Could you please explain this?
We can simplify his code a little bit if we assume that we have lazy boolean evaluation node *reverse(node *head) { node *p, *q; if(head == NULL || head->next == NULL) return head; p = head; q = p->next; q = reverse(q); p->next->next = p; p->next = NULL; return q; }
sir u have described the function which returns a node ,then how can u simply write return without mentioning any pointer along with it.At last how will we able to know the address of new head??
It is time to iterative approach now Solution based on stack node * reverse(node *head) { node *p, *q, *r; p = NULL; // we intialize pointer to reversed list q = head; // we initialize traversal pointer while(q != NULL) { r = q->next // we save next pointer in list with original order of elements q->next = p; p = q; // In these two lines we perform push operation known from stack q = r; // we get pointer to the next element } return p; }
Because no matter how big the linked list is we always use just 2 pointers , O(2) -> O(1) . In other words the number of pointers required is constant , it doesn't grow in size when the list grows.
If this was in Java it would have been easier than C. It's easier to understand that way. Pointers are difficult sometimes. Kind request is to consider to code in Java alongside C.
I have executed same code which is in video, Its not working. Below code works for sure. reverse(&head1); void reverse(struct Node **head) { struct Node *p,*q;
My solution is non recursive based on stack push operation void reverse(node ** head) { node *p, *q, *r; p = NULL; // Head of reversed list is initially set to NULL q = (*head); // Iterator is set to head while(q != NULL) // We traverse entire list { r = q->next; // We save pointer to next node q->next = p; p = q; //We push current node to the list q = r; //We restore saved node; } (*head) = p; }
this code is not working , next.next (do not do that ). public void ReverseList() { Node prev = null, current = head, next = null; while (current != null) { next = current.next; current.next = prev; prev = current; current = next; } head = prev; }
It is correct. Imagine you have a linked list of two elements: 1 and 2. 1 points to 2 and that is your list. The reverse is 2 and 1. If you want to reverse that, you need to access 2 in order to link it to 1 so your linked list could be 2 and 1. It turns out that 2 is nothing more than 1's next since 2 is following next after 1. So 1->next = 2. 1->next->next = 2 -> next. 1->next->next = 1 => 2 -> next = 1. So now our linked list is 2, 1 where 1 follows 2 ( 2->next = 1).
Great explanation ever! Thank you Also, can you do video on Sort List (Leetcode #148) by using Bottom Up Merge Sort method? No video uses this method to solve for Sort List.
@@sankalanpaulchowdhury8505 what I mentioned is Leetcode #148 using bottom up merge sort technique. Your recommended video is about top down merge sort algo.
Superb explanation Sir.
Here's another approach of reversing a linkedlist recursively-
private static LinkedListNode reverseLinkedList(LinkedListNode start, LinkedListNode prev) {
if (start == null || start.next == null) {
start.next = prev;
return start;
}
LinkedListNode second = start.next;
start.next = prev;
return reverseLinkedList(second, start);
}
Your visualization thing is very helpful. Thank you.
Sir interview me web project ke liye kis type ke project se kaam chl sakta h or jada problem na ho.
1. Complete mern stack project.
2. Any simple react project
3. Simple With html,css or javascript.
4. Any dsa project
5. Or any dbms.
Inme se konse rakha acha rhega or sirf kitno se kaam ho jayega pls reply.
From this code it seems, "p->next->next = p" is getting executed only once. But it should be executed number of times recursive function is executed. Could you please explain this?
it'll execute several of times until the recursive stack don't get empty, its hard to digest but this is how recursive work
Amazing , worth watching, thank you sir , khup madat zali..... Parat ekda dhanyawad..... Banvat rha videos...
Sir....all your videos are so good...you write code first on board and explain in a beautiful way....thank you...Dr.Padmaja.Pulicherla
but if we return q after breaking at if(q==NULL) then how we can get head of reversed list?
if(q==null) it should return p;
perfect :)
We can simplify his code a little bit if we assume that we have lazy boolean evaluation
node *reverse(node *head)
{
node *p, *q;
if(head == NULL || head->next == NULL)
return head;
p = head;
q = p->next;
q = reverse(q);
p->next->next = p;
p->next = NULL;
return q;
}
Please Sir can we change this instruction :
P->next->next =p
By
q->next = p
sir u have described the function which returns a node ,then how can u simply write return without mentioning any pointer along with it.At last how will we able to know the address of new head??
make some changes --
return head;
in both the statements(3rd & 7th)
Try this
ruclips.net/video/S5UByEqe8aM/видео.html
Can you please make solution video for Divide Two Integers. Thank you.
hats off to you sir..you deserve million subscribers.
could you please make one or two videos regarding working of recursions, i.e. like generating binary strings for given no.s etc
It is time to iterative approach now
Solution based on stack
node * reverse(node *head)
{
node *p, *q, *r;
p = NULL; // we intialize pointer to reversed list
q = head; // we initialize traversal pointer
while(q != NULL)
{
r = q->next // we save next pointer in list with original order of elements
q->next = p;
p = q; // In these two lines we perform push operation known from stack
q = r; // we get pointer to the next element
}
return p;
}
This code will not give correct output in computer. For correction We need to return head Pointer from base case then it will work.
need to use a tail variable for deleting the last node from a link list :( please help
Thanks a lot. Really you have the teaching capability. Any one can understand.
NICE SUPER EXCELLENT MOTIVATED
the return expects a node, but your return statement returns nothing..
Try this.
ruclips.net/video/S5UByEqe8aM/видео.html
I don't understand efficiently please sir how i identify the head and null or execute
May I know, Why have you stopped posting videos?
You did not assign head pointer after the reverse...
Appreciate your sharing, It is helpful thought your accent is a bit hard to hear!
At least better than asians from chineseeeee >
🐸
Get over it
how is this a reversed linked list?You have created a loop in the linked list
Try this
ruclips.net/video/S5UByEqe8aM/видео.html
such a gem
is this algorithm valid in c langage ???
Ok, but here the return node* or q refers to NULL until you return p when q==NULL as the base case...So head is NULL which is wrong :)
@@inspiritlinspirit3259
If ( q == NULL){
return p;
}
p is missing in code....
We can also rewrite this function as void and pass head by a pointer
Beautiful algorithm!
What is the role of return after every if statement??
What answer u got for this query
sir you explain really well thanks a lot
Thank you sir
Why the space complexity is 1 in this problem?
Because no matter how big the linked list is we always use just 2 pointers , O(2) -> O(1) . In other words the number of pointers required is constant , it doesn't grow in size when the list grows.
If this was in Java it would have been easier than C. It's easier to understand that way. Pointers are difficult sometimes. Kind request is to consider to code in Java alongside C.
Types of linked list explanation?????????
if(q==NULL) return p;
Copy a list using recursion
please make on flattening of linked list video
I have executed same code which is in video, Its not working.
Below code works for sure.
reverse(&head1);
void reverse(struct Node **head)
{
struct Node *p,*q;
if(*head == NULL)
return ;
p=*head;
q=p->next;
if(q == NULL)
return ;
reverse(&q);
p->next->next=p;
p->next=NULL;
*head = q;
}
make a video without recursion sir by using temp pointer
ruclips.net/video/S5UByEqe8aM/видео.html
Tqqq sir
superb explanation sir
My solution is non recursive based on stack push operation
void reverse(node ** head)
{
node *p, *q, *r;
p = NULL; // Head of reversed list is initially set to NULL
q = (*head); // Iterator is set to head
while(q != NULL) // We traverse entire list
{
r = q->next; // We save pointer to next node
q->next = p;
p = q; //We push current node to the list
q = r; //We restore saved node;
}
(*head) = p;
}
this code is not working , next.next (do not do that ).
public void ReverseList()
{
Node prev = null, current = head, next = null;
while (current != null) {
next = current.next;
current.next = prev;
prev = current;
current = next;
}
head = prev;
}
This is for iterative approach
Wrong explanation, if there is no reverse link exist how p->next->next will link in reverse order.
It is correct. Imagine you have a linked list of two elements: 1 and 2. 1 points to 2 and that is your list. The reverse is 2 and 1. If you want to reverse that, you need to access 2 in order to link it to 1 so your linked list could be 2 and 1. It turns out that 2 is nothing more than 1's next since 2 is following next after 1. So 1->next = 2. 1->next->next = 2 -> next. 1->next->next = 1 => 2 -> next = 1. So now our linked list is 2, 1 where 1 follows 2 ( 2->next = 1).
Try this
ruclips.net/video/S5UByEqe8aM/видео.html
Great explanation ever! Thank you
Also, can you do video on Sort List (Leetcode #148) by using Bottom Up Merge Sort method? No video uses this method to solve for Sort List.
ruclips.net/video/jlHkDBEumP0/видео.html
@@sankalanpaulchowdhury8505 what I mentioned is Leetcode #148 using bottom up merge sort technique. Your recommended video is about top down merge sort algo.
Droan clg se kon kon dekh raha hai ye video....??
very good sir
thanks a lot, sir
love you sir.
where is algorithm???
Linklist polynomial addition pls..c code
DS ke Ravindrababu Ravula :)
usse better bro
circular linklist
Sir can i get the full code of this video ??plzz sir it's urgent
nice video :)
Thanks
Complete step wise explanation with animation. Optimised solution with single iteration.
ruclips.net/video/txqLgAdgyVM/видео.html
Java language seems better..#pls. kind request to continue in Java..if possible...
I'm not so crazy about Java for because of garbage collector
and i dont think that java is good language for teaching or learning programming
Error in your code
Try this 1st method ruclips.net/video/S5UByEqe8aM/видео.html
@@SatyendraJaiswalsattu ok bro
Here you will get 2 approach and you will also submit your code on hackerrank too😊
wrong explanation
Sourav Biswas what's wrong
void push(int data,list *head)
{
list newNode = (list)malloc(sizeof(node));
newNode->data = data;
newNode->link = *head;
*head = newNode;
}
//using iteration
list reverse(list head)
{
list curr, prev;
curr = head;
head= NULL;
while(curr!=NULL)
{
prev= curr;
curr= curr->link;
push(prev->data,&head);
}
return head;
}
i.e good expanation.....
code is wrong. For example you can't write return without specifying variable in a non void function. I like the dude but he choked in this vid.
It’s pseudo code
@@jericho1211 No, code to the left is not psuedo code.
This code will not work. Try it.
first of all , its an algorithm explained brother not code. secondly, the algorithm seems correct.
b
time waste..not worth it
bakwas vedio ..
sir first you learn and then teach . Don't teach what ever you want .
"TIME WASTE"
please dont waste our time like this, Sir...
poor explaination.
ruclips.net/video/S5UByEqe8aM/видео.html
Wrong explanation
why there is not p=null in 2 step at last.
Try this
ruclips.net/video/S5UByEqe8aM/видео.html