DS Manual - 22scheme - Updated
DS Manual - 22scheme - Updated
Prepared by: -
CO2 Design & demonstrate linear data structures and their applications such as Applying (K3)
stacks, queues and lists
CO3 Analyze and implement non-Linear data structures and their Applying (K3)
applications such as trees and graphs
Institution Vision & Mission
MISSION:
MISSION:
Department of Computer Science and Engineering shall,
❖ Provide good infrastructure and facilitate learning to become competent
engineers who meet global challenges.
❖ Encourages industry institute interaction to give an edge to the students.
❖ Facilitates experimental learning through interdisciplinary projects.
❖ Strengthen soft skill to address global challenges.
K.S. SCHOOL OF ENGINEERING AND MANAGEMENT
# 15, Mallasandra, off Kanakapura Road, Bengaluru-560109
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
3. Design, Develop and Implement a menu driven Program in C for the following operations on
STACKof Integers (Array Implementation of Stack with maximum size MAX)
a. Push an Element on to Stack
b. Pop an Element from Stack
c. Demonstrate how Stack can be used to check Palindrome 13
d. Demonstrate Overflow and Underflow situations on Stack
e. Display the status of Stack
f. Exit
Support the program with appropriate functions for each of the above operations
4. Design, Develop and Implement a Program in C for converting an Infix Expression to Postfix
Expression. Program should support for both parenthesized and free parenthesized
expressions with the operators: +, -, *, /, % (Remainder), ^ (Power) and alphanumeric operands. 20
5. Design, Develop and Implement a Program in C for the following Stack Applications
a. Evaluation of Suffix expression with single digit operands and operators: +, -, *, /, %,^
b. Solving Tower of Hanoi problem with n disks 23
6. Design, Develop and Implement a menu driven Program in C for the following operations onCircular
QUEUE of Characters (Array Implementation of Queue with maximum size MAX)
a. Insert an Element on to Circular QUEUE
b. Delete an Element from Circular QUEUE
27
c. Demonstrate Overflow and Underflow situations on Circular QUEUE
d. Display the status of Circular QUEUE
e. Exit
Support the program with appropriate functions for each of the above operations
7. Design, Develop and Implement a menu driven Program in C for the following operations onSingly
Linked List (SLL) of Student Data with the fields: USN, Name, Programme, Sem, PhNo
a. Create a SLL of N Students Data by using front insertion.
b. Display the status of SLL and count the number of nodes in it 35
c. Perform Insertion / Deletion at End of SLL
d. Perform Insertion / Deletion at Front of SLL(Demonstration of stack)
e. Exit
8. Design, Develop and Implement a menu driven Program in C for the following operations onDoubly
Linked List (DLL) of Employee Data with the fields: SSN, Name, Dept, Designation, Sal, PhNo
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
c. Perform Insertion and Deletion at End of DLL 44
d. Perform Insertion and Deletion at Front of DLL
e. Demonstrate how this DLL can be used as Double Ended Queue.
f. Exit
9. Design, Develop and Implement a Program in C for the following operationson SinglyCircular
Linked List (SCLL) with header nodes
a. Represent and Evaluate a Polynomial P(x,y,z) = 6x2y2z-4yz5+3x3yz+2xy5z-2xyz3
b. Find the sum of two polynomials POLY1(x,y,z) and POLY2(x,y,z) and store theresult in 54
POLYSUM(x,y,z)
Support the program with appropriate functions for each of the above operations
10. Design, Develop and Implement a menu driven Program in C for the following operations onBinary
Search Tree (BST) of Integers .
a. Create a BST of N Integers: 6, 9, 5, 2, 8, 15, 24, 14, 7, 8, 5, 2
b. Traverse the BST in Inorder, Preorder and Post Order 60
c. Search the BST for a given element (KEY) and report the appropriate message
d. Exit
11. Design, Develop and Implement a Program in C for the following operations on Graph(G)of Cities
a. Create a Graph of N cities using Adjacency Matrix.
b. Print all the nodes reachable from a given starting node in a digraph using DFS/BFSmethod 66
12. Given a File of N employee records with a set K of Keys (4-digit) which uniquely determinethe records
in file F. Assume that file F is maintained in memory by a Hash Table (HT) of mmemory locations with
L as the set of memory addresses (2-digit) of locations in HT. Let thekeys in K and addresses in L are
Integers. Design and develop a Program in C that uses Hashfunction H: K ->L as H(K)=K mod m 70
(remainder method), and implement hashing technique to map a given key K to the address space L.
Resolve the collision (if any) using linear probing.
2. Design, Develop and Implement a Program in C for the following operations on Strings.
a. Read a main String (STR), a Pattern String (PAT) and a Replace String (REP)
b. Perform Pattern Matching Operation: Find and Replace all occurrences of PAT in STR 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-in functions.
3. Design, Develop and Implement a menu driven Program in C for the following operations on
STACK of Integers (Array Implementation of Stack with maximum size MAX)
a. Push an Element on to Stack
b. Pop an Element from Stack
c. Demonstrate how Stack can be used to check Palindrome
d. Demonstrate Overflow and Underflow situations on Stack
e. Display the status of Stack
f. Exit
Support the program with appropriate functions for each of the above operations
4. Design, Develop and Implement a Program in C for converting an Infix Expression to Postfix
Expression. Program should support for both parenthesized and free parenthesized
expressions with the operators: +, -, *, /, % (Remainder), ^ (Power) and alphanumeric
operands.
5. Design, Develop and Implement a Program in C for the following Stack Applications
a. Evaluation of Suffix expression with single digit operands and operators: +, -, *, /, %,
^
b. Solving Tower of Hanoi problem with n disks
6. Design, Develop and Implement a menu driven Program in C for the following operations on
Circular QUEUE of Characters (Array Implementation of Queue with maximum size MAX)
a. Insert an Element on to Circular QUEUE
b. Delete an Element from Circular QUEUE
c. Demonstrate Overflow and Underflow situations on Circular QUEUE
d. Display the status of Circular QUEUE
e. Exit
Support the program with appropriate functions for each of the above operations
7. Design, Develop and Implement a menu driven Program in C for the following operations on
Singly Linked List (SLL) of Student Data with the fields: USN, Name, Programme, Sem,
PhNo
a. Create a SLL of N Students Data by using front insertion.
b. Display the status of SLL and count the number of nodes in it
c. Perform Insertion / Deletion at End of SLL
d. Perform Insertion / Deletion at Front of SLL(Demonstration of stack)
e. Exit
8. Design, Develop and Implement a menu driven Program in C for the following operations on
Doubly Linked List (DLL) of Employee Data with the fields: SSN, Name, Dept, Designation,
Sal, PhNo
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
c. Perform Insertion and Deletion at End of DLL
d. Perform Insertion and Deletion at Front of DLL
e. Demonstrate how this DLL can be used as Double Ended Queue.
f. Exit
9. Design, Develop and Implement a Program in C for the following operationson Singly
Circular Linked List (SCLL) with header nodes
a. Represent and Evaluate a Polynomial P(x,y,z) = 6x2y2z-4yz5+3x3yz+2xy5z-2xyz3
b. Find the sum of two polynomials POLY1(x,y,z) and POLY2(x,y,z) and store the
result in POLYSUM(x,y,z)
Support the program with appropriate functions for each of the above operations
10. Design, Develop and Implement a menu driven Program in C for the following operations on
Binary Search Tree (BST) of Integers .
a. Create a BST of N Integers: 6, 9, 5, 2, 8, 15, 24, 14, 7, 8, 5, 2
b. Traverse the BST in Inorder, Preorder and Post Order
c. Search the BST for a given element (KEY) and report the appropriate message
d. Exit
11. Design, Develop and Implement a Program in C for the following operations on Graph(G)
of Cities
a. Create a Graph of N cities using Adjacency Matrix.
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 in file F. Assume that file F is maintained in memory by a Hash Table (HT) of m
memory locations with L as the set of memory addresses (2-digit) of locations in HT. Let the
keys in K and addresses in L are Integers. Design and develop a Program in C that uses Hash
function H: K →L as H(K)=K mod m (remainder method), and implement hashing
technique to map a given key K to the address space L. Resolve the collision (if any) using
linear probing.
Laboratory Outcomes: The student should be able to:
• Analyze and Compare various linear and non-linear data structures
• Demonstrate the working nature of different types of data structures and theirapplications.
• Use appropriate searching and sorting algorithms for the give scenario.
• Apply the appropriate data structure for solving real world problems
Laboratory Experiments:
1. Develop a Program in C for the following:
a) Declare a calendar as an array of 7 elements (A dynamically Created array) to represent 7 days of a
week. Each Element of the array is a structure having three fields. The first field is the name of the Day
(A dynamically allocated String), The second field is the date of the Day (A integer), the third field is
the description of the activity for a particular day (A dynamically allocated String).
b) Write functions create(), read() and display(); to create the calendar, to read the data from the keyboard
and to print weeks activity details report on screen.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
return day;
}
return 0;
}
2. Design, Develop and Implement a Program in C for the following operations on Strings
a. Read a main String (STR), a Pattern String (PAT) and a Replace String (REP)
b. Perform Pattern Matching Operation: Find and Replace all occurrences of PAT in STR 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-in functions.
#include<stdio.h>
void readstr(void);
void readsearchstr(void);
void readreplacestr(void);
void matching(char str[100]);
char mainstr[100],pat[100],replace[100],ans[100];
void main()
{
readstr();
readsearchstr();
readreplacestr();
matching(mainstr);
}
void readstr(void)
{
printf("\n enter a string\n");
gets(mainstr);
}
void readsearchstr(void)
{
printf("enter a search string\n");
gets(pat);
}
void readreplacestr(void)
{
printf("\n enter a replace string\n");
gets(replace);
}
void matching(char mainstr[100])
{
char ans[100];
int i,j,c,m,k,flag;
i=m=c=j=flag=0;
while(mainstr[c]!='\0')
{
if(mainstr[m]==pat[i])
{
i++;
m++;
if(pat[i]=='\0')
{
for(k=0;replace[k]!='\0';k++,j++)
ans[j]=replace[k];
i=0;
Dept. of CSE, KSSEM Page 5
DATA STRUCTURES LABORATORY BCSL305
c=m;
}
} flag=1;
else
{
ans[j]=mainstr[c];
j++;
c++;
m=c;
i=0;
}
}
ans[j]='\0';
if(flag==0)
{
printf("search string is not present\n");
printf("the resultant string is %s",ans);
}
else
3. Design, Develop and Implement a menu driven Program in C for the following operations on STACK of
integers (Array Implementation of Stack with maximum size MAX)
a. Push an Element on to Stack
b. Pop an Element from Stack
c. Demonstrate how Stack can be used to check Palindrome
d. Demonstrate Overflow and Underflow situations on Stack
e. Display the status of Stack
f. Exit
Support the program with appropriate functions for each of the above operations
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX 5
int stack[MAX],top=-1;char
stack1[MAX],top1=-1;
void push()
{
int ele;
if(top<MAX-1)
{
printf("enter the value to be inserted into the stack:\n");
scanf("%d",&ele);
stack[++top]=ele;
}
else
printf("\n stack is full\n");
return;
}
void pop()
{
if(top!=-1)
{
printf("\n the element deleted from the stack is:%d\n",stack[top--]);
}
else
printf("\n stack is empty\n");
return;
}
void palindrome()
{
int i,count=0,len;
char str[100];
printf("\n entertring to check whether it is palindrome or not:");
scanf("%s",str);
len=strlen(str);
for(i=0;i<len;i++)
{
stack1[++top1]=str[i];
Dept. of CSE, KSSEM Page 8
DATA STRUCTURES LABORATORY BCSL305
}
for(i=0;i<len;i++)
{
if(str[i]==stack1[top1--])
count++;
}
if(count==len)
printf("\n %s is a palindrome string\n",str);
else
printf("\n %s is not a palindrome string\n",str);
return;
}
void check()
{
if(top>=MAX-1)
printf("stack is overflow\n");
else if(top==-1)
printf("stack is underflow\n");
else
printf("stack operation can be performed\n");
}
void display()
{
int i;
if(top==-1)
{
printf("\n stack is empty\n");
}
else
{
printf("\n elements in the stack
are\n");for(i=top;i>=0;--i)
printf("|%d|\n",stack[i]);
}
return;
}
void main()
{
int choice;
while(1)
{
printf("\n STACK OPERATIONS\n");
printf("\n 1:push\t2:pop\t3:palindrome\t4:check\t5:display\t6:exit\n");
printf("\n enter your choice[1/2/3/4/5/6]:");
scanf("%d",&choice);
switch(choice)
{
case 1: push();break;
case 2: pop();break;
case 3: palindrome();break;
switch (elem)
{
case '#': return 0;
case '(': return 1;
case '+':
case '-': return 2;
case '*':
case '/':
case '%': return 3;
case '^': return 4;
}
}
void main() /* Main Program */
{
char infx[50], pofx[50], ch, elem;
int i = 0, k = 0;
if (ch == '(')
push(ch);
else if (isalnum(ch))
pofx[k++] = ch;
else if (ch == ')')
{
while (s[top] != '(')
pofx[k++] = pop();
elem = pop(); /* Remove */
}
else /* Operator */
{
while (pr(s[top]) >= pr(ch))
pofx[k++] = pop();
push(ch);
}
}
while (s[top] != '#') /* Pop from stack till empty */
pofx[k++] = pop();
pofx[k] = '\0'; /* Make pofx as valid string */
printf("\n\nGiven Infix Expn: %s Postfix Expn: %s\n", infx, pofx);
}
5. Design, Develop and Implement a Program in C for the following Stack Applications
a. Evaluation of Suffix expression with single digit operands and operators: +, -, *, /, %, ^
b. Solving Tower of Hanoi problem with n disks
#include<stdio.h>
#include<math.h>
#include<ctype.h>
int top=-1;
float s[50];
float pop()
{
return(s[top--]);
}
float eval(char postfix[50])
{
int i;
char symbol;
float opr1,opr2,value,res;
for(i=0;postfix[i]!='\0';i++)
{
symbol=postfix[i];
if(isdigit(symbol))
push(symbol-48);
else if(isalpha(symbol))
{
printf("\n enter the value for %c ",symbol);
scanf("%f",&value);
push(value);
}
else
{
opr2=pop();
opr1=pop();
res=operate(opr1,opr2,symbol);
push(res);
}
}
return(pop());
}
void main()
{
char postfix[80];
float res;
printf("\n Enter The Postfix Expression \n");
gets(postfix);
printf("The Given Expression is :");
puts(postfix);
res=eval(postfix);
printf("\nThe value of the expression is %f\n" ,res);
}
5a Program Output : Suffix expression
#include<stdio.h>
void towers(int n,char source,char dest,char auxilary);
void main()
{
int n;
printf("enter the number of disk\n");
scanf("%d",&n);
towers(n,'A','C','B');
}
void towers(int n,char source,char dest,char auxilary)
{
if(n==0)
return;
towers(n-1,source,auxilary,dest);
printf("move disk %d from %c to %c \n",n,source,dest);
towers(n-1,auxilary,dest,source);
}
6. Design, Develop and Implement a menu driven Program in C for the following operations on
Circular QUEUE of Characters (Array Implementation of Queue with maximum size MAX)
a. Insert an Element on to Circular QUEUE
b. Delete an Element from Circular QUEUE
c. Demonstrate Overflow and Underflow situations on Circular QUEUE
d. Display the status of Circular QUEUE
e. Exit
Support the program with appropriate functions for each of the above operations
#include<stdio.h>
#include<stdlib.h>
#define size 5
int CQ[size],f=-1,r=-1;
int CQfull()
{
if((f==r+1)||(f==0&&r==size-1))
return 1;
return 0;
}
int CQempty()
{
if(f==-1)
return 1;
return 0;
}
CQinsert(int ele)
{
if(CQfull())
printf("\n overflow!!!\n");
else
{
if(f==-1)
f=0;
r=(r+1)%size;
CQ[r]=ele;
}
}
int CQdelete()
{
int ele;
if(CQempty())
{
printf("\n underflow!!!\n");
return(-1);
}
else
{ ele=CQ[f];
if(f==r)
{
f=-1;
} r=-1;
else
Dept. of CSE, KSSEM Page 22
DATA STRUCTURES LABORATORY 18CSL38
f=(f+1)%size;
return(ele);
}
}
display()
{
int i;
if(CQempty())
printf("\n empty queue\n");
else
{
printf("front[%d]->",f);
for(i=f;i!=r;i=(i+1)%size)
printf(" %d ",CQ[i]);
printf(" %d ",CQ[i]);
printf("<-[%d]rear",r);
}
}
main()
{
int opn,ele;
do
{
printf("\n \n Circular queue operations\n");
printf("\n press 1-insert,2-delete,3-display,4-exit\n");
printf("\n your option? ");
scanf("%d",&opn);
switch(opn)
{
case 1:printf("\n read the element to be inserted ?\n");
scanf("%d",&ele);
CQinsert(ele);break;
case 2:ele=CQdelete();
if(ele!=-1)
printf("\n delete element is %d\n",ele);
break;
case 3:printf("\n status of circular queue \n\n");
display();
break;
case 4:exit(0);
default:printf("invalid option\n");
}
}
while(opn!=4);
}
7. Design, Develop and Implement a menu driven Program in C for the following operations on Singly Linked
List (SLL) of Student Data with the fields: USN, Name, Branch, Sem, PhNo
a. Create a SLL of N Students Data by using front insertion.
b. Display the status of SLL and count the number of nodes in it
c. Perform Insertion / Deletion at End of SLL
d. Perform Insertion / Deletion at Front of SLL(Demonstration of stack)
e. Exit
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
node *start=NULL;
node* getnode()
{
node *new1;
new1=(node *)malloc(sizeof(node));
printf("Enter the student \nUsn \nName \nBranch \nSemester \nPhone\n");
scanf("%s %s %s %d %s",new1->usn,new1->name,new1->branch,&new1->sem,new1->phone);
new1->next=NULL;
return(new1);
}
void display()
{
node *temp=start;
int count=0;
if(start==NULL)
{
printf("List Empty\n");
return;
}
printf("\n Usn:\t Name:\t Branch:\t Sem: \tPhone: \n");
while(temp!=NULL)
{
printf("%s\t%s\t%s\t\t%d\t%s\n",temp->usn,temp->name,temp->
branch,temp->sem,temp->phone);
temp=temp->next;
count++;
}
printf("The number of nodes are:%d\n ",count);
}
void createSLL()
{
int n,i=0;
printf("Enter the number of students to be created\n");
scanf("%d",&n);
while(i<n)
{ i++;
insert_front(); // or call insert_end();
}
return;
}
void insert_end()
{
node *new1,*temp=start;
new1=getnode();
if(start==NULL)
{
start=new1;
return;
}
while(temp->next!=NULL)
{
temp=temp->next;
}
temp->next=new1;
}
void del_front()
{
node *temp;
if(start==NULL)
{
printf("List is empty\n");
return;
}
temp=start;
start=start->next;
printf("The node of student usn %s is deleted\n",temp->usn);
void del_end()
{
node *cur,*pre;
if(start==NULL)
{
printf("List is empty\n");
return;
}
cur=start;
pre=NULL;
while(cur->next!=NULL)
{
pre=cur;
cur=cur->next;
}
if(pre==NULL)
start=NULL;
else
pre->next=NULL;
printf("The node of student usn %s is deleted\n",cur->usn);
free(cur);
}
void main()
{
int ch;
for(;;)
{
printf("\n 1: CraeteSLL \n 2. Insert Front \n 3: Insert End \n 4: Delete Front \n 5: Delete End \n
6:Display\n 7: Exit \n");
printf("Enter ur choice\n");
scanf("%d",&ch);
switch(ch)
{
case 1: createSLL();break;
case 2:insert_front();break;
case 3: insert_end(); break;
case 4: del_front();break;
case 5: del_end();break;
case 6: display();break;
default : printf("Invalid option\n");
exit(0);
}
}
}
8. Design, Develop and Implement a menu driven Program in C for the following operations on Doubly Linked
List (DLL) of Employee Data with the fields: SSN, Name, Dept, Designation, Sal, PhNo
#include<stdio.h>
#include<stdlib.h>
struct node {
char ssn[15],name[15],dept[15],desg[15],phno[15];
long int sal;
struct node *llink,*rlink;
};
typedef struct node *NODE;
NODE temp, first=NULL, end=NULL;
NODE getnode(void)
{
NODE x=(NODE)malloc(sizeof(struct node));
return x;
}
void read(void)
{
temp=getnode();
temp->llink=temp->rlink=NULL;
printf("Enter SSN:");
scanf("%s",temp->ssn);
printf("Enter Name:");
scanf("%s",temp->name);
printf("Enter Deptartment:");
scanf("%s",temp->dept);
printf("Enter Designation:");
scanf("%s",temp->desg);
printf("Enter PhoneNo:");
scanf("%s",temp->phno);
printf("Enter Salary:");
scanf("%ld",&temp->sal);
}
void create_dll(void)
{
int n,i=0;
printf("Enter the number of Employees:");
scanf("%d",&n);
while(i!=n)
{
i++;
Dept. of CSE, KSSEM Page 39
DATA STRUCTURES LABORATORY 18CSL38
printf("Enter details\n");
read();
if(first==NULL)
first=end=temp;
else
{
end->rlink=temp;
temp->llink=end;
end=temp;
}
}
printf("[+] DONE\n");
}
void displaycount(void)
{
NODE temp1=first;
int count=1;
if(temp1==NULL)
printf("[!] List is empty\n");
else
{
printf("SSN\tName\tDEPT\tDESIG\tPhone\tSalary\n");
printf(" -\t- \t -\t- \t \t \n");
while(temp1!=end)
{
count++;
printf("%s\t%s\t%s\t%s\t%s\t%ld\n",temp1->ssn,temp1->name,
temp1->dept,temp1->desg,temp1->phno, temp1->sal);
temp1=temp1->rlink;
}
printf("%s\t%s\t%s\t%s\t%s\t%ld\n",temp1->ssn,temp1->name,
temp1->dept,temp1->desg,temp1->phno, temp1->sal);
printf("\nCount:%d\n",count);
}
}
void insertfront(void)
{
printf("Enter Details\n");
read();
if(first==NULL)
first=temp;
else
{
temp->rlink = first;
first->llink = temp;
first=temp;
}
}
void insertend(void)
{
printf("Enter Details\n");
void deletefront(void)
{
NODE temp2;
if(first==NULL)
printf("[!] List is empty\n");
else if(first == end)
{
temp2 = first;
printf("[+] Deleted record %s\n",temp2->ssn);
first=end=NULL;
}
else
{
temp2= first;
printf("[+] Deleted record %s\n",temp2->ssn);
first = first->rlink;
temp2->llink = NULL;
free(temp2);
} }
void deleteend(void)
{
NODE temp2 = end;
if(temp2 == NULL)
printf("[!] List is empty\n");
else if(first==end)
{
printf("[+] Deleted record %s\n", temp2->ssn);
first = end =NULL;
}
else
{
printf("[+] Deleted record %s\n", temp2->ssn);
end=end->llink;
end->rlink=NULL;
free(temp2);
}
}
void main(void)
{
9. Design, Develop and Implement a Program in C for the following operations on Singly Circular Linked List
(SCLL) with header nodes
a. Represent and Evaluate a Polynomial P(x,y,z) = 6x2y2z-4yz5+3x3yz+2xy5z- 2xyz3
b. Find the sum of two polynomials POLY1(x,y,z) and POLY2(x,y,z) and store the result in
POLYSUM(x,y,z) Support the program with appropriate functions for each of the above operations
#include<stdio.h>
#include<malloc.h>
#include<math.h>
struct node
{
float cf;
int px,py,pz;
int flag;
struct node *link;
};
typedef struct node *NODE;
NODE getnode()
{
NODE x;
x=(NODE)malloc(sizeof(struct node));
if(x==NULL)
{
printf("out of memory\n");
exit(0);
}
return x;
}
NODE insert_rear(float cf,float x,float y,float z,NODE head)
{
NODE temp,cur;
temp=getnode();
temp->cf=cf;
temp->px=x;
temp->py=y;
temp->pz=z;
temp->flag=0;
cur=head->link;
while(cur->link!=head)
{
cur=cur->link;
}
cur->link=temp;
temp->link=head;
return head;
else
h3=insert_rear(cf1,x1,y1,z1,h3);
p1=p1->link;
}
p2=h2->link;
while(p2!=h2)
{
if(p2->flag==0)
{
h3=insert_rear(p2->cf,p2->px,p2->py,p2->pz,h3);
}
p2=p2->link;
NODE h1,h2,h3;
h1=getnode();
h2=getnode();
h3=getnode();
h1->link=h1;
h2->link=h2;
h3->link=h3;
10. Design, Develop and Implement a menu driven Program in C for the following operations on Binary Search
Tree (BST) of Integers
#include<stdio.h>
#include<stdlib.h>
#define MAX 10
struct node
{
int info;
struct node *llink;
struct node *rlink;
};
}
return x;
}
}
else
{
prev=NULL;
cur=root;
while(cur!=NULL)
{
prev=cur;
cur=(temp->info<cur->info)?cur->llink:cur->rlink;
}
}
return;
}
void in(NODE IN)
{
if(IN!=NULL)
{
in(IN->llink); printf("%d\t",IN->info);in(IN->rlink);
}
return;
}
void post(NODE POST)
{
if(POST!=NULL)
{
post(POST->llink);
post(POST->rlink);
printf("%d\t",POST->info);
}
return;
}
if(flag==1)
printf("key found\n");
else
printf("key not found\n");
return;
}
void main()
{
int choice,item;
NODE root=NULL;
while(1)
{
printf("\n1 create bst\n2 traverse\n3 search\n4 exit");
printf("\nEnter choice: ");
scanf("%d",&choice);
switch(choice)
{
case 1: printf("Enter item to be inserted: ");
scanf("%d",&item);
root=insert(item,root);break;
case 2: traversal(root);break;
case 3: search(root);break;
case 4: exit(0);
default: printf("enter prowopejwopu");
}
11. Design, Develop and Implement a Program in C for the following operations on Graph(G) of Cities
a. Create a Graph of N cities using Adjacency Matrix.
b. Print all the nodes reachable from a given starting node in a digraph using DFS/BFS method
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#define MAX 20
int G[MAX][MAX], n,visited[10];
void Creation_Graph()
{
int i,j;
printf("Enter the Number of Cities\n");
scanf("%d", &n);
printf("Enter the edges for the Cities\n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&G[i][j]);
}
}
printf("edges 0f the Cities are\n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf("%d\t",G[i][j]);
}
printf("\n");
}
printf("Adjacency matrix for the Cities is created succesfully\n");
}
void dfs(int source)
{
int v;
visited[source]=1;
for(v=0;v<n;v++)
if(G[source][v]==1&&visited[v]==0)
{
dfs(v);
}
return;
}
void main()
{
int choice,source;
while(1)
{
printf("\n\n\n\t1.create a graph .\t2.Test for connectivity......\t4.Exit...");
printf("\n\n\n\tEnter Your Choice: ");
scanf("%d",&choice);
switch(choice)
{
case 1:Creation_Graph();break;
case 3:exit(0);
12. Given a File of N employee records with a set K of Keys(4-digit) which uniquely determine the records in
file F. Assume that file F is maintained in memory by a Hash Table(HT) of m memory locations with L
as the set ofmemory addresses (2-digit) of locations in HT. Let the keys in K and addresses in L are
Integers. Design and develop a Program in C that uses Hash function H: K →L as H(K)=K mod m
(remainder method), and implement hashing technique to map a given key K to the address space L.
Resolve the collision (if any) using linear probing.
#include<stdio.h>
#include<stdlib.h>
#define MAX_ADDR 5
int hash (int key);
struct employee
{
int emp_id, emp_age;
char emp_name[25];
}emp[MAX_ADDR];
void main()
{
int i, ch, count = 0, index, haddr, id ;
for(;;)
{
printf("Enter 1 to insert record \n 2. to display record\n");
scanf("%d", &ch);
switch(ch)
{
case 1: if(count == MAX_ADDR)
{
printf("No free addres space\n");
break;
}
printf("Enter employee id\n");
scanf("%d", &id);
haddr = hash(id);
printf("Home address is %d\n", haddr);
for(i=0; i<MAX_ADDR; i++)
{
index = (haddr+i)%MAX_ADDR;
if(emp[index].emp_id == 0)
{
emp[index].emp_id = id;
printf("Enter the employee name\n");
scanf("%s", emp[index].emp_name);
printf("Enter the employee age\n");
scanf("%d", &emp[index].emp_age);
count++;
printf("Successfuly inserted at Actual Address: %d\n\n", index);
break;
}
}
break;
case 2: printf("?Employee details are\n");
VIVA QUESTIONS
1. What is data structure and explain its types as well as its operations?
It is a way of organizing data that considers not only the items stored, but also their relationship to each
other. General data structure types include the array, the file, the record, the table, the tree, and so on. Any data
structure is designed to organize data to suit a specific purpose so that it can be accessed and worked with in
appropriate ways. Data Structure is also a way of collecting and organizing data in such a way that we can perform
operations on these data in an effective way.
Linear data structure: a data structure which is sequential and continues in nature i.e. access the data in
sequential manner. Linear data structures are: array, linked list, stack and queue. Non-linear data structure: a data
structure which is not sequential. Non-linear data structures are: tree and graph.
The data in the data structures are processed by certain operations. The particular data structure chosen
largely depends on the frequency of the operation that needs to be performed on the data structure. Basic Operations:
Traversing, Searching, Insertion, Deletion, Sorting, Merging
2. List out the areas in which data structures are applied extensively?
3. What are the major data structures used in the following areas : RDBMS,
4. If you are using C language to implement the heterogeneous linked list, what pointer type will you use?
The heterogeneous linked list contains different data types in its nodes and we need a link, pointer to connect
them. As ordinary pointers cannot be used for this. So we go for void pointer. Void pointer is capable of storing
pointer to any type as it is a generic pointer type.
8. Convert the expression ((A + B) * C – (D – E) ^ (F + G)) to equivalent Prefix and Postfix notations.
Prefix Notation: ^ - * +ABC - DE + FG
Postfix Notation: AB + C * DE - - FG + ^
(d) Deletion.
Using insertion we can perform insertion sort, using selection we can perform selection sort, using exchange we
can perform the bubble sort (sorting methods). But no sorting method can be done just using deletion.
14. List out few of the applications that make use of Multilinked Structures?
(i) Sparse matrix (ii) Index generation.
16. What is the type of the algorithm used in solving the 8 Queens problem?
Backtracking and Branch Bound.
18. What is the bucket size, when the overlapping and collision occur at same time?
One. If there is only one entry possible in the bucket, when the collision occurs, there is no way to
accommodate the colliding value. This results in the overlapping of values.
19 .What is a Register?
A register is a small amount of memory within the CPU that is used to temporarily store instructions and data.
20. An ABSTRACT data type is a keyword of a programming language that specifies the amount of memory
needed to store data and the kind of data that will be stored in that memory location?
22.Which of the following abstract data types are NOT used by Integer Abstract
Data type group?
(i) short
(ii) int
(iii) float
(iv) long
23 .There are 8, 15, 13, and 14 nodes in four different trees. Which one of them
can form a full binary tree?
The answer is the tree with 15 nodes. In general, there are 2^n-1 nodes in a full
binary tree.
26. Hash Table(HT) linear probing: In hash table, the data is stored in an array format where each data value has
its own unique index value. Access of data becomes very fast, if we know the index of the desired data.
Hashing : Hashing is a technique to convert a range of key values into a range of indexes of an array. We're going
to use modulo operator to get a range of key values. Consider an example of hash table of size 20, and the following
items are to be stored. Item are in the (key,value) format.
Linear Probing : As we can see, it may happen that the hashing technique is used to create an already used index of
the array. In such a case, we can search the next empty location in the array by looking into the next cell until we
find an empty cell. This technique is called linear probing.