Upload
pankaj-ahire
View
220
Download
0
Embed Size (px)
Citation preview
8/13/2019 In Degree
1/10
Write a program in C to find indegree and outdegree of every vertex of adirected graph when graph is represented by an adjacency list .Name-Roll no- 063
#include
void main(){int m[10][10],r,c,sumin,sumout,n,v,i;clrscr();printf("how many vertices:");scanf("%d",&n);for(r=0;r
8/13/2019 In Degree
2/10
is there an edge between vertex 2 and 1 (1/0):1
vertex indegree Outdegree total degree
1 1 1 2
2 1 1 2 */
8/13/2019 In Degree
3/10
Write a program in C to implement DFS on a graph through an adjacencymatrix.Name-Shraddha WaniRoll no- -63
#include
#define MAX 20typedef struct{int data[MAX];int top;}STACK;void initstack(STACK *ps){ ps->top=-1;}
void push(STACK *ps, int num){ps->top++;ps->data[ps->top]=num;
}int pop(STACK *ps){return(ps->data[ps->top--]);}
int isempty(STACK *ps){return(ps->top== -1);}int isfull(STACK *ps){return(ps->top==MAX-1);}
void dfs(int m[10][10],int n){int i,v,w,found;int visited[20]={0};STACK s;initstack(&s);v=0;
8/13/2019 In Degree
4/10
visited[v]=1;push(&s,v);printf("v%d",v+1);visited[w]=1;while(1){
found=0;for(w=0;w
8/13/2019 In Degree
5/10
scanf("%d", &m[i][j]);}
}
printf("\nthe depth first search is :");
dfs(m,n);getch();}/* output
how many vertices:2is there an edge between vertex 1 and 2 (1/0)1is there an edge between vertex 2 and 1 (1/0)1
the depth first search is :v1v2
8/13/2019 In Degree
6/10
Name- Shraddha WaniRoll no- 063Consider the following Entities & RelationshipsPolitician (pno, pname, pdesc, constituency)Party (party_code,party_name)
Politician & party are related with many-to-one.Constraints : Primary key, Foreign keyParty_name Not NULLCreate a RDB in 3NF & construct the queries in SQL Server/Oracle 8i
1.List all politici ans of party BJP.
2. Count the number of politician having political description as MP andconstituency is North Delhi.
3. Count the total number of politicians for each party.
4. List party wise politician names along with their constituency
SQL> create table party32
2 (party_code integer primary key,
3 party_name varchar2(20) not null);
Table created.
SQL> create table politician32
2 (pcode integer primary key,
3 pname varchar2(10),pdesc varchar2(20),
4 constituency varchar2(20),party_code
5 integer,foreign key(party_code)
6 references party32);
8/13/2019 In Degree
7/10
Table created.
SQL> select * from party32;
PARTY_NO PNAME
--------- --------------------
101 BJP
102 CNG
103 MNS
SQL> select * from politician32;
PCODE PNAME PDESC CONSTITUENCY PARTY_CODE
--------- -------------------- -------------------- -------------------- ----------
1 kamble MLA north mumbai 103
2 sinha MP north mumbai 101
3 ahuja MP north delhi 102
4 shelar MLA pune 103
5 yadav MLA north delhi 101
6 singh nasik nasik 103
7 rao MP west mumbai 102
1) List all p oliticians of party BJP.
SQL> select party32.pname,politician32.pname
2 from party32,politician32
8/13/2019 In Degree
8/10
8/13/2019 In Degree
9/10
4 group by party32.pname;
PNAME COUNT(PCODE)
-------------------- ------------
BJP 2
CNG 2
MNS 3
4) List party wise politician names along with their constituency
SQL> select party32.pname,politician32.pname,constituency
2 from party32,politician32
3 where party32.party_no=politician32.party_code
4 group by party32.pname,politician32.pname,constituency;
PNAME PNAME CONSTITUENCY-------------------- ---------- --------------------
BJP sinha north delhi
BJP yadav north delhi
CNG ahuja north delhi
CNG rao west mumbai
MNS kamble north mumbai
MNS shelar pune
MNS singh nasik
8/13/2019 In Degree
10/10
7 rows selected.