0% found this document useful (0 votes)
12 views

DS Answer sheet

The document provides an overview of data structures, including their classifications based on arrangement, memory management, and data holding. It discusses various data types, advantages of linked lists over arrays, and operations related to stacks and queues. Additionally, it covers algorithms, asymptotic analysis, and specific examples of data structure implementations.

Uploaded by

pavantomar1858
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

DS Answer sheet

The document provides an overview of data structures, including their classifications based on arrangement, memory management, and data holding. It discusses various data types, advantages of linked lists over arrays, and operations related to stacks and queues. Additionally, it covers algorithms, asymptotic analysis, and specific examples of data structure implementations.

Uploaded by

pavantomar1858
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 55

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

1. Primitive Data Type:


It is the basic data type supported by the computer. It is the most funda-
mental data type usable in the programming language.
E.g.: int, char, string, float, double.
2. Non Primitive Data Type:
It is more sophisticated data structure. These data type is derived from
primitive data structures. The non-primitive data structures emphasizes on structur-
ing of a group of homogeneous and non-homogeneous data items.
Eg: stack, queue, graph, tree, linked list.
3. Abstract Data Type(ADT):
It consists of data items and related functions that can be performed on the
data it does not deal with implementation.
The process of providing only the essentials and hiding the details is known as ab-
straction.
E.g.: When we drive we are aware about the stearing, brakes, and certain other op-
erations that are enough for driving.
Q3. Explain Advantages and Limitations of Array
Q4. Explain Array with the help of example using One dimensional and Two di-
mensional Array.
Q5. What is sparse matrix explain its types
Q6. Define Algorithm with its Properties
Q7. Write a note on Abstract data type

Q8. What is Asymptotic Analysis? Explain with example


(any 2)
Q9. Write a program to insert an element in array.
Q10. Explain Memory Representation of Sparse Matrix
(All Three).
Q11. There is an array M [4:7,-1:3] it requires 2
bytes to stores each element. Calculate the Ad-
dress of [6] [2] when base address is 100.
Unit 2
Q1. What are the applications of linked list?

Q2. Write a note on Header Linked List.


Q3. Explain Memory allocation and Deallocation
function.
Q4. Discuss advantages of linked list over Array.
Answer:
Advantages of Linked List over Arrays are:
1.Dynamic Size: One of the most significant advant-
ages of linked list over arrays is that linked lists
can grow or shrink dynamically during runtime.
This means that the size of a linked list can be ad-
justed to accommodate new elements or remove
existing elements without having to allocate or
deallocate a fixed-size block of memory, as is the
case with arrays.
2.Efficient Insertion and Deletion: Linked lists allow
efficient insertion and deletion of elements at any
position in the list, whereas arrays require shifting
of elements when a new element is added or re-
moved, which can be slow and inefficient for large
arrays.
3.Memory Efficiency: Linked lists use memory more
efficiently than arrays. In an array, all elements
must be stored in contiguous memory locations,
even if some of the elements are not used. In con-
trast, linked lists only allocate memory for the ele-
ments that are used, which can save memory in
cases where the size of the data set is unknown or
varies over time.
4.Easy Implementation of Abstract Data
Types: Linked lists are easy to use and implement
when implementing abstract data types such as
stacks, queues, and trees. These data structures
require frequent insertion and deletion of ele-
ments, which is a task in which linked lists are
well-suited.
5.More Efficient Sorting: In some cases, linked lists
can be more efficient for sorting algorithms than
arrays. This is because linked lists do not require
swapping elements like arrays, which can be time-
consuming for large arrays.
Q5. Explain deletion at intermediation node in
Singly Linked List.
Q6. Explain the steps of Insertion at last in Singly
Linked List.
Q7. Explain Insertion at intermediate node in Doubly
Linked List.
Q8. Explain with the Pseudo Code of Deletion of last
node in Doubly Linked List.

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

| Original Expression | Stack | Output |


|---------------------------|----------------|-------------|
| A*(B+C/D) | | |
|A | |A |
|A |( |A |
| AB |( |A |
| AB+ |( |A |
| AB+ | (+ |A |
| AB+ | (+ | AB |
| AB+/ | (+ | AB |
| AB+/D | (+ | AB |
| AB+/D | (+/ | AB |
| AB+/D/ | (+/ | AB |
| AB+/D/ | | ABCD/+/ |
| AB+/D/ | | ABCD/+/ |
| Original Expression | Stack | Output |
|---------------------------|-----------------|-------------|
| ((A+B)*(C+D))/E | | |
| (A+B)*(C+D))/E |( | |
| AB)*(C+D))/E |( | |
| AB)(C+D))/E |( | |
| AB)(C+D))/E |( | AB |
| AB)*(C+D))/E | (*+ | AB |
| AB)*(C+D))/E | (*+ | AB |
| AB)*(C+D))/E | (*+( | AB |
| AB)*(C+D))/E | (*+( | AB |
| AB)*(C+D))/E | (*+(C | AB |
| AB)*(C+D))/E | (*+(C | AB |
| AB)*(C+D))/E | (*+(C+ | AB |
| AB)*(C+D))/E | (*+(C+ | AB |
| AB)*(C+D))/E | (*+(C+D | AB |
| AB)*(C+D))/E | (*+(C+D | AB |
| AB)*(C+D))/E | (*+(C+D | AB |
| AB)*(C+D))/E | (*+(C+D+ | AB |
| AB)*(C+D))/E | (*+(C+D+ | AB |
| AB)*(C+D))/E | (*+(C+D+ | AB |
| AB)*(C+D))/E | (*+(C+D+ | AB |
| AB)*(C+D))/E | (*+(C+D+ | AB |
| AB)*(C+D))/E | (*+(C+D+ | AB |
| AB)*(C+D))/E | (*+(C+D+ | AB |
| AB)*(C+D))/E | (*+(C+D+ | AB |
| AB)*(C+D))/E | (*+(C+D+ | AB |
| AB)*(C+D))/E | (*+(C+D+ | AB |
| AB)(C+D))/E | (*+(C+D+ | AB |
| AB)(C+D))/E | (*+(C+D+ | AB |
| AB)*(C+D))/E | (*+(C+D+*E | AB |
| AB)*(C+D))/E | (*+(C+D+*E/ | AB |
| AB)*(C+D))/E | | AB+CD+*E/ |
| ((A+B)*(C+D))/E | | AB+CD+*E/ |
Q7.Convert the following Infix Expression into Prefix
Expression:
(a)(A*B)- (C/D) +E
(b)(A+B/C*(D+C)-F
Q8. Write a short note on Queue Operation.
Q9.Write a short note on Priority Queue.
Q10. What are the applications of Queue?
Q11.Explain Dequeue with help of input restricted
Queue.
Q12. Write a short Note on Circular Queue.

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy