Data Structures using C Part 29 - Adjacency List Representation of Graph in c programming

preview_player
Показать описание
Adjacency List Representation of Graph in c programming :

ankpro
ankpro training
C#
C sharp
Bangalore
Rajajinagar
Selenium
Coded UI
Mobile automation testing
Mobile testing
JQuery
JavaScript
.Net
C
C++
Components of the .Net framework
Hello World
Literal
Keywords
Variable
Data types
Operators
Branching
Loops
Arrays
Strings
Structures
Enums
Functions
Рекомендации по теме
Комментарии
Автор

After finding so many videos about the Adjacency list i am not able to understand from them. Your This video is just amazing And you clear my all doubt. All other are representing this Program in the cpp with the help of the vector which is not worth it in the data structure. Thank you man for making this video.

chillxstreams
Автор

Best explanation of adjacency list on you tube👍

yogeshrawat
Автор

Great Explanation Sir,
I suppose this is a directed graph, for ex: when we will traverse the graph we have 0(src) -> 1(dest) but not 1(src) to 0(dest)

meenakshihattewar
Автор

Great video..really helped me. One query, couldn't we have used the array to store the vertices data itself? There could have been another 'int' variable in 'adjlist' and while initialising the array in main function we could have the stored vertices value (0, 1, 2 and so on) in the variable?

soumikdc
Автор

Thank you so much for the awesome tutorial!
God bless you!
:):):)

shankarghimire
Автор

Very well explained sir! Thank you so much.. :)

upasonabiswas
Автор

Good video on data structure to represent graph using linked list.

deepakborah
Автор

I don't think this is a good implementation of what you were showing earlier on in the video..

Firstly lets say I use exact same code as you in the end:
addNode(0, 1);
addNode(0, 3);
addNode(1, 2);

This is what shows when you run:
Adjacency list for vertex 0
0 1 3
Adjacency list for vertex 1
1 2
Adjacency list for vertex 2

Adjacency list for vertex 3

As you can see this is incorrect. Output should be like this:
Adjacency list for vertex 0
0 1 3
Adjacency list for vertex 1
1 0 2
Adjacency list for vertex 2
2 1
Adjacency list for vertex 3
3 0

You need to make it so the edge is shown from source to destination, and destination to source. You need to do both ways!

AKGamersLite
Автор

Hello Sir great Explaination but in print function i think the loop should start from 0 such that adjlist[0] be acccessed.. isn't it?

sagaralwani
Автор

Thank you for sharing. There is however a huge problem in the while loop. a while loop is not an if/else loop. Hence, it does not mean " until" but "as long as". great job though.

francoisallouin
Автор

How is list[0] pointing to 0
You explained that there's no self loop consideration
Plz explain

SwetaBardhan
Автор

I have problem printing the list because some of my vertices does not have any edges to any vertices.

Moments
Автор

Sir very well explanation. Can you pls do a video on implementation of BST using linked list

ysaianusha
Автор

Thank you ....It helps me in implementation of code.

sarthakn
Автор

thank u for the code! its really clear!!!

weisiqi
Автор

in the while loop: add a curly brackets between temp=temp->next; and temp->next=dest; to make it work.

francoisallouin
Автор

Good explanation, can you just correct while condition

mandar.vaidya
Автор

Here code:

#include <stdio.h>
#include <stdlib.h>
#define maxNode 4
typedef struct Node {
int vertexNum;
struct Node* next;
}Node;
typedef struct List {
Node* head;
}List;

List* adjlist[maxNode] = {0};

void addNode(int s, int d)
{
Node *dest, *tmp, *src;
if(adjlist[s]->head==NULL) {
src = (Node*)malloc(sizeof(Node));
src->vertexNum=s;
src->next=NULL;
adjlist[s]->head = src;
}
dest = (Node*)malloc(sizeof(Node));
dest->vertexNum=d;
dest->next=NULL;
tmp=adjlist[s]->head;
while(tmp->next!=NULL){
tmp=tmp->next;
}
tmp->next=dest;
}
void printList(){
int i;
for(i=0;i<maxNode;i++){
Node *p = adjlist[i]->head;
printf("Adjacency list for vertex %d\n", i);
while(p) {
printf("%d", p->vertexNum);
p=p->next;
}
printf("\n");
}
}
void main()
{
int i;
for(i=0; i<maxNode; i++){

adjlist[i]->head = NULL;
}
addNode(0, 1);
addNode(0, 3);
addNode(1, 2);
printList();

}

meSpideYX
Автор

Sir explain adjacent list . But not understand sir

Bhanu-xo
Автор

While loop condition is absolutely wrong.

shouvikdutta
welcome to shbcf.ru