Data Structures With C Laboratory - 18CSL38 - Lab1 - Lab8 - LAb10 - Updated
Data Structures With C Laboratory - 18CSL38 - Lab1 - Lab8 - LAb10 - Updated
11. Design, Develop and Implement a Program in C for the following operations on Graph (G) of Cities
Expression. Program should support for both parenthesized and free parenthesized expressions with a. Create a Graph of N cities using Adjacency Matrix.
the operators: +, -, *, /, %(Remainder), ^(Power) and alphanumeric operands. b. Print all the nodes reachable from a given starting node in a digraph using DFS/BFS method
12. Given a File of N employee records with a set K of Keys(4-digit) which uniquely determine the records
5. Design, Develop and Implement a Program in C for the following Stack Applications
in file F. Assume that file F is maintained in memory by a Hash Table(HT) of m memory locations with L
a. Evaluation of Suffix expression with single digit operands and operators: +, -, *, /, %, ^
as the set of memory addresses (2- digit) of locations in HT. Let the keys in K and addresses in L are Integers.
b. Solving Tower of Hanoi problem with n disks
Implement all the experiments in C Language under Linux / Windows Design and develop a Program in C that uses Hash function H: K L as H(K)=K mod m (remainder
6. Design, Develop and Implement a menu driven Program in C for the following operations on
method), and implement hashing technique to map a given key K to the address space L. Resolve the collision
environment Circular QUEUE of Characters (Array Implementation of Queue with maximum size MAX)
(if any) using linear probing.
a. Insert an Element on to Circular QUEUE b. Delete an Element from Circular QUEUE
Course objectives: This laboratory course enables students to get practical experience in Course outcomes: On the completion of this laboratory course, the students will be able to:
c. Demonstrate Overflow and Underflow situations on Circular QUEUE
design, develop, implement, analyze and evaluation/testing of
d. Display the status of Circular QUEUE CO1: Analyse various linear and non-linear data structures.
Asymptotic performance of algorithms. CO2: Apply the concepts of data structures to implement various operations of linear and non-
e. Exit
Linear data structures and their applications such as Stacks, Queues and Lists Support the program with appropriate functions for each of the above operations linear data structure.
7. Design, Develop and Implement a menu driven Program in C for the following operations on Singly CO3: Make use of Code Block tool to edit, compile, and execute programs on data structures
Non-Linear Data Structures and their Applications such as Trees and Graphs
Linked List (SLL) of Student Data with the fields: USN, Name, Branch, Sem, PhNo CO4: Summarise the procedure for implementation, working nature of different types of data
Sorting and Searching Algorithms a. Create a SLL of N Students Data by using front insertion. structure and their operations.
Laboratory Experiments: b. Display the status of SLL and count the number of nodes in it
1. Design, Develop and Implement a menu driven Program in C for the following Array operations c. Perform Insertion / Deletion at End of SLL CO5: Choose the appropriate data structure for solving real world problems
a. Creating an Array of N Integer Elements d. Perform Insertion / Deletion at Front of SLL(Demonstration of stack)
Graduate Attributes (as per NBA)
b. Display of Array Elements with Suitable Headings e. Exit
c. Inserting an Element (ELEM) at a given valid Position (POS) 8. Design, Develop and Implement a menu driven Program in C for the following operations on Doubly 1. Engineering Knowledge
d. Deleting an Element at a given valid Position (POS) Linked List (DLL) of Employee Data with the fields: SSN, Name, Dept, Designation, Sal, PhNo
2. Problem Analysis
e. Exit. a. Create a DLL of N Employees Data by using end insertion.
b. Display the status of DLL and count the number of nodes in it 3. Design/Development of Solutions
Support the program with functions for each of the above operations.
c. Perform Insertion and Deletion at End of DLL 4. Modern Tool Usage
2. Design, Develop and Implement a Program in C for the following operations on Strings
d. Perform Insertion and Deletion at Front of DLL
a. Read a main String (STR), a Pattern String (PAT) and a Replace String (REP)
e. Demonstrate how this DLL can be used as Double Ended Queue
b. Perform Pattern Matching Operation: Find and Replace all occurrences of PAT in STR
f. Exit
with REP if PAT exists in STR. Report suitable messages in case PAT does not exist in
STR Support the program with functions for each of the above operations. Don't use Built - 9. Design, Develop and Implement a Program in C for the following operations on Singly Circular Linked
List (SCLL) with header nodes
in functions.
a. Represent and Evaluate a Polynomial P(x,y,z) = 6x2y2z-4yz5+3x3yz+2xy5z- 2xyz3
3. Design, Develop and Implement a menu driven Program in C for the following operations on
b. Find the sum of two polynomials POLY1(x,y,z) and POLY2(x,y,z) and store the result in
STACK of Integers (Array Implementation of Stack with maximum size MAX)
POLYSUM(x,y,z)
a. Push an Element on to Stack
Support the program with appropriate functions for each of the above operations
b. Pop an Element from Stack 10. Design, Develop and Implement a menu driven Program in C for the following operations on Binary
c. Demonstrate how Stack can be used to check Palindrome Search Tree (BST) of Integers
d. Demonstrate Overflow and Underflow situations on Stack a. Create a BST of N Integers: 6, 9, 5, 2, 8, 15, 24, 14, 7, 8, 5, 2
e. Display the status of Stack b. Traverse the BST in Inorder, Preorder and Post Order
f. Exit c. Search the BST for a given element (KEY) and report the appropriate message
CO1 CO2 CO3 CO4 CO5
Support the program with appropriate functions for each of the above operations e. Exit
Viva Tests Conduction Record book
List of Programs Data Structures Laboratory - 18CSL38 III Semester / B.E Data Structures Laboratory - 18CSL38 III Semester / B.E
Data Structures Laboratory - 18CSL38 III Semester / B.E Data Structures Laboratory - 18CSL38 III Semester / B.E Data Structures Laboratory - 18CSL38 III Semester / B.E
while(STR[c] != '\0') { EXPERIMENT – 03: STACK operations
Program should be tested and output should be recorded if(STR[m] == PAT[i]){ //if same , scan next character Design, Develop and Implement a menu driven program in C forthe following operations on STACK of integers
i++; (Array implementation of stack with maximum size MAX)
Display, Create- 3 elements, Display, Insert, Insert, Display, Insert m++; a. Push an element on to stack
if(PAT[i] == '\0'){//If scanned then replace b. Pop an element from stack.
Additional Program: flag = 1; c. Demonstrate how stack can be used to check palindrome.
k=0; d. Demonstrate Overflow and Underflow situations on stack.
Input a word while(REP[k] != '\0'){
Insert new character at specified position and display the updated word e. Display the status of stack.
ANS[j++] = REP[k++];
Delete a character at specified position and display the updated word. f. Exit. Support the program with appropriate functions foreach of the above operations.
}
Evaluation of experiment: Conduction: 5, Modification: 5 Viva 4 i = 0;
c = m; PUSH operation:
}
EXPERIMENT – 02: Strings operations } Display Stack overflow if no space in stack ie. TOP=MAX-1
Design, develop and Implement a program in C for the following else { Otherwise Increment TOP and copy new ITEM at TOP
Stringsoperations ANS[j++] = STR[c++]; // copy input string to resultant string if not matching
m = c; POP operation:
a. Read a Main String (STR), a Pattern String (PAT) and a Replace i = 0; //reset index of pattern string to point to first char and scan again
} Display Stack Underflow if no element in stack ie. TOP=-1
b. String(REP).
} //end of while Otherwise return the TOP element of stack and decrement TOP by 1
c. Perform Pattern Matching Operation: Find and Replace all ANS[j] = '\0';
return flag; Palindrome check operation:
d. occurrencesof PAT in STR with REP if PAT exists in STR. }
Compare both end of stack till TOP/2 if all element are matching
e. Repost suitable messages incase PAT does not exist in STR.
int main(){ //Main program then display Palindrome otherwise not a palindrome
f. Support the program with functions for each of the above operations. Do not use built-in functions. printf("\nEnter a main string :");
gets(STR); CODE:
printf("\nEnter a pattern string :"); #include<stdio.h>
#include<stdlib.h>
Steps for Pattern_Match_Repace() gets(PAT);
#define MAX 5
printf("\nEnter a string to be replaced:"); void Display();
For All characters of Main String STR, scan each gets(REP); int stack[MAX],top = -1,i;
character of Main string STR and Pattern String PAT if if(Pattern_Match_Replace( ) ) int isEmpty(){
correspondingcharacter are same. printf("\nThe resultant string is: %s \n" , ANS); if(top == -1){
else printf("\nStack is Underflow!");
If pattern found then replace all matching characters return 1; //return 1 if empty
printf("\nPattern string NOT found\n");
by replacement string REP otherwise copy characters of return 0; }
Main string till scanned position to resultant string } else
ANS. return 0; //not empty
OUTPUT }
Reset next scanning position, point to first character int isFull(){
ofPAT and continue. Enter a main string: Data Structures Laboratory using C++ if (top == (MAX-1)){
printf("\n\nStack is Overflow!");
Enter a pattern string: C++
return 1; //1 if full
CODE: Enter a replace string: C }
#include<stdio.h> else
#include<stdlib.h> The resultant string is: Data Structures Laboratory using C return 0;//not full
char STR[100], PAT[50], REP[50], ANS [100]; }
int Pattern_Match_Replace() { // String Matching function
Find out any other efficient method for pattern matching
int i=0; //index for PAT
int c=0, m=0; //index for STR
int k=0 ; //index for REP
int flag=0;
int j=0; //index for ANS
Dept. of ISE,SIT, Mangaluru Page|4 Dept. of ISE,SIT, Mangaluru Page|5 Dept. of ISE,SIT, Mangaluru Page|6
Data Structures Laboratory - 18CSL38 III Semester / B.E Data Structures Laboratory - 18CSL38 III Semester / B.E Data Structures Laboratory - 18CSL38 III Semester / B.E
OUTPUT
void Push(int item){ /*PUSH FUNCTION*/ MAIN MENU: 1.PUSH 2.POP 3.PALINDROME check 4.DISPLAY status 5. Exit EXPERIMENT – 04: Infix Expression to Postfix
int item; Enter Your Choice: 2
if (isFull()==0){ //not full Stack is Underflow! Design, develop and Implement a Program in C for converting an Infix Expression to Postfix Expression.
printf("\nEnter an element to be pushed:"); Program should support for both parenthesized and free parenthesized expressions with the operators: +, -,
scanf("%d", &item); MAIN MENU: 1.PUSH 2.POP 3.PALINDROME check 4.DISPLAY status 5. Exit
stack[++top] = item; Enter Your Choice: 1 *, /, %( Remainder), ^ (Power) and alphanumeric operands .
}
Display(); Enter an element to be pushed: 12 _____ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ ___
void Palindrome() { /*PALINDROME FUNCTION*/ Enter an element to be pushed: 45 If it is a right parentheses, pop out elements from the stack
int i, temp = top+1, count=0; The stack contents are: 45 34 12
and add it to the postfix string. Pop out the left parentheses
for(i=0; i<temp/2; i++){
MAIN MENU: 1.PUSH 2.POP 3.PALINDROME check 4.DISPLAY status 5. Exit but don’t add to postfix. (Observe the return value of “(“ of
if(stack[i] == stack[top-i]){
Enter Your Choice: 1
count++; stack and “)” of Input)
} Enter an element to be pushed: 34
if((temp/2)==count) If it is an operator, compare its precedence with that of the
The stack contents are: 34 45 34 12
printf("\nStack is a Palindrome numbers "); element at the top of stack.
else
MAIN MENU: 1.PUSH 2.POP 3.PALINDROME check 4.DISPLAY status 5. Exit o If it is greater push it onto the stack.
printf("\nStack is not a palindrome!!");
Enter Your Choice: 1
} Enter a element to be pushed: 12 o Otherwise pop and add elements to the postfix expression
void Display() {int i;
The stack contents are: 12 34 45 34 12 until base symbol #.
if (isEmpty()==0){
printf("\nThe stack contents are:"); o If # is reached, i.e the end of the expression, pop out
MAIN MENU: 1.PUSH 2.POP 3.PALINDROME check 4.DISPLAY status 5. Exit
for(i=top; i>=0; i--) Enter Your Choice: 1
printf("\t %d", stack[i]); any leftover elements in the stack till it becomes empty.
Enter an element to be pushed: 23
} Stack is Overflow! o Append a null terminator at the end display the result
} The stack contents are: 12 34 45 34 12
void main() {
int ch,item; MAIN MENU: 1.PUSH 2.POP 3.PALINDROME check 4.DISPLAY status 5. Exit
do{ Code:
Enter Your Choice: 3
printf("\n MAIN MENU:"); #include<stdio.h>
printf("1.PUSH\n 2.POP \n3.PALINDROME check \n 4.DISPLAYstatus 5. Exit"); Popped element is:- 12
#include<string.h>
printf("\nEnter Your Choice: "); Popped element is:- 34 int Stack (char symbol) {
scanf("%d", &ch); Stack contents are Palindrome switch(symbol){
switch(ch){ case '+': return 2;
case 1: Push(item); break; MAIN MENU: 1.PUSH 2.POP 3.PALINDROME check 4.DISPLAY status 5. Exit case '-': return 2;
case 2: Pop(); break; Enter your choice: 4 case '*': return 4;
case 3: Palindrome(); break; The stack contents are: 12 34 45 case '/': return 4;
case 4: Display(); break; case '%': return 4; //modulus ex- 5% 3=2
case 5: exit(0); break; MAIN MENU: 1.PUSH 2.POP 3.PALINDROME check 4.DISPLAY status 5. Exit
}
case '^': return 5; //power
Enter your choice: 3 case '(': return 0;
}while (1); Popped element is:- 45
} case '#': return -1;
Stack contents are not palindrome!!
default : return 8;
MAIN MENU: 1.PUSH 2.POP 3.PALINDROME check 4.DISPLAY status 5. Exit }
Enter Your Choice:5 }
Dept. of ISE,SIT, Mangaluru Page|7 Dept. of ISE,SIT, Mangaluru Page|8 Dept. of ISE,SIT, Mangaluru Page|9
Data Structures Laboratory - 18CSL38 III Semester / B.E Data Structures Laboratory - 18CSL38 III Semester / B.E Data Structures Laboratory - 18CSL38 III Semester / B.E
int Input (char symbol) { EXPERIMENT – 05.A: Evaluation of Suffix expression EXPERIMENT – 05.B: Tower of Hanoi
switch(symbol) { Design, Develop and Implement a Program in C for the following Stack Applications
case '+': return 1; Design, Develop and Implement a Program in C for the following Stack Applications
a. Evaluation of Suffix expression with single digit operands and operators: +, -, *, /, %, ^
case '-': return 1; a) Evaluation of Suffix expression with single digit operands and operators: +, -, *, /, %, ^
case '*': return 3;
Step 1: Read the infix expression as a string. b) Solving Tower of Hanoi problem with n disks._ _
case '/': return 3;
case '%': return 3; //mod Step 2: Scan the expression character by character till the end. Repeat
Algorithm:
case '^': return 6; //power the following operations
case '(': return 9; Step 1: Move a tower of height-1 to an intermediate pole, using the
a. If it is an operand push it onto the stack.
case ')': return 0; final pole.
default : return 7; b. If it is an operator
Step 2: Move the remaining disk to the final pole.
} 1. Pop out two operands from stack.
} Step 3: Move the tower of height-1 from the intermediate pole to the
2. Apply the operator onto the popped operands.
void Infix_postfix(char infix[], char postfix[]){
int top = -1,j = 0, i; 3.Store the result back on to the stack.
CODE:
char s[30], symbol; Step 3: On reaching the end of expression, pop out the contents of the
s[++top] = '#'; #include<stdio.h>
stack and display as the result. #include<math.h>
for(i=0; i < strlen(infix); i++) {
symbol = infix[i]; CODE: void Tower(int n, char source, char temp, char destination){
if(Input (symbol)==7 ) { # include<stdio.h> if(n = = 0) return;
postfix[j++] =symbol; #include<math.h> Tower(n-1, source, destination, temp);
continue; #include<string.h> printf("\n Move disc %d from %c to %c", n, source, destination);
} #include <ctype.h> Tower(n-1, temp, source, destination);
while(Stack (s[top]) > Input (symbol)){ int Compute(char symbol, int op1, int op2){ }
int Temp=1,i; void main(){
postfix[j++] = s[top--]; switch(symbol){
} int n;
case'+' :Temp=op1 + op2; break; printf("\nEnter the number of discs: ");
if( Stack (s[top]) != Input (symbol)) case'-' :Temp=op1 -op2;break;
s[++top] = symbol; scanf("%d", &n);
case'*' :Temp=op1 * op2;break;
else Tower(n, 'S', 'T', 'D');
case'/' :if (op2 != 0) Temp= op1 / op2;break;
top--; case'%' :if (op2 != 0) Temp=op1% op2; break; printf("\n\n Total Number of moves are: %d", (int)pow(2,n)-1);
} case'^' :for(i=1;i<=op2;i++) }
while(s[top] != '#') Temp=Temp*op1;
break; OUTPUT
postfix[j++] = s[top--]; cc Lab5b.c –lm
postfix[j] = '\0'; default: break;
printf("\nThe infix expression is:%s \nThe postfix expression is:%s ",infix, postfix); } Enter the number of discs: 3
return (Temp);
}
} Move disc 1 from S to D
void main(){ int main(){ Move disc 2 from S to T
char infix[20], postfix[20]; int s[20], op1, op2,top=-1, i; Move disc 1 from D to T
printf("\nEnter the infix expression :"); char postfix[20], symbol; Move disc 3 from S to D
gets(infix); printf("\nEnterthe postfix expression:"); Move disc 1 from T to S
Infix_postfix(infix,postfix); scanf("%s",postfix); Move disc 2 from T to D
for(i=0; i<strlen(postfix); i++){ Move disc 1 from S to D
} Obtain the postfix expression for the following and observe the output: symbol = postfix[i];
if(isdigit(symbol)) Total Number of moves are: 7
1) ((A+B)*C-(D-E))%(F+G) Expected Answer: AB+C*DE--FG+% s[++top] = symbol -'0';
2) A/B^C+D*E-A*C Expected Answer: ABC^/DE*+AC*- else{ 1 S D
op2 = s[top--]; 2 S T
op1 = s[top]; 1 D T
Few examples: s[top]= Compute(symbol, op1, op2); 3 S D
(1+2+3) left to right execution 3+3 6 } 1 T S
(1*2-3) left to right, * has higher priority so 3-3=0 } 2 T D
(1%3%6) left to right 1%31 1%6 1 printf("\n The result is : %d\n", s[top]); 1 S D
}
(2^3^2) right to left 2^9 512 OUTPUT: cc Lab5a.c –lm { Sample Expression: 935*64-/+ ,Result=16
Dept. of ISE,SIT, Mangaluru Page|10 Dept. of ISE,SIT, Mangaluru Page|11 Dept. of ISE,SIT, Mangaluru Page|12
Data Structures Laboratory - 18CSL38 III Semester / B.E Data Structures Laboratory - 18CSL38 III Semester / B.E Data Structures Laboratory - 18CSL38 III Semester / B.E
EXPERIMENT – 06: Circular QUEUE OPERATIONS void Insert(){
Design, Develop and Implement a menu driven Program in C for the following operations on if(isFull()==0) { //if not full Observe the output and draw circular queue status
printf("Enter element to insert:"); (diagram) for the following sequence of operations.
Circular QUEUE of Characters (Array Implementation of Queue with maximum size MAX)
rear=(++rear)%max;
a. Insert an Element on to Circular QUEUE scanf(" %c",&q[rear]); //read a char and insert if cir.queue is not full Insert a, Insert b, Insert c,
printf("front=%d Rear=%d", front,rear); Insert d,
b. Delete an Element from Circular QUEUE
} Insert e, Display Delete Insert e
c. Demonstrate Overflow and Underflow situations on Circular QUEUE else ,
printf("Queue is overflow\n"); Delete Delete Delete Delete Delete
d. Display the status of Circular QUEUE
}
e. Exit void Delete(){
if(isEmpty()==0){ //if not empty
Support the program with appropriate functions for each of the above operations
front=(++front)%max; EXPERIMENT – 07: Singly Linked List Operations
printf("Deleted element is:%c\n", q[front]); //remove and delete a char from queue Design, Develop and Implement a menu driven Program in C for the following operations on Singly Linked List
Steps: printf("front=%d Rear=%d", front,rear); (SLL) of Student Data with the fields: USN, Name, Programme, Sem, PhNo
if(front==rear)
1. Insertion { a. Create a SLL of N Students Data by using front insertion.
Display overflow if rear >-1 and front is rear+1 printf("true"); b. Display the status of SLL and count the number of nodes in it
front=rear=-1; c. Perform Insertion / Deletion at End of SLL
Otherwise Insert new element at updated rear (i.e rear+1) } d. Perform Insertion / Deletion at Front of SLL(Demonstration of stack)
2. Deletion } e. Exit
else
Display Underflow if front=0 and rear=-1
printf("Queue is NOW empty\n"); #include<stdio.h>
Otherwise return the element at front and update front } #include<stdlib.h>
void Display(){ int MAX=4,count=0;
(i.e front=front +1 if no element found( if rear=front) struct student{
int i=(front+1) %max;
then resetfront and rear. if(isEmpty()==0){ char usn[10], name[30], branch[5];
char phno[10];
3. Display do{ int sem;
printf("\t%c",q[i]);
Display all element from front to rear in circular fashion struct student *next;
i=(i+1)%max; };
} while(i!=(rear+1)%max); typedef struct student NODE;
CODE: } NODE *head,*newnode;
#include<stdio.h> else NODE* Getnode(){
#include<stdlib.h> printf("Queue is empty\n"); newnode=(NODE*)malloc(sizeof(NODE));
char q[10]; } printf("\nEnter USN, Name, Branch, Sem, Ph.No:");
int max=4; int main() scanf("%s%s%s%d%s",
int front=-1,rear=-1; { newnode->usn,newnode->name,newnode->branch, &newnode->sem, newnode->phno);
int isFull(){ newnode->next=NULL;
int ch;
if((front+1)%max==(rear+1)% max && rear>-1) count++;
do { return (newnode);
{ printf("\n Circular Queue operations\n 1.Insert\n 2.Delete\n 3.Display\n 4.Exit\n"); }
return 1; //if full printf("Enter your choice:");
} scanf("%d",&ch); void Display(NODE *p){
else switch(ch) { if( p!= NULL){
return 0; //if not full case 1: Insert(); printf("\n----STUDENT DATA----\n USN\t\tNAME\t\tBRANCH\tSEM\tPh.NO.");
} break; while(p!=NULL){
int isEmpty(){ case 2: Delete(); printf("\n%s\t%s\t\t%s\t%d\t%s", p->usn, p->name, p->branch, p->sem, p->phno);
if((front==-1)&&(rear==-1)) { break; p = p->next;
return 1; //if empty case 3: Display(); }
} printf("\nNumber of nodes%d",count);
break;
else{ }
case 4: exit(0); else
return 0; //if not empty } printf("\nNo data available!!\n");
} }while(1); }
} }
Dept. of ISE,SIT, Mangaluru Page|13 Dept. of ISE,SIT, Mangaluru Page|14 Dept. of ISE,SIT, Mangaluru Page|15
Data Structures Laboratory - 18CSL38 III Semester / B.E Data Structures Laboratory - 18CSL38 III Semester / B.E Data Structures Laboratory - 18CSL38 III Semester / B.E
p=p->next;
} 8. Design, Develop and Implement a menu driven Program in C for the following operations on Doubly
NODE *Insert_Front(NODE *head){ q->next=NULL; Linked List (DLL) of Employee Data with the fields: SSN, Name, Dept, Designation, Sal, PhNo
NODE *newnode,*p; free(p); a. Create a DLL of N Employees Data by using end insertion.
if(count==MAX) count--; b. Display the status of DLL and count the number of nodes in it
printf("\n Overflow!!"); } c. Perform Insertion and Deletion at End of DLL
else { }
d. Perform Insertion and Deletion at Front of DLL
newnode=Getnode(); return head;
e. Demonstrate how this DLL can be used as Double Ended Queue
if(head==NULL) }
head= newnode; int main(){ f. Exit
else{ int ch, i, n; #include<stdio.h>
newnode->next=head; NODE *head=NULL; #include<stdio.h>
head=newnode; printf("\n----------Student Database---------"); #include<stdlib.h>
} printf("\nHow many student data you want to create: "); int MAX=4,count=0;
} scanf("%d", &n); struct emp{
return (head); for(i=0;i<n;i++) char ssn[5],name[20], dept[10], phno[10],desig[15];
} head=Insert_Front(head); //Creation int sal;
NODE* Insert_Rear(NODE *head){ do { struct emp *left, *right;
NODE *newnode,*p; printf("\nMENU:\n1.Display\n2.Insert-Front \n3.Delete Front\n4.Insert-Rear \n5.Delete Rear"); };
if(count==MAX) printf("\n 6.Stack-PUSH\n 7.Stack-POP\n 8.Exit \nEnter your choice: ");
typedef struct emp NODE;
printf("\n Overflow!!"); scanf("%d", &ch);
else { switch(ch) { NODE* Getnode(){
newnode=Getnode(); case 1: Display(head); break; NODE *node=(NODE*)calloc(1,sizeof(NODE));
if(head==NULL) case 2: head=Insert_Front(head); break; printf("\nEnter SSN, Name, Dept, Designation, Sal, Ph.No:");
head=newnode; case 3: head=Delete_Front(head); break; scanf("%s%s%s%s%s%d",node ->ssn, node ->name, node ->dept, node ->phno ,node ->desig,&node -
else{ case 4: head=Insert_Rear(head); break; >sal);
p=head; case 5: head=Delete_Rear(head); break; node->right=node ->left =NULL;
while(p->next!=NULL){ case 6: head=Insert_Rear(head); break; //stack-Push count ++;
p=p->next; case 7: head=Delete_Rear(head); break; //stack-Pop return node;
} case 8: exit(0); }
p->next=newnode; } void Display(NODE *p){
} }while(1);
if(p != NULL){
} }
return (head); printf("\nSSN\tNAME\tDEPT\tDESINGATION\tSAL\tPh.NO.\n");
} while(p!=NULL){
NODE* Delete_Front(NODE *head){ // printf("count:%d %u",count,p);
NODE *p; printf("\n%s\t%s\t%s\t%s\t%s\t\t%d",p->ssn, p->name, p->dept, p->phno,p->desig,p->sal);
p=head; p = p->right;
if(head==NULL) }
printf("\nEmpty(Underflow)"); printf("\nNumber of nodes%d",count);
else { }
head=head->next; else
free(p);
printf("\nNo data available!!\n");
count--;
}
}
return head; NODE* Insert_Rear(NODE *head){
} NODE *p=head, *newnode;
NODE* Delete_Rear(NODE *head){ if(count==MAX)
NODE *p, *q; printf("\n Overflow!!");
p=head; else{
if(head==NULL) newnode=Getnode();
printf("\nEmpty(Underflow)"); if(head==NULL)
else { head=newnode;
if (head->next==NULL) else{
head=NULL;
while(p->right!=NULL){
else {
p=p->right;
while(p->next!=NULL){
q=p; }
Dept. of ISE,SIT, Mangaluru Page|16 Dept. of ISE,SIT, Mangaluru Page|17 Dept. of ISE,SIT, Mangaluru Page|18
Data Structures Laboratory - 18CSL38 III Semester / B.E Data Structures Laboratory - 18CSL38 III Semester / B.E Data Structures Laboratory - 18CSL38 III Semester / B.E
p->right=newnode; }
newnode->left=p; return head; EXPERIMENT – 09: Singly Circular Linked List (SCLL)
} } Design, Develop and Implement a Program in C for the following operations on Singly Circular Linked
} int main(){
return head; int ch, i, n; List (SCLL) with header nodes:
} NODE *head=NULL; a. Represent and Evaluate a Polynomial P(x,y,z) = 6x2y2z-4yz5+3x3yz+2xy5z-2xyz3
NODE* Insert_Front(NODE *head){ printf("\nHow many employees data you want to create: ");
NODE *p=head, *newnode; scanf("%d", &n); b. Find the sum of two polynomials POLY1(x,y,z) and POLY2(x,y,z) and store the result
if(count==MAX) for(i=0;i<n;i++) in POLYSUM(x,y,z). Support the program with appropriate functions for each of the above operations.
printf("\n Overflow!!"); head=Insert_Rear(head);
else { do{
newnode=Getnode(); printf("\n1.Display\n2.Insert-Front\n3.Insert-Rear\n4.Deletion-Front");
if(head==NULL) printf("\n5.Deletion-Rear\n6.Queue-Insertion\n7.Queue-Deletion \n8.Exit\n"); Algorithm:
head=newnode; printf( "Enter your choice: ");
Step for Node creation
else{ scanf("%d", &ch);
newnode->right=head; switch(ch) { Get a node and assign coefficient and power of x,y,z
head->left=newnode; case 1 : Display (head); break;
Attach this to head in circular linked list fashion
head=newnode; case 2 : head=Insert_Front (head); break;
} case 3 : head=Insert_Rear (head); break; Step for Node display
} case 4 : head=Delete_Front (head); break; From the first node last node display all data fields of
return head; case 5 : head=Delete_Rear(head); break;
a node in a standard form Coeff.X^ powx.Y^powx.Z^powxGet a
} case 6 : head=Insert_Rear (head); break; //queue insertion
NODE* Delete_Rear(NODE *head){ case 7 : head=Delete_Front(head); break; //queue deletion node and assign coefficient and power of x,y,z
NODE *p=head,*q; case 8 : exit(0); break; Steps for compare
if(head==NULL) }
printf("\nList is Empty (QUEUE)"); }while(1); Return aif corresponding coefficient X,Y and Z of two
else { } polynomials are same, otherwise return 0.
while(p->right!=NULL) Doubly Linked list
Steps for Evaluate
p=p->right;
if( p->left !=NULL){ For all the terms evaluate and return the final answer.
q=p->left;
q->right=NULL; Steps for Adding two polynomils
} Repeat for all terms of both olynomials
else
Compare a terms of first polynomial with a term of second
head=NULL;
free(p); polynomial
count--; If powers of X,Y and Z are same then add corresponding
}
coefficients and mark both terms and the resultant terms
return head;
} to Result polynomial( to avoid further consideration)
NODE* Delete_Front(NODE *head){ Otherwise consider the other term of second polynomial if
NODE *p=head,*q;
if(head==NULL) no matching powers of X,Y and Z found add the first
printf("\nList is Empty (QUEUE)"); polynomial term to resultant and mark it Repeat this for
else { all terms of first polynomial
if( p->right ==NULL)
head=NULL; If any unmarked terms found in second then add it to the
else{ resultant polynomial.
head=p->right;
head->left=NULL;
}
free(p);
count--;
Dept. of ISE,SIT, Mangaluru Page|19 Dept. of ISE,SIT, Mangaluru Page|20 Dept. of ISE,SIT, Mangaluru Page|21
Data Structures Laboratory - 18CSL38 III Semester / B.E Data Structures Laboratory - 18CSL38 III Semester / B.E Data Structures Laboratory - 18CSL38 III Semester / B.E
#include<stdio.h> NODE* Add_poly(NODE *h1,NODE *h2,NODE *h3){ case 3: h3=Add_poly(h1,h2,h3);
#include<math.h> NODE *p1=h1->link,*p2; printf("\nPolynomial C is:");
#include<stdlib.h> do{ Display(h3);
struct node{ p2=h2->link; break;
int coef, ex, ey, ez,flag; do{ case 4: printf("\n Enter value for x, y, z, terms to evaluate:");
struct node *link; if((p1->flag !=1 )&& (p2->flag !=1)&&(p1->ex==p2->ex)&& (p1->ey == p2->ey ) && scanf("%d%d%d", &x, &y, &z);
}; (p1->ez == p2->ez)) { Evaluate(x,y,z,h1);
typedef struct node NODE; h3=Insert(p1->coef+p2->coef,p1->ex,p1->ey,p1->ez,h3); Evaluate(x,y,z,h2);
NODE* Insert(int coef,int x,int y,int z, NODE *head){ p1->flag=1; break;
NODE *newnode=(NODE*) calloc(1,sizeof(NODE)), *temp=head; p2->flag=1; //mark visited case 5: exit(0);
newnode->coef=coef; } }
newnode->ex=x; p2=p2->link; } while(1);
newnode->ey=y; }while(p2!=h2); return 0;
newnode->ez=z; p1=p1->link; }
newnode->flag=0; }while(p1!=h1); OUTPUT
if(head==NULL) p1=h1->link; //reset to copy all remaining terms cc Lab9.c –lm
head=newnode;//if no node then newly created node is first node while(p1!=h1){ 1.Create 2. Display 3. Add two poly 4. Evaluate 5.Exit
else{ if(p1->flag !=1){//if not considered Enter your choice:1
while(temp->link!=head){ h3=Insert(p1->coef,p1->ex,p1->ey,p1->ez,h3); Enter polynomial to evaluate:
temp=temp->link; p1->flag=1; Enter number of terms in polynomial terms:2
} } Enter coeff and powers of x,y ,z: 3 1 1 2
temp->link=newnode; //change rear p1=p1->link; //next term of A Enter coeff and powers of x,y ,z: 6 1 2 1
} } Enter number of terms in polynomial terms:2
newnode->link=head; //form as circular header -by connecting to head node p2=h2->link; Enter coeff and powers of x,y ,z: 9 2 1 1
return head; while(p2!=h2){ Enter coeff and powers of x,y ,z: 10 1 2 1
} if(p2->flag!=1){//if not considered 1.Create 2. Display 3. Add two poly 4. Evaluate 5.Exit
NODE *Read_poly(NODE *head){ h3=Insert(p2->coef,p2->ex,p2->ey,p2->ez,h3); Enter your choice:3
int ex, ey, ez, coef, n,i; p2->flag=1; Polynomial C is:+16X^1Y^2Z^1+3X^1Y^1Z^2+9X^2Y^1Z^1
printf("\nEnter number of terms in polynomial terms:"); } 1.Create 2. Display 3. Add two poly 4. Evaluate 5.Exit
scanf("%d",&n); p2=p2->link; //next term of A Enter your choice:2
Polynomial A is:+3X^1Y^1Z^2+6X^1Y^2Z^1
for(i=0;i<n;i++){ }
Polynomial B is:+9X^2Y^1Z^1+10X^1Y^2Z^1
printf("\n Enter coeff and powers of x,y ,z: "); return h3;
1.Create 2. Display 3. Add two poly 4. Evaluate 5.Exit
scanf("%d%d%d%d", &coef,&ex, &ey, &ez); }
Enter your choice:4
head=Insert(coef,ex,ey,ez,head); int main(){
Enter value for x, y, z, terms to evaluate:1 1 1
} NODE *h1=NULL,*h2=NULL,*h3=NULL;
Polynomial result is: 9
return head; int ch,x,y,z; Polynomial result is: 19
} do{ 1.Create 2. Display 3. Add two poly 4. Evaluate 5.Exit
void Display(NODE *head){ printf("\n1.Create 2. Display 3. Add 4. Evaluate 5.Exit\n Enter your choice:"); Enter your choice:5
NODE *temp=head->link; //to point to the first data node scanf("%d", &ch);
while(temp!=head){ switch(ch) {
printf("%+dX^%dY^%dZ^%d", temp->coef, temp->ex, temp->ey, temp->ez); case 1: h1=Insert(0,0,0,0,h1);//header node creation
temp=temp->link; h2=Insert(0,0,0,0,h2);
} h3=Insert(0,0,0,0,h3);
} printf("\nEnter polynomial to evaluate:\n");
void Evaluate( int x, int y, int z,NODE *head){ h1=Read_poly(h1);
NODE *temp=head->link; h2=Read_poly(h2);
int result=0; break;
while(temp!=head){ case 2: printf("\nPolynomial A is:");
result = result + (temp->coef * pow(x,temp->ex) * pow(y,temp->ey) *pow(z,temp->ez)); Display(h1);
temp=temp->link; printf("\nPolynomial B is:");
} Display(h2);
printf("\n Polynomial result is: %d", result); break;
}
Dept. of ISE,SIT, Mangaluru Page|22 Dept. of ISE,SIT, Mangaluru Page|23 Dept. of ISE,SIT, Mangaluru Page|24
Data Structures Laboratory - 18CSL38 III Semester / B.E Data Structures Laboratory - 18CSL38 III Semester / B.E Data Structures Laboratory - 18CSL38 III Semester / B.E
EXPERIMENT – 10: Binary Search Tree (BST) NODE* Createtree(NODE *node, int data){ printf("\n Enter your choice: ");
1. Design, Develop and Implement a menu driven Program in C for the following operations on Binary if (node == NULL) { scanf("%d", &ch);
NODE *temp= (NODE*)calloc(1,sizeof(NODE)); switch (ch){
Search Tree (BST) of Integers temp->data = data; case 1: printf("\nEnter total numbers to be added to binary tree: " );
a. Create a BST of N Integers: 6, 9, 5, 2, 8, 15, 24, 14, 7, 8, 5, 2 return temp; //create and insert new node to BST scanf("%d", &n);
} printf("\nEnter the values for the BST");
b. Traverse the BST in Inorder, Preorder and Post Order
if (data < node->data) //TRAVERSE LEFT of NODE if key is less than data for(i=0; i<n; i++) {
c. Search the BST for a given element (KEY) and report the appropriate message node->left = Createtree(node->left, data); scanf("%d", &no);
e. Exit else if (data > node->data) //TRAVERSE LEFT of NODE if key is greater than data root=Createtree(root, no);
_____ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ node -> right = Createtree(node->right, data); }
else //reject the duplicate break;
printf(“duplicate data found”); case 2: printf("\nEnter the element to search: ");
Steps: return node; scanf("%d", &no);
} Search(root, no);
1) Binary Search Tree-BST Creation NODE* Search(NODE *node, int data){ break;
if(node == NULL) //insert at proper place case 3: : printf("\nInorder Traversal: \n");
If no node exist , then create a node , insert data
printf("\n Element not found"); Inorder(root);
into data field, set left and right child to null break;
else if(data < node->data) //TRAVERSE LEFT of NODE if key is less than data
,return node->left=Search(node->left, data); case 4 :printf("\nPreorder Traversal: \n");
If head is not null, compare data field of the node else if(data > node->data) //TRAVERSE LEFT of NODE if key is greater than data Preorder(root);
,traverse to left branch if data field of the node is node->right=Search(node->right, data); break;
less than the new data to insert, else{ case 5: printf("\nPostorder Traversal: \n");
Traverse to right branch of the node if data field is printf("\n Element found: %d", node->data); Postorder(root);
} break;
greater than data to insert.
return node; case 6: exit(0);
Repeat above two step until a null node. } default: printf("\n Wrong option");
If null node add the node by setting the address field void Inorder(NODE *node){ //LEFT-ROOT-RIGHT break;
to last child node and return. if(node != NULL){ }
2) Binary Search Tree BST-Creation Inorder(node->left); } while (1);
If no node exist , then display proper prompt printf("%d\t", node->data); }
Inorder(node->right); OUTPUT
Traverse to left branch if data field is greater than 1.Insertion 2.Search an Element 3.Delete an Element
}
data to search } 4.Inorder 5.Preorder 6.Postorder 7.Exit
Traverse to right branch if data field is lesser than void Preorder(NODE *node){ //ROOT—LEFT-RIGHT Create BST for the following data : 6,9,5,2,8,15,24,14,7,8,5,2
data to search if(node != NULL) { Perform following operations
If found or not found display proper message printf("%d\t", node->data); 1. Insertion 6,9,5,2,8,15,24,14,7,8,5,2
3) Traverse Preorder(node->left); 2. Search for 15 Deletion : 2 Inorder Preorder
Preorder(node->right); 3. Post order traverse
If head node is not null, then recursively traverse
} Represent your response in graphical form also
o If preorder: DATA LEFT child Right Child
}
o If postorder: LEFT child Right Child DATA void Postorder(NODE *node){ //LEFT –RIGHT-ROOT Observation: //sample data {6,9,5,2,8,15,24,14,7,8,5,2};
o If Inorder: LEFT child DATA Right Child if(node != NULL) {
Postorder(node->left);
Postorder(node->right);
printf("%d\t", node->data);
}
CODE:
}
#include <stdio.h>
void main()
#include <stdlib.h>
{
struct BST {
int no, ch, i, n;
int data;
NODE *root=NULL;
struct BST *left, *right;
do{
};
printf("\n1.Creation\n2.Search\n3. Inorder \n4. Preorder \n5. Postorder \n6.Exit");
typedef struct BST NODE;
Dept. of ISE,SIT, Mangaluru Page|25 Dept. of ISE,SIT, Mangaluru Page|26 Dept. of ISE,SIT, Mangaluru Page|27
Data Structures Laboratory - 18CSL38 III Semester / B.E Data Structures Laboratory - 18CSL38 III Semester / B.E Data Structures Laboratory - 18CSL38 III Semester / B.E
int ch, start, i, j;
EXPERIMENT – 11: Operations on Graph(G) printf("\nEnter the number of vertices in graph: ");
Design, Develop and Implement a Program in C for the following operations on Graph(G) of Cities scanf("%d", &n);
a. Create a Graph of N cities using Adjacency Matrix. printf("\nEnter the adjacency matrix:\n");
for(i=1; i<=n; i++)
b. Print all the nodes reachable from a given starting node in a digraph using BFS method for(j=1; j<=n; j++)
scanf("%d", &adj[i][j]);
Algorithm: do{
printf("\n1. Reachable vertices using BFS\n2. Reachable vertices using DFS");
Input: A graph G and a vertex v of G printf("\n3. Exit");
Output: All vertices reachable from v labeled as discovered printf("\n Enter your choice: ");
Step for BFS(G,v) (Breadth First Search)
scanf("%d", &ch);
for(i=1;i<=n;i++)
Mark vas discovered and add it to q at rear. visited[i] = 0;
printf("\n Enter the starting vertex: ");
Visit all vertices from front to rear only once and after visiting a vertices, mark it as scanf("%d", &start);
visited and also display the data containing in the vertices printf("\nNodes reachable from starting vertex %d are:", start);
switch(ch){
Step for DFS(G,v) (Depth First Search)
case 1: BFS(start); break;
Mark vas discovered and push it to top of q at rear. case 2: DFS(start); break;
case 3: exit(0);
Visit all vertices only once and after visiting a vertices, mark it as visited and also }
display the data containing in the vertices. }while(ch!=3);
CODE: }
OUTPUT
#include<stdlib.h>
#include<stdio.h>
BFS:
int adj[20][20],visited[20], G[20], front = -1,rear =-1, top = -1,n,i; Enter the starting vertex: 1
Nodes reachable from starting vertex 1 are: 1->2 1->3 2->4
void BFS(int v){ //uses G as Queue
int cur; DFS
visited[v] = 1; Nodes reachable from starting vertex 4 are: 4 -- 1 1 -- 2 2 -- 3
G[++rear] = v;
while(front!=rear){
cur = G[++front];
for(i=1;i<=n;i++){
if((adj[cur][i]==1)&&(visited[i]==0)){
Draw a graph and apply BFS and DFS
G[++rear]=i;
visited[i]=1;
printf("%d%d \n",cur,i);
}
}
}
}
void DFS(int v){ //uses G as Stack
visited[v]=1;
G[++top] = v;
for(i=1;i<=n; i++){
if(adj[v][i] == 1 && visited[i] == 0 ) {
printf("\n%d -- %d", v, i);
DFS(i);
}
}
}
int main(){
Dept. of ISE,SIT, Mangaluru Page|28 Dept. of ISE,SIT, Mangaluru Page|29 Dept. of ISE,SIT, Mangaluru Page|30
Data Structures Laboratory - 18CSL38 III Semester / B.E Data Structures Laboratory - 18CSL38 III Semester / B.E Data Structures Laboratory - 18CSL38 III Semester / B.E
EXPERIMENT – 12: Liner probing Enter the choice:1
Given a File of N employee records with a set K of Keys(4-digit) which uniquely determine the if(flag==0) HTKey EmpID EmpName
printf("\n Hash table is full"); 0 0
records in file F. Assume that file F is maintained in memory by a Hash Table(HT) of m 1 0
else{
memory locations with L as the set of memory addresses (2-digit) of locations in HT. Let 2 100 Ricky
printf("\nEnter emp id: "); 3 0
the keys in K and addresses in L are Integers. Design and develop a Program in C that uses scanf("%d",&emp[i].id); 4 0
printf("\nEnter emp name: "); 5 0
Hash function H: K L as H(K)=K mod m (remainder method), and implement hashing scanf("%s",emp[i].name); 6 0
technique to map a given key K to the address space L. Resolve the collision (if any) a[i]=i; 7 101 Reena
printf("\nCollision avoided successfully using LINEAR PROBING\n"); 8 0
using linear probing } 9 0
} #Run 2
void Display(){ Collision handling by linear probing:
Enter the data: 2
Algorithm: int i, ch;
Enter emp id: 101
printf("\n1.Display ALL\n2.Filtered Display \n Enter the choice:"); Enter emp name: Raj
Read employee record, generate hash value using key scanf("%d",&ch); Collision avoided successfully using LINEAR PROBING
printf("\nHTKey\tEmpID\tEmpName"); Do you wish to continue? (1/0): 1
Scan the hash table for inserting the record in the proper place , if place is for(i=0; i<MAX; i++){ Enter the data: 4
if(ch==2 && a[i] == -1) Enter emp id: 102
empty , then insert the record otherwise the go the next location.
continue; Enter emp name: Raina
If a record found the table display a message and try for next unused else Collision avoided successfully using LINEAR PROBING
printf("\n%d\t%d\t%s", i, emp[i].id, emp[i].name); Do you wish to continue? (1/0): 0
location. 1.Display ALL 2.Filtered Display
}
Enter the choice:2
}
If no place found , display a message “ Hash table is full” int main(){
The hash table is:
HTKey EmpID EmpName
If a place is found the table, insert the inpit data such as ID and Name. int num, key, i; 2 101 Raj
CODE: int ch = 1; 4 102 Raina
#include<stdio.h> printf("\nCollision handling by linear probing: "); #Run 3
#include <stdlib.h> for (i=0; i < MAX; i++) { Collision handling by linear probing:
a[i] = -1; Enter the data: 2
#define MAX 10 Enter emp id: 100
struct employee{ }
Enter emp name: Reema
int id; do{
Collision avoided successfully using LINEAR PROBING
char name[15]; printf("\nEnter the data: "); Do you wish to continue? (1/0): 1
}; scanf("%d", &num); Enter the data: 2
typedef struct employee EMP; Linear_prob(num % 100,num); Collision Detected...!!!
EMP emp[MAX]; printf("\nDo you wish to continue? (1/0): "); Enter emp id: 101
int a[MAX]; scanf("%d",&ch); Enter emp name: Robert
void Linear_prob(int key, int num){ }while(ch); Do you wish to continue? (1/0): 1
Display(); Enter the data: 2
int flag=0, i=key;
} Collision Detected...!!!
if(a[i] == -1) Enter emp id: 103
flag=1; Enter emp name: Richard
OUTPUT
else{
#Run 1
printf("\nCollision Detected...!!!\n"); Collision handling by linear probing:
i=(key+1)%MAX; Enter the data: 2
do{ Enter emp id: 100
if(a[i] == -1) { Enter emp name: Ricky
flag = 1; Collision avoided successfully using LINEAR PROBING
break; Do you wish to continue? (1/0): 1
} Enter the data: 7
else Enter emp id: 101
i=(++i)%MAX; Enter emp name: Reena
Collision avoided successfully using LINEAR PROBING
}while(i!=key && flag==0);
Do you wish to continue? (1/0): 0
} 1.Display ALL 2.Filtered Display
Dept. of ISE,SIT, Mangaluru Page|31 Dept. of ISE,SIT, Mangaluru Page|32 Dept. of ISE,SIT, Mangaluru Page|33
Data Structures Laboratory - 18CSL38 III Semester / B.E Department of Computer Science and Engineering
50. How do you construct a binary tree?
Sample Viva Questions
51. Give the structure for implementing a Binary search tree.
1. What is an array? 52. What is skewed tree?
2. What is the use of top in Stack? 53. What is sibling?
3. How top is updated during stack operation? 54. For tree (assume a tree), give the preorder, postorder and inorder traversal.
4. How do you create an array to hold 15 integer items? 55. What is expression tree?
5. How many memory locations are utilized for 15 items integer array? 56. How do you construct expression tree?
6. What is pointer? 57. How do you construct BST for given inorder and postorder expression?
7. What is the difference between &a and *a in C code? 58. What is a graph?
8. What is the use of NULL? 59. How graph is useful in computer science?
9. How do you keep track of queue, during its operations? 60. How do create a graph?
10. What are the conditions to be checked during stack operation? 61. What is adjacency matrix?
11. What is dynamic stack? 62. Assume a graph and give the adjacency matrix
12. How dynamic stack is useful over static allocation? 63. What is the difference between BST and DFS?
13. When do you say overflow and underflow? 64. What is hash key?
14. What is pattern? 65. What is collision?
15. What is the logic used in simple pattern matching algorithm? 66. How do you handle collision?
16. Differentiate Postfix, Prefix and Infix expression 67. How linear probing works?
17. What is the postfix and prefix of expression : a+b/c*d$e 68. For the given SLL, node NewNode and a SLL head is Root. What is effect of statements:
18. What is recursion? NewNode=Root; and Root =NewNode;
19. How stack is used during recursion? 69. For the given SLL, node NewNode and a SLL head is Root. What is effect of statements:
20. What is the difference between recursion and infinite loop? NewNodenext=Root and Rootnext =NewNode
21. What is linked list? 70. For the given SLL, node NewNode and a SLL head is Root. What is effect of statements:
22. What is the advantage of linked list over array? free(NewNode); and free(Root);
23. How do you allocate memory to hold data consisting name and ID? 71. Give a piece of code to insert an element into the middle of array.
24. What is the use of sizeof in malloc function? 72. Give a piece of code to remove an element into the middle of array.
25. How do you design stack using linked list? 73. Give any one example for hash function.
26. How do you implement queue using linked list? 74. What is the use of –lm option when you compile certain c program?
27. What is the disadvantage of linked list 75. Give the piece of code to display content of SLL.
28. What is the idea of single linked list? 76. Give the piece of code to read data for node of DLL.
29. How Double linked list is different over single linked list? 77. How do you retrieve content of integer array whose size is 10?
30. What is the application of stack? 78. Identify the mistake in the below given piece of code
31. Give one application for queue? While(temp->next !NULL);
32. When a SLL and DLL can be used? Temp->next=Temp ;
33. How circular list differ over SLL? 79. What is the effect of code : temp->next =temp and Temp=Temp->next
34. Give the C structure for SLL. Assume Only one field of type int 80. What is the use of (NODE) in malloc function ?
35. Give the C structure for DLL. Assume Only one field of type int 81. What is the effect of statement print(“%d”, a[0]) and print(“%d”, *a);
36. What is traversing? 82. For the statement printf(“%d”, a[0]) , what is nature of array?
37. What are the operations that can be performed over SLL or DLL or CLL? 83. Create a structure a single linked list
38. What is Head node? 84. Identify the mistake in the below given piece of code
39. What is the use of Head? if(Count=MAX);
40. Evaluate the expression: AB+CDE -*/ given A=5, B=6 C=4 D=3 E=7 Count++ ;
41. Give the piece of code to insert a node at end of the list assume necessary information? 85. What is spanning tree?
42. How do you insert a node at the beginning of linked list? 86. What is data structure?
43. How do you remove a node which is at the rear end? 87. What is the application of Data structure?
44. Give the piece of code remove a node from the beginning. 88. What are the types of data structure? Give an example also
45. What is the result of statement Head=NULL, if it contains 5 nodes. 89. How do you represent polynomial using array of structure?
46. Give the piece of code to add 5 nodes to a circular linked list. 90. Give the structure of a polynomial with 3 variables (6XYZ)
47. What is a tree?
48. What is binary tree?
49. What is the use of binary tree?