Explain Abstract data types with its characteristics.
Answer
Whenever a programmer has been told to write any program firs...
For the following Graph, Write its equivalent Adjacency list and Adjacency Matrix
Answer
Adjacency List
NODES ADJACENCY LI...
Explain quick sort and tree sort.
Answer
Quick Sort:
It is also known as partition sort and it is the most widely used int...
Write a C-program to implement stack using array data structure and perform the following stack
operations (a) POP (b) PUS...
int i;
printf("nThe Stack elements are:");
for(i=0;i<=top;i++)
{
printf("%d",stack[i]);
}
}
int main()
{
char ch , a='y';
...
Write a C program to demonstrate linked list implementation of stack
Answer
#include <stdio.h>
void push();
void pop();
vo...
Upcoming SlideShare
Loading in …5
×

Bc0038– data structure using c

345 views

Published on

Published in: Engineering, Technology, Business
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
345
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
3
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Bc0038– data structure using c

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

×