DS Answer sheet
DS Answer sheet
Unit 1
Q1. What is Data Structure? Explain its Classifications.
Answer: Data Structure is the way of organizing a data in a logical manner so as it can be
used effectively. It is a technique or method of study how the data are inter-related to each
other logically or mathematically.
Data structure is classified into 3 main classifications:
1. On the basis of Arrangement
i) Linear Data Structure
ii) Non Linear Data Structure
2. On the basis of Memory Management
i) Dynamic Data Structure
ii) Static Data Structure
3. On the basis of Data Holding
i) Homogeneous Data Structure
ii) Non- Homogeneous Data Structure
Explanation
1. On the basis of Arrangement:
i) Linear Data structure:
A linear data structure is a structure that helps to store data in a lin-
ear pattern or sequence.
E.g.: Array, Stack, Linked List, Queue.
ii) Non- Linear Data Structure:
A non-linear data structure is a structure that stores data in a non-
linear fashion.
E.g.: Trees, Graph
2. On the basis of Memory Management:
i) Dynamic Data Structure:
The size of a dynamic data structure is not fixed and can be modified
while the operations are performed on it.
E.g.: Linked List
ii) Static Data Structure:
The size of static data structure is fixed and cannot be modified while
the operations are performed on it.
E.g.: Array
3. On the basis of Data Holding:
i) Homogeneous Data Structure
In this type of data structure only similar type of data can be stored
E.g.: Array
ii) Non-Homogeneous Data Structure
This type of data structure can store various type of data.
E.g.: Stack, Queue, Tree, and Graph
Q2. What are the different types of Data types in Data structure?
Answer: There are three types of Data Types in Data Structure:
Primitive Data
Data Type
Type
Non Primitive Data
Type
Abstract Data
Type
Answer:
#include<stdio.h>
#include<malloc.h>
struct node*delete(struct node*start)
{
int val;
struct node*pre=NULL,*temp=NULL;
printf (“Enter value to be deleted:”);
scanf(“%d”, &val)
temp=start;
while(temp-> data != val && temp != NULL)
{
pre=temp
temp=temp->next;
}
if(temp==start)
{
start= start->next;
free(temp);
printf(“Successfully Deleted.\n”);
}
elseif(temp->next==NULL)
{
pre->next=NULL;
free(temp);
printf(“Successfully Deleted.\n”);
}
elseif(temp==start)
{
printf(“Value not found.”);
}
else
{
temp->next->prev=temp->prev;
pre->next=temp->next
free(temp);
printf(“Successfully Deleted.\n”)
}
return start;
}
Q9. Write a procedure to add a node at last in Circular
Linked List.
Answer:
The procedure to add a node at last in circular
linked list is as follows:
Step 1:
Create a new node:
struct node*new node
new node =(struct node*)malloc(sizeof
(struct node))
new node->data=val
Step 2:
Check if the linked list is empty or not
if(start==last==null)
{
printf(“The Circular Linked List is Empty”)
}
Step 3:
Traverse the linked list
start = current
while(current->next!=start)
{
current= current->next
}
Step 4:
Attach the new node at the last of the linked list
current->next = new node
Step 5:
New node->next= start
Q10. Write a note on deletion in Circular Linked list.
Q11. Explain the procedure of Copying linked list into
the other linked list.
UNIT 3
Q1.What is Stack? Explain all its Operations.
Q2.How will you represent insertion in stack using
Array.
Answer:
Stack 5;
int val;
if (top==max-1)
printf(“Stack is full”);
else
{
printf(“Enter the value to be pushed”);
scanf(“%d”,&val);
stack[++top]=val;
printf(“Successfully Pushed”);
}
Q3. How will you represent deletion in stack using ar-
ray?
Q4.Write a short note on Recursion.
Q5.How to check whether the Parenthesis are correctly
matched or not. (with Example)
Q6.Convert the following Infix Expression into Postfix
Expression:
(a)A*(B+C/D)
(b)((A+B)*(C+D))/E
Answer:
Circular Queue is a queue in which last element
refers to the first.
A circular array is just an array represented in a form of
circular.
A circular queue allows us to insert a new element
even after rear moves to the last index of the array.
------------------------------------
END---------------------------------