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

paper -ds

This document is an examination paper for a Data Structures course, covering various topics such as sorting algorithms, data structures definitions, binary trees, linked lists, and graph types. It includes multiple-choice questions, definitions, and coding tasks in C related to data structures. The paper emphasizes understanding and applying concepts in data structures through practical examples and coding exercises.

Uploaded by

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

paper -ds

This document is an examination paper for a Data Structures course, covering various topics such as sorting algorithms, data structures definitions, binary trees, linked lists, and graph types. It includes multiple-choice questions, definitions, and coding tasks in C related to data structures. The paper emphasizes understanding and applying concepts in data structures through practical examples and coding exercises.

Uploaded by

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

[6058]-301

S.Y. B.C.A. (Science)


BCA - 231 : DATA STRUCTURES
(2019 Pattern) (Semester - III)
Time : 3 Hours] [Max. Marks : 70
Instructions to the candidates :
1) All questions are compulsory.
2) Figures to right indicate full marks.
3) Draw neat sketches whenever necessary to illustrate answer.
4) Each question carry equal marks.
—------------------------------------------------------------------------------------------------------------------------
Q1) A) Choose the correct option. [5 × 1 = 5]
a) _______ sorting algorithm can be used to sort a random linked list
with minimum time complexity.
i) Insertion sort ii) Quick sort
iii) Heap sort iv) Merge sort

🌀
a) iv) Merge sort​
Best suited for linked lists due to non-contiguous memory and stable O(n log n) time.

b) _______ many queues are required to implement a stack?


i) 3 ii) 2
iii) 1 iv) 4

🔁
b) ii) 2​
A stack can be implemented using 2 queues.

c) A data structure in which elements can be inserted or deleted at /


from both the ends but not in the middle is ________.
i) Queue ii) Circular Queue
iii) Priority Queue iv) Dequeue

c) iv) Dequeue​
↔️ Double-ended queue allows insertion/deletion from both ends.

d) Find no. of binary tree with 3 nodes which when traversed in post
order gives the sequence A, B, C is _______.
i) 3 ii) 9
iii) 7 iv) 5

🌳
d) i) 3​
3 distinct binary trees give postorder A, B, C.

e) A vertex with degree one in a graph is called ________.


i) a leaf ii) pendant vertex
iii) adjacency list iv) node
📌
e) ii) Pendant vertex​
A vertex with degree 1 is called a pendant vertex.

B) Answer the following : [5 × 1 = 5]

a) Define Non-linear data structure.

b) List out 2 applications of linked list.

c) What is Pivot?

d) List out operations on Binary tree.

e) What is critical path?

B) Answer the following

a) Non-linear data structure:​


A data structure where elements are not stored sequentially. Examples: Trees, Graphs.

b) Applications of linked list:

1.​ Implementation of stacks/queues​

2.​ Dynamic memory allocation​

c) Pivot:​
An element chosen during Quick Sort to partition the array.

d) Operations on Binary Tree:

●​ Insertion​

●​ Deletion​

●​ Traversal (Inorder, Preorder, Postorder)​

●​ Search​

📈
e) Critical path:​
The longest path in a project network diagram determining the shortest project duration.

—------------------------------------------------------------------------------------------------------------------------
Q2) Answer the following (Any Five) : [5 × 3 = 15]

b) Define Binary tree and explain its advantages and disadvantages.

c) What is Recursion? Give one example.

d) Difference between singly linked list and doubly linked list.

e) Write a note on Multidimensional array.

f) What is Sparse Matrix? How it is represented using arrays?

b) Define Binary Tree and Explain Its Advantages and Disadvantages 🌳


Definition:​
A Binary Tree is a hierarchical data structure where each node has at most two children,
referred to as the left child and the right child.

Advantages:

✅ Efficient Searching and Insertion (especially in Binary Search Trees)​


✅ Hierarchical Representation of data​
✅ Supports various traversal methods (Inorder, Preorder, Postorder)​
✅ Used in expression parsing, heaps, and Huffman encoding
Disadvantages:

❌ Can become unbalanced, reducing efficiency​


❌ Complex implementation compared to linear structures​
❌ Requires extra memory for pointers

c) What is Recursion? Give One Example 🔁


Definition:​
Recursion is a process where a function calls itself to solve a smaller instance of the same
problem.
Example: Factorial

int factorial(int n) {

if (n == 0) return 1;

else return n * factorial(n - 1);

Calling factorial(5) will compute:​


5 * 4 * 3 * 2 * 1 = 120

d) Difference Between Singly Linked List and Doubly Linked List 🔗

e) Write a Note on Multidimensional Array 📊


A Multidimensional Array is an array of arrays — where each element of a primary array is
another array.
2D Array Example:

int matrix[2][3] = {

{1, 2, 3},

{4, 5, 6}

};

●​ matrix[0][0] = 1, matrix[1][2] = 6​

●​ Represents a table (2 rows, 3 columns)​

Uses:

●​ Matrix operations​

●​ Game grids (e.g., tic-tac-toe)​

●​ Storing tabular data​

f) What is Sparse Matrix? How It Is Represented Using Arrays? 🧮


Definition:

A Sparse Matrix is a matrix in which most of the elements are zero. Storing all zero values
wastes memory.

Q3) Answer the following (Any Five) : [5 × 4 = 20]

a) Sort the following list using merge sort 2, 6, 8, 2, 3, 9, 1, 4, 9.

b) Write 'C' function for searching element in singly linked list.

c) What is Searching? Explain two techniques of it?

d) Write a 'C' function to insert node into Binary search tree.


e) What is Graph? Explain its types.

f) Explain representation of Queue with example.

g) Convert following expression infix to postfix form (Step - by - step)

P/Q – R * S + T.

a) Sort the following list using Merge Sort:

List: 2, 6, 8, 2, 3, 9, 1, 4, 9

Step-by-step Merge Sort:

1.​ Divide:​

[2, 6, 8, 2, 3, 9, 1, 4, 9]

-> [2, 6, 8, 2] [3, 9, 1, 4, 9]

-> [2, 6] [8, 2] [3, 9] [1, 4, 9]

-> [2] [6] [8] [2] [3] [9] [1] [4] [9]

2.​ Merge:​

[2,6] [2,8] [3,9] [1,4,9]

-> [2,2,6,8] [1,3,4,9,9]

-> [1,2,2,3,4,6,8,9,9]

✅ Sorted List: 1, 2, 2, 3, 4, 6, 8, 9, 9
b) C Function to Search Element in Singly Linked List

struct Node {

int data;

struct Node* next;

};

int search(struct Node* head, int key) {

while (head != NULL) {

if (head->data == key)

return 1; // Found

head = head->next;

return 0; // Not Found

c) What is Searching? Explain Two Techniques of It 🔍


Definition:​
Searching is the process of finding the required element in a collection of data.

1. Linear Search:

Definition: Linear Search is a straightforward search algorithm that checks each element in
a list sequentially until the desired element is found or the list ends.

Linear Search is simple and works on any list but is inefficient for large datasets.
Algorithm Steps:

1. Start from the first element of the array.

2. Compare each element with the target value.

3. If the target value is found, return its index.

4. If the end of the list is reached without finding the target, return a signal that indicates the
element is not present.

2. Binary Search:

Definition: Binary Search is an efficient searching algorithm that works on sorted arrays. It
divides the search interval in half repeatedly, checking the middle element each time.

Binary Search is much faster but requires the data to be sorted. When applicable, it is the
preferred method for searching due to its logarithmic time complexity.

Algorithm Steps:

1. Start with two pointers, low and high, representing the bounds of the search space.

2. Calculate the middle index: mid = (low + high) / 2.

3. Compare the middle element with the target:

o If the middle element equals the target, return the middle index.

o If the middle element is less than the target, narrow the search to the upper half by setting
low = mid + 1.

o If the middle element is greater than the target, narrow the search to the lower half by
setting high = mid - 1.

4. Repeat until the element is found or the search space is empty.


d) C Function to Insert Node into Binary Search Tree

struct Node {

int data;

struct Node *left, *right;

};

struct Node* insert(struct Node* root, int key) {

if (root == NULL) {

struct Node* newNode = (struct Node*)malloc(sizeof(struct


Node));

newNode->data = key;

newNode->left = newNode->right = NULL;

return newNode;

if (key < root->data)

root->left = insert(root->left, key);

else

root->right = insert(root->right, key);

return root;

}
e) What is Graph? Explain Its Types 📊
Definition:​
A graph is a non-linear data structure consisting of nodes (vertices) and edges that
connect pairs of nodes.

Types of Graphs:

1.​ Directed Graph (Digraph):​


Arrows show direction between nodes.​

2.​ Undirected Graph:​


Edges have no direction.​

3.​ Weighted Graph:​


Each edge has a weight or cost.​

4.​ Unweighted Graph:​


Edges have no weight.​

5.​ Cyclic Graph:​


Contains cycles (loops)​

6.​ Acyclic Graph:​


No cycles present (e.g., trees)​

7.​ Connected Graph:​


Path exists between any two nodes.​

8.​ Disconnected Graph:​


Some nodes are isolated.​

f) Queue Representation with Example 🧾


Queue: A linear data structure that works on FIFO (First-In-First-Out).

Array Representation:

#define SIZE 5
int queue[SIZE], front = -1, rear = -1;

void enqueue(int val) {

if (rear == SIZE - 1)

printf("Queue Full\n");

else {

if (front == -1) front = 0;

queue[++rear] = val;

void dequeue() {

if (front == -1 || front > rear)

printf("Queue Empty\n");

else

printf("Deleted: %d\n", queue[front++]);

g) Infix to Postfix Conversion (Step-by-step) 🧠


Expression: P / Q – R * S + T
—------------------------------------------------------------------------------------------------------------------------

Q4) Answer the following (Any Five) : [5 × 5 = 25]

a) Construct a BST for following data.

11, 7, 15, 25, 18, 5, 12, 20

b) Define stack with its primitive operations.

c) Write 'C' function to delete node from beginning and end in Doubly linked

list.

e) Write 'C' function to insert and delete element in Circular Queue.


f) What is tree? Explain methods of Tree traversal.

g) Write a short note on Asymptotic notations.

a) Construct a BST for the following data:

Data: 11, 7, 15, 25, 18, 5, 12, 20

Step-by-step BST Construction:

1.​ Root: 11​

2.​ 7 < 11 → left of 11​

3.​ 15 > 11 → right of 11​

4.​ 25 > 15 → right of 15​

5.​ 18 < 25 → left of 25​

6.​ 5 < 7 → left of 7​

7.​ 12 < 15 → left of 15​

8.​ 20 > 18 → right of 18​

markdown

CopyEdit

11

/ \

7 15

/ / \

5 12 25

18
\

20

b) Define Stack with Its Primitive Operations 📚


Stack:​
A stack is a linear data structure that follows the LIFO (Last In, First Out) principle. This
means the last element added to the stack is the first one to be removed.

Primitive Operations:

●​ Push:​
Inserts an element onto the top of the stack.​
➤ Example: push(10)​

●​ Pop:​
Removes the element from the top of the stack.​
➤ Example: pop() removes the most recently added item.​

●​ Peek / Top:​
Returns the top element of the stack without removing it.​
➤ Example: peek() returns the current top value.​

●​ isEmpty():​
Checks if the stack is empty.​
➤ Returns true if no elements are present.​

●​ isFull():​
Checks if the stack is full (in case of array implementation).​
➤ Useful for avoiding overflow errors.

// Function to check if stack is empty

int isEmpty() {

return top == -1;

}
// Function to check if stack is full

int isFull() {

return top == SIZE - 1;

// Push operation

void push(int value) {

if (isFull()) {

printf("Stack Overflow! Cannot push %d\n", value);

} else {

top++;

stack[top] = value;

printf("%d pushed to stack.\n", value);

// Pop operation

void pop() {

if (isEmpty()) {

printf("Stack Underflow! Cannot pop.\n");

} else {

printf("%d popped from stack.\n", stack[top]);


top--;

// Peek operation

void peek() {

if (isEmpty()) {

printf("Stack is empty.\n");

} else {

printf("Top element is: %d\n", stack[top]);

c) C Function to Delete Node from Beginning and End in Doubly Linked


List

struct Node {

int data;

struct Node *prev, *next;

};

void deleteFromBeginning(struct Node** head) {

if (*head == NULL) return;

struct Node* temp = *head;


*head = (*head)->next;

if (*head != NULL) (*head)->prev = NULL;

free(temp);

void deleteFromEnd(struct Node** head) {

if (*head == NULL) return;

struct Node* temp = *head;

while (temp->next != NULL)

temp = temp->next;

if (temp->prev != NULL)

temp->prev->next = NULL;

else

*head = NULL;

free(temp);

e) C Function to Insert and Delete Element in Circular Queue

#define SIZE 5

int cq[SIZE], front = -1, rear = -1;

void insert(int val) {


if ((rear + 1) % SIZE == front)

printf("Queue Overflow\n");

else {

if (front == -1) front = 0;

rear = (rear + 1) % SIZE;

cq[rear] = val;

void delete() {

if (front == -1)

printf("Queue Underflow\n");

else {

printf("Deleted: %d\n", cq[front]);

if (front == rear)

front = rear = -1;

else

front = (front + 1) % SIZE;

}
f) What is Tree? Explain Methods of Tree Traversal 🌳
✅ Definition:
A tree is a non-linear hierarchical data structure consisting of nodes connected by
edges.

●​ It begins with a root node,​

●​ Every node can have zero or more child nodes,​

●​ There are no cycles in a tree.​

🌿 Tree Traversal Methods:


Tree traversal means visiting each node of the tree in a specific order.

1. Inorder Traversal (Left, Root, Right):

●​ Visit left subtree → Root → Right subtree​

●​ Example Use: Retrieve sorted data from a Binary Search Tree (BST)​

2. Preorder Traversal (Root, Left, Right):

●​ Visit Root → Left subtree → Right subtree​

●​ Example Use: Used to copy or clone the tree​

3. Postorder Traversal (Left, Right, Root):

●​ Visit Left subtree → Right subtree → Root​

●​ Example Use: Used to delete or free nodes in a tree​


4. Level Order Traversal (Breadth-First):

●​ Traverse nodes level-by-level from top to bottom​

●​ Implemented using a queue​

●​ Example Use: Printing a tree level-wise or finding the shortest path in a tree

g) Write a Short Note on Asymptotic Notations 📈


Asymptotic Notation describes the growth of algorithms in terms of input size (n). It
helps in comparing algorithm efficiency.
●​

You might also like