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

data structures cie paper solution

all

Uploaded by

ssn.123shreyas
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

data structures cie paper solution

all

Uploaded by

ssn.123shreyas
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Bapuji Educational Association (Regd.

Bapuji Institute of Engineering and Technology


Affiliated to Visvesvaraya Technological University, Belgavi, Accredited by NAAC with 'A' grade,
Recognized by UGC under 2(F) and 12(B)

Department of Computer Science and Engineering

SCHEME OF VALUATION - 2

Course Title DATA STRUCTURES AND APPLICATIONS Course Code [BCS304]

Dr. Naveen Kumar K R & Vishwanath V K & 3rd Sem/CSE


Course Coordinator Semester/Branches
Dr. Abdul Razak M.S Sections: A, B & C

CIE No. Ⅱ Max. Marks 25

Date Feb 5, 2024 Time 03:00 pm - 04: 00 pm


Bapuji Educational Association (Regd.)
Bapuji Institute of Engineering and Technology, Davangere-577004
Department of Computer Science and Engineering

Course Title DATA STRUCTURES AND APPLICATIONS Course Code [BCS304]

Course Dr. Naveen Kumar K R & Vishwanath V K & Dr. Abdul Razak M.S 3rd Sem/CSE
Semester/Branches
Coordinator Sections: A, B & C

CIE No. Ⅱ Max. Marks 25

Date Mar 5, 2024 Time 03:00 pm - 04: 00 pm

Course Outcomes: After studying this course, students will be able to:
1. Explain different data structures and their applications.
2. Apply Arrays, Stacks and Queue data structures to solve the given problems.
3. Use the concept of linked list in problem solving.
4. Develop solutions using trees and graphs to model the real-world problem.
5. Explain the advanced Data Structures concepts such as Hashing techniques and Optimal Binary Search Trees.

Note : Answer any three full questions.


Q. NO. QUESTIONS MARKS RBL COs

MODULE 3
Write the C functions for Inorder, Preorder, Postorder traversals of Binary tree and
apply the same for the tree given in Figure 1a.

1 a 5 L3 3

Figure 1a:
OR
Provide two rules for constructing threaded binary trees, followed by the C declaration
for a threaded binary tree. Illustrate these concepts with an example using nodes A,
2 a 5 L3 3
B, C, D, E, F, G, H, and I. Additionally, define a C function for inorder traversal of a
threaded binary tree.
MODULE 4
Define Binary Search Tree with an example. Write a C function to insert a node into a
a 5 L2 4
Binary Search Tree.
3
Give the adjacency matrix and adjacency list representation for the graph shown in
b 5 L2 4
following figure 3b.
Figure 3b:
OR
A binary tree has 9 nodes. The inorder and preorder traversals yield the following
sequences of nodes:
a Inorder: E A C K F H D B G 5 L3 4
4 Preorder: F A E K C D H G B
Draw the binary tree.
b What are the methods used for traversing a graph? Explain any one with an example. 5 L2 4
MODULE 5

a Write a short note on Hashing. Explain any 3 popular HASH functions. 5 L2 5


5
b Explain in detail about Static and Dynamic hashing. 5 L2 5

OR

a Define priority queues. Explain in detail two varieties of priority queues. 5 L2 5


6
b Develop a C function for finding an Optimal Binary Search tree. 5 L2 5

RBT (Revised Bloom’s Taxonomy) Levels : Cognitive Domain


L1 : Remembering L2 : Understanding L3 : Applying
L4 : Analyzing L5 : Evaluating L6 : Creating
1a // C function to perform inorder traversal of a binary tree
void inorder(struct node* root)
{
if (root == NULL)
return;

inorder(root->left);
printf("%d ", root->data);
inorder(root->right);
}

// C function to perform preorder traversal of a binary tree


void preorder(struct node* root)
{
if (root == NULL)
return;

printf("%d ", root->data);


preorder(root->left);
preorder(root->right);
}

// C function to perform postorder traversal of a binary tree


void postorder(struct node* root)
{
if (root == NULL)
return;

postorder(root->left);
postorder(root->right);
printf("%d ", root->data);
}
For correctly implementing the inorder traversal function. 1+

For correctly implementing the preorder traversal function. 1+

For correctly implementing the postorder traversal function. 1+

For presenting the results of the traversals in the correct order. 2

2a Rules for constructing threaded binary trees:

1. Each node has a left child pointer and a right child pointer.
2. If a node has no left child, then its left child pointer points to its inorder
predecessor.
3. If a node has no right child, then its right child pointer points to its
inorder successor.

C declaration for a threaded binary tree:

struct threaded_node {
int data;
struct threaded_node *left;
struct threaded_node *right;
int left_thread;
int right_thread;
};

Example of a threaded binary tree with nodes A, B, C, D, E, F, G, H, and I:


C function for inorder traversal of a threaded binary tree:

void inorder_threaded(struct threaded_node *root) {


struct threaded_node *current = root;

while (current != NULL) {


// If the left child is a thread, then the current node
is the leftmost node.
if (current->left_thread == 1) {
printf("%d ", current->data);

// If the right child is also a thread, then the


current node is the rightmost node.
if (current->right_thread == 1) {
break;
} else {
// Otherwise, move to the right child.
current = current->right;
}
} else {
// Otherwise, move to the left child.
current = current->left;
}
}
}

For correctly stating the two rules for constructing threaded binary trees. 1+

For correctly providing the C declaration for a threaded binary tree. 1+

For correctly illustrating the concepts with an example using nodes A, B, C, 1+


D, E, F, G, H, and I.

For correctly defining the C function for inorder traversal of a threaded 2


binary tree.

3a Definition of a Binary Search Tree (BST):

A binary search tree (BST) is a binary tree in which each node has at most
two child nodes, one to the left and one to the right. Specifically, the data in
each node is greater than the data in all of its left child nodes and less than
the data in all of its right child nodes.

Example of a BST:
C function to insert a node into a BST:

struct node* insert(struct node* root, int data) {


if (root == NULL) {
// If the tree is empty, create a new node and return it.
return create_node(data);
} else if (data < root->data) {
// If the data is less than the data in the current node,
insert it in the left subtree.
root->left = insert(root->left, data);
} else if (data > root->data) {
// If the data is greater than the data in the current
node, insert it in the right subtree.
root->right = insert(root->right, data);
}

return root;
}

For correctly defining a binary search tree (BST). 1+


For providing an example of a BST. 1+
For correctly writing the C function to insert a node into a BST. 3

3b Adjacency Matrix:

0 1 2 3 4 5 6 7

0 0 1 1 0 0 0 0 0

1 1 0 0 1 1 0 0 0

2 1 0 0 0 0 1 1 0

3 0 1 0 0 0 0 0 1

4 0 1 0 0 0 0 0 1

5 0 0 1 0 0 0 0 1
6 0 0 1 0 0 0 0 1

7 0 0 0 1 1 1 1 0

Adjacency List:

For correctly constructing the adjacency matrix. 2.5 +

For correctly constructing the adjacency list. 2.5

4a

For correctly drawing the binary tree. 1+


For correctly labeling the root node. 1+
For correctly labeling the left and right child nodes of each node. 1+
For presenting the tree in a clear and well-organized manner. 1+
For correctly connecting the nodes with edges. 1
4b Methods used for traversing a graph:

Depth-first search (DFS)

Breadth-first search (BFS)

Example:

For correctly stating the two methods used for traversing a graph. 1+
For correctly explaining depth-first search (DFS). 1+
For providing an example of DFS.
1+
For correctly describing the steps involved in DFS.
2

5a Hashing

Hashing is a technique used for storing and retrieving data efficiently. It


involves using a hash function to map data of arbitrary size to a fixed-size
value, called a hash value or hash code.

Popular Hash Functions

Clearly defining and explaining the concept of hashing, including its key 2+
characteristics and advantages.

Providing a detailed explanation of the three popular hash functions 3


(Division, Mid-Square and Folding), including their key features, such as
hash value size, use cases, and any known weaknesses or limitations.

5b Clearly defining and explaining the concept of static hashing, including its 2.5 +
key characteristics, advantages, and limitations.

Providing a detailed explanation of dynamic hashing, including its different 2.5


techniques (linear hashing, and quadratic hashing), their working
principles, and the advantages and disadvantages of dynamic hashing
compared to static hashing.

6a Priority Queues

A priority queue is a data structure that maintains a collection of elements,


each with an associated priority.

Varieties of Priority Queues

Max Priority Queue


Min Priority Queue
1 mark: Clearly defining and explaining the concept of a priority queue, 2+
including its key characteristics and operations.

2 marks: Providing a detailed explanation of the two varieties of priority 3


queues (max priority queue and min priority queue), including their
implementation using a binary heap, the enqueue and dequeue operations,
and the key differences between the two varieties.

6b 5

Course Coordinator Coordinator Program Coordinator


DQAC (HOD, CSE)

You might also like