SlideShare a Scribd company logo
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;
}
}
}

More Related Content

PPT
Introductiont To Aray,Tree,Stack, Queue
PPT
Introduction of data structure
PPTX
Data Types - Premetive and Non Premetive
PPTX
Data Structures
PDF
Lesson 1 overview
PPTX
Introduction to data structure
PDF
Lesson 2.2 abstraction
PPTX
Data structure,abstraction,abstract data type,static and dynamic,time and spa...
Introductiont To Aray,Tree,Stack, Queue
Introduction of data structure
Data Types - Premetive and Non Premetive
Data Structures
Lesson 1 overview
Introduction to data structure
Lesson 2.2 abstraction
Data structure,abstraction,abstract data type,static and dynamic,time and spa...

What's hot (19)

PPTX
R Datatypes
PPT
Data structures
PPT
Chapter 8: tree data structure
PPTX
R data types
PPT
User defined data type
PDF
Lab6: I/O and Arrays
PPT
Lecture 1 data structures and algorithms
PPT
Data structure
PPTX
Data structure
PPTX
Data Structure
PPTX
Introduction to data structure ppt
PPTX
C programming
PDF
Introduction to Data Structure
PPTX
Data structure and its types.
DOCX
Mit102 data & file structures
PDF
Ii pu cs practical viva voce questions
PDF
Data structure using c++
PPTX
Lecture 1 and 2
PDF
R Datatypes
Data structures
Chapter 8: tree data structure
R data types
User defined data type
Lab6: I/O and Arrays
Lecture 1 data structures and algorithms
Data structure
Data structure
Data Structure
Introduction to data structure ppt
C programming
Introduction to Data Structure
Data structure and its types.
Mit102 data & file structures
Ii pu cs practical viva voce questions
Data structure using c++
Lecture 1 and 2
Ad

Similar to Bc0038– data structure using c (20)

PPTX
Lecture 1.pptxffffffffffffffcfffffffffff
PPTX
data structures module I & II.pptx
PPT
358 33 powerpoint-slides_4-introduction-data-structures_chapter-4
PPT
data structure algorithm example and example
PPT
Data_Structure With C_LECTURE ONE PPT123
PPTX
1-Introduction to Data Structures beginner.pptx
PPTX
DS Module 1.pptx
PPT
DATA STRUCTURE AND ALGORITJM POWERPOINT.ppt
PPT
1597380885789.ppt
DOCX
Data structure and algorithm.
DOC
Bt0065
DOC
B T0065
PDF
Data Structure - Lecture 2 - Recursion Stack Queue.pdf
PPT
DS_PPT.ppt
PPTX
DS Module 1.pptx
PPTX
Introduction-to-Data-Structure-and-Algorithm.pptx
PPTX
Data structures - unit 1
DOCX
Introduction to Data Structure and Algorithm
PDF
Introduction to Data Structure
Lecture 1.pptxffffffffffffffcfffffffffff
data structures module I & II.pptx
358 33 powerpoint-slides_4-introduction-data-structures_chapter-4
data structure algorithm example and example
Data_Structure With C_LECTURE ONE PPT123
1-Introduction to Data Structures beginner.pptx
DS Module 1.pptx
DATA STRUCTURE AND ALGORITJM POWERPOINT.ppt
1597380885789.ppt
Data structure and algorithm.
Bt0065
B T0065
Data Structure - Lecture 2 - Recursion Stack Queue.pdf
DS_PPT.ppt
DS Module 1.pptx
Introduction-to-Data-Structure-and-Algorithm.pptx
Data structures - unit 1
Introduction to Data Structure and Algorithm
Introduction to Data Structure
Ad

Recently uploaded (20)

PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PPTX
Construction Project Organization Group 2.pptx
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPTX
Current and future trends in Computer Vision.pptx
PPTX
Safety Seminar civil to be ensured for safe working.
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPTX
UNIT 4 Total Quality Management .pptx
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPTX
CH1 Production IntroductoryConcepts.pptx
PPTX
Sustainable Sites - Green Building Construction
PPTX
Geodesy 1.pptx...............................................
PDF
composite construction of structures.pdf
PDF
Digital Logic Computer Design lecture notes
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PDF
Well-logging-methods_new................
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
Operating System & Kernel Study Guide-1 - converted.pdf
R24 SURVEYING LAB MANUAL for civil enggi
Automation-in-Manufacturing-Chapter-Introduction.pdf
Construction Project Organization Group 2.pptx
Foundation to blockchain - A guide to Blockchain Tech
Model Code of Practice - Construction Work - 21102022 .pdf
Current and future trends in Computer Vision.pptx
Safety Seminar civil to be ensured for safe working.
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
UNIT 4 Total Quality Management .pptx
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
CH1 Production IntroductoryConcepts.pptx
Sustainable Sites - Green Building Construction
Geodesy 1.pptx...............................................
composite construction of structures.pdf
Digital Logic Computer Design lecture notes
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
Well-logging-methods_new................

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; } } }