SlideShare una empresa de Scribd logo
1 de 6
Explain Abstract data types with its characteristics.
Answer
Whenever a programmer has been told to write any program first thing with which he is encountered is
the “problem “in writing a program. Therefore to overcome this problem first thing to be done is too get
to know about the problem and separate the necessary and unnecessary details from it so that the
programmed could have a clear view of the problem to solve or you can say to have a view of his own
on the problem, This is called Abstraction therefore with the help of abstraction it is easier for the
programmer to think about the problem to be solved.
Defined as structuring of problem into well-defined entities by defining their data and operations.
Characteristics of Abstract data types:
1. It exports a type
2. It exports set of operations
3. Operation of interface are the one and only access mechanism to the type’s data structure.
4. Axioms and preconditions define the application domain of the type.
Let us say your Learning Centre decides to store all the three types of student data:
a. Register-Number
b. Name
c. Age
In a single data type, which is the most suitable data type? Give its syntax
Answer
The most suitable data type in the list is the Register Number. This is because every individual upon
registration in offered a number for his name. With a simple search using the Register Number, all your
registration details will be displayed.
Further structure is the best suitable data type to store data in single data type.
Syntax:
struct Student
{
int regno;
char name[20];
int age;
};
For the following Graph, Write its equivalent Adjacency list and Adjacency Matrix
Answer
Adjacency List
NODES ADJACENCY LIST
A B
B A,D
D B,E,F
E D
F D
Adjacency Matrix
a b d e f
a 0 1 0 0 0
b 1 0 1 0 0
d 0 1 0 1 1
e 0 0 1 0 0
f 0 0 1 0 0
A
D
B
F
E
Explain quick sort and tree sort.
Answer
Quick Sort:
It is also known as partition sort and it is the most widely used internal sorting algo also it is one of the
fastest algo but it is also complex one to code.
The basis of quick sort is divide and conquer i.e. divide the list to be sorted into sub lists until sub lists
are sorted. Quick sort begins by picking an element to be the pivot value. Then when the pivot value is
selected the array is divided into three parts: all value less the pivot value, the pivot value, and value
greater than the pivot value .when this is finished then the pivot value is in the proper position in the
sorted array. Then quick sort recursively applies the same process to first partition, containing low
values and to the second partition which contains the high value. Each time one pivot find its final place
in the array and partition gets smaller until the complete array is sorted.
Tree Sort:
Tree sort requires additional space for a tree to be constructed. a tree sort begins by visiting each
element of the array and adding it to an ordinary tree . When all the elements of the array have been
added to the trees, we walk the tree and repopulate the array in sorted order.
In the worst case, the original tree is already in the sorted order. If this happens, then for each element
of the array we will end up adding that element as a leaf on a tree that is a linked list
Write a C-program to implement stack using array data structure and perform the following stack
operations (a) POP (b) PUSH
Answer
#include<stdio.h>
#include<conio.h>
int stack[MAX];
int top;
void push(int token)
{
char a;
if(top==MAX-1)
{
printf("Stack full");
return;
}
do
{
printf("nEnter the token to be inserted:");
scanf("%d",&token);
top=top+1;
stack[top]=token;
printf("do you want to continue insertion Y/N");
a=getch();
}
while(a=='y');
}
int pop()
{
int t;
if(top==-1)
{
printf("Stack empty");
return -1;
}
t=stack[top];
top=top-1;
return t;
}
void show()
{
int i;
printf("nThe Stack elements are:");
for(i=0;i<=top;i++)
{
printf("%d",stack[i]);
}
}
int main()
{
char ch , a='y';
int choice, token;
top=-1;
printf("1.Insert");
printf("n2.Delete");
printf("n3.show or display");
do
{
printf("nEnter your choice for the operation: ");
scanf("%d",&choice);
switch(choice)
{
case 1:
{push(token);
show();
break;
}
case 2:
{
token=pop();
printf("nThe token deleted is %d",token);
show();
break;
}
case 3:
{
show();
break;
}
default:printf("Wrong choice");
break;
}
printf("nDo you want to continue(y/n):");
ch=getch();
}
while(ch=='y'||ch=='Y');
getch();
}
Write a C program to demonstrate linked list implementation of stack
Answer
#include <stdio.h>
void push();
void pop();
void display();
struct node
{
int info;
struct node *link;
} *top = NULL;
int item;
main()
{
int ch;
do
{
printf("nn1. Pushn2. Popn3. Displayn4. Exitn");
printf("nEnter your choice: ");
scanf("%d", &ch);
switch(ch)
{
case 1:
push();
break;
case 2:
pop();
break;
case 3:
display();
break;
case 4:
exit(0);
void display()
{
struct node *ptr;
if (top == NULL)
printf("nnStack is emptyn");
else
{
ptr = top;
while(ptr != NULL)
{
printf("nn%d", ptr->info);
ptr = ptr->link;
}
}
}

Más contenido relacionado

La actualidad más candente

User defined data type
User defined data typeUser defined data type
User defined data type
Amit Kapoor
 
Lecture 1 data structures and algorithms
Lecture 1 data structures and algorithmsLecture 1 data structures and algorithms
Lecture 1 data structures and algorithms
Aakash deep Singhal
 
Data structure
Data structureData structure
Data structure
Mohd Arif
 
Introduction to Data Structure
Introduction to Data StructureIntroduction to Data Structure
Introduction to Data Structure
Jazz Jinia Bhowmik
 

La actualidad más candente (19)

R Datatypes
R DatatypesR Datatypes
R Datatypes
 
Data structures
Data structuresData structures
Data structures
 
Chapter 8: tree data structure
Chapter 8:  tree data structureChapter 8:  tree data structure
Chapter 8: tree data structure
 
R data types
R data typesR data types
R data types
 
User defined data type
User defined data typeUser defined data type
User defined data type
 
Lab6: I/O and Arrays
Lab6: I/O and ArraysLab6: I/O and Arrays
Lab6: I/O and Arrays
 
Lecture 1 data structures and algorithms
Lecture 1 data structures and algorithmsLecture 1 data structures and algorithms
Lecture 1 data structures and algorithms
 
Data structure
Data structureData structure
Data structure
 
Data structure
Data structureData structure
Data structure
 
Data Structure
Data StructureData Structure
Data Structure
 
Introduction to data structure ppt
Introduction to data structure pptIntroduction to data structure ppt
Introduction to data structure ppt
 
C programming
C programmingC programming
C programming
 
Introduction to Data Structure
Introduction to Data StructureIntroduction to Data Structure
Introduction to Data Structure
 
Data structure and its types.
Data structure and its types.Data structure and its types.
Data structure and its types.
 
Mit102 data & file structures
Mit102  data & file structuresMit102  data & file structures
Mit102 data & file structures
 
Ii pu cs practical viva voce questions
Ii pu cs  practical viva voce questionsIi pu cs  practical viva voce questions
Ii pu cs practical viva voce questions
 
Data structure using c++
Data structure using c++Data structure using c++
Data structure using c++
 
Lecture 1 and 2
Lecture 1 and 2Lecture 1 and 2
Lecture 1 and 2
 
Unit 4
Unit 4Unit 4
Unit 4
 

Similar a Bc0038– data structure using c

DATA STRUCTURE AND ALGORITJM POWERPOINT.ppt
DATA STRUCTURE AND ALGORITJM POWERPOINT.pptDATA STRUCTURE AND ALGORITJM POWERPOINT.ppt
DATA STRUCTURE AND ALGORITJM POWERPOINT.ppt
yarotos643
 
data structure details of types and .ppt
data structure details of types and .pptdata structure details of types and .ppt
data structure details of types and .ppt
poonamsngr
 
DS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and EngineeringDS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and Engineering
RAJASEKHARV8
 
Abstract Data Types (a) Explain briefly what is meant by the ter.pdf
Abstract Data Types (a) Explain briefly what is meant by the ter.pdfAbstract Data Types (a) Explain briefly what is meant by the ter.pdf
Abstract Data Types (a) Explain briefly what is meant by the ter.pdf
karymadelaneyrenne19
 

Similar a Bc0038– data structure using c (20)

data structures module I & II.pptx
data structures module I & II.pptxdata structures module I & II.pptx
data structures module I & II.pptx
 
DS_PPT.pptx
DS_PPT.pptxDS_PPT.pptx
DS_PPT.pptx
 
1597380885789.ppt
1597380885789.ppt1597380885789.ppt
1597380885789.ppt
 
DATA STRUCTURE AND ALGORITJM POWERPOINT.ppt
DATA STRUCTURE AND ALGORITJM POWERPOINT.pptDATA STRUCTURE AND ALGORITJM POWERPOINT.ppt
DATA STRUCTURE AND ALGORITJM POWERPOINT.ppt
 
data structure in programing language.ppt
data structure in programing language.pptdata structure in programing language.ppt
data structure in programing language.ppt
 
Data structures "1" (Lectures 2015-2016)
Data structures "1" (Lectures 2015-2016) Data structures "1" (Lectures 2015-2016)
Data structures "1" (Lectures 2015-2016)
 
PM.ppt
PM.pptPM.ppt
PM.ppt
 
PM.ppt
PM.pptPM.ppt
PM.ppt
 
Bt0065
Bt0065Bt0065
Bt0065
 
B T0065
B T0065B T0065
B T0065
 
data structure details of types and .ppt
data structure details of types and .pptdata structure details of types and .ppt
data structure details of types and .ppt
 
DS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and EngineeringDS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and Engineering
 
DS_PPT.ppt
DS_PPT.pptDS_PPT.ppt
DS_PPT.ppt
 
Data structure
 Data structure Data structure
Data structure
 
data structure programing language in c.ppt
data structure programing language in c.pptdata structure programing language in c.ppt
data structure programing language in c.ppt
 
intr_ds.ppt
intr_ds.pptintr_ds.ppt
intr_ds.ppt
 
Abstract Data Types (a) Explain briefly what is meant by the ter.pdf
Abstract Data Types (a) Explain briefly what is meant by the ter.pdfAbstract Data Types (a) Explain briefly what is meant by the ter.pdf
Abstract Data Types (a) Explain briefly what is meant by the ter.pdf
 
Data structures and algorithms short note (version 14).pd
Data structures and algorithms short note (version 14).pdData structures and algorithms short note (version 14).pd
Data structures and algorithms short note (version 14).pd
 
Datastructures using c++
Datastructures using c++Datastructures using c++
Datastructures using c++
 
6.array
6.array6.array
6.array
 

Último

notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
MsecMca
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Christo Ananth
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
dollysharma2066
 

Último (20)

notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 

Bc0038– data structure using c

  • 1. Explain Abstract data types with its characteristics. Answer Whenever a programmer has been told to write any program first thing with which he is encountered is the “problem “in writing a program. Therefore to overcome this problem first thing to be done is too get to know about the problem and separate the necessary and unnecessary details from it so that the programmed could have a clear view of the problem to solve or you can say to have a view of his own on the problem, This is called Abstraction therefore with the help of abstraction it is easier for the programmer to think about the problem to be solved. Defined as structuring of problem into well-defined entities by defining their data and operations. Characteristics of Abstract data types: 1. It exports a type 2. It exports set of operations 3. Operation of interface are the one and only access mechanism to the type’s data structure. 4. Axioms and preconditions define the application domain of the type. Let us say your Learning Centre decides to store all the three types of student data: a. Register-Number b. Name c. Age In a single data type, which is the most suitable data type? Give its syntax Answer The most suitable data type in the list is the Register Number. This is because every individual upon registration in offered a number for his name. With a simple search using the Register Number, all your registration details will be displayed. Further structure is the best suitable data type to store data in single data type. Syntax: struct Student { int regno; char name[20]; int age; };
  • 2. For the following Graph, Write its equivalent Adjacency list and Adjacency Matrix Answer Adjacency List NODES ADJACENCY LIST A B B A,D D B,E,F E D F D Adjacency Matrix a b d e f a 0 1 0 0 0 b 1 0 1 0 0 d 0 1 0 1 1 e 0 0 1 0 0 f 0 0 1 0 0 A D B F E
  • 3. Explain quick sort and tree sort. Answer Quick Sort: It is also known as partition sort and it is the most widely used internal sorting algo also it is one of the fastest algo but it is also complex one to code. The basis of quick sort is divide and conquer i.e. divide the list to be sorted into sub lists until sub lists are sorted. Quick sort begins by picking an element to be the pivot value. Then when the pivot value is selected the array is divided into three parts: all value less the pivot value, the pivot value, and value greater than the pivot value .when this is finished then the pivot value is in the proper position in the sorted array. Then quick sort recursively applies the same process to first partition, containing low values and to the second partition which contains the high value. Each time one pivot find its final place in the array and partition gets smaller until the complete array is sorted. Tree Sort: Tree sort requires additional space for a tree to be constructed. a tree sort begins by visiting each element of the array and adding it to an ordinary tree . When all the elements of the array have been added to the trees, we walk the tree and repopulate the array in sorted order. In the worst case, the original tree is already in the sorted order. If this happens, then for each element of the array we will end up adding that element as a leaf on a tree that is a linked list
  • 4. Write a C-program to implement stack using array data structure and perform the following stack operations (a) POP (b) PUSH Answer #include<stdio.h> #include<conio.h> int stack[MAX]; int top; void push(int token) { char a; if(top==MAX-1) { printf("Stack full"); return; } do { printf("nEnter the token to be inserted:"); scanf("%d",&token); top=top+1; stack[top]=token; printf("do you want to continue insertion Y/N"); a=getch(); } while(a=='y'); } int pop() { int t; if(top==-1) { printf("Stack empty"); return -1; } t=stack[top]; top=top-1; return t; } void show() {
  • 5. int i; printf("nThe Stack elements are:"); for(i=0;i<=top;i++) { printf("%d",stack[i]); } } int main() { char ch , a='y'; int choice, token; top=-1; printf("1.Insert"); printf("n2.Delete"); printf("n3.show or display"); do { printf("nEnter your choice for the operation: "); scanf("%d",&choice); switch(choice) { case 1: {push(token); show(); break; } case 2: { token=pop(); printf("nThe token deleted is %d",token); show(); break; } case 3: { show(); break; } default:printf("Wrong choice"); break; } printf("nDo you want to continue(y/n):"); ch=getch(); } while(ch=='y'||ch=='Y'); getch(); }
  • 6. Write a C program to demonstrate linked list implementation of stack Answer #include <stdio.h> void push(); void pop(); void display(); struct node { int info; struct node *link; } *top = NULL; int item; main() { int ch; do { printf("nn1. Pushn2. Popn3. Displayn4. Exitn"); printf("nEnter your choice: "); scanf("%d", &ch); switch(ch) { case 1: push(); break; case 2: pop(); break; case 3: display(); break; case 4: exit(0); void display() { struct node *ptr; if (top == NULL) printf("nnStack is emptyn"); else { ptr = top; while(ptr != NULL) { printf("nn%d", ptr->info); ptr = ptr->link; } } }