0% found this document useful (0 votes)
9 views9 pages

Dsa Slved Pprs

The document contains a series of questions and answers related to data structures, specifically focusing on binary trees, graphs, hashing, and tree traversal methods. Key concepts such as min heaps, splay trees, minimum spanning trees, and the differences between B and B+ trees are discussed. Additionally, it includes programming examples for counting leaf nodes, inserting into binary search trees, and implementing hash tables.

Uploaded by

geeshshaikh007
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)
9 views9 pages

Dsa Slved Pprs

The document contains a series of questions and answers related to data structures, specifically focusing on binary trees, graphs, hashing, and tree traversal methods. Key concepts such as min heaps, splay trees, minimum spanning trees, and the differences between B and B+ trees are discussed. Additionally, it includes programming examples for counting leaf nodes, inserting into binary search trees, and implementing hash tables.

Uploaded by

geeshshaikh007
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/ 9

P-6383

✅ Q1) Attempt any eight of the following. [8×1=8]

a) "Binary tree contains every node with minimum two child nodes".

Answer: False. In binary trees, each node can have 0, 1, or 2 children.

b) Define: left skewed binary tree.

Answer: A binary tree where each node has only left child and no right child.

c) What is degree of a graph?

Answer: The number of edges connected to a vertex is the degree of a graph.

d) Name data structure used to implement DFS of a graph.

Answer: Stack (explicitly or through recursion) is used in DFS.

e) What is complete binary tree?

Answer: A tree in which all levels are completely filled except possibly the last, which is filled left to
right

f) Define: balance factor.

Answer: Balance Factor = Height of left subtree – Height of right subtree.

g) Write properties of a good hash function.

Answer: Should distribute keys uniformly, avoid clustering, and be fast to compute.

h) Write any two applications of graph.

Answer: 1. Social networks

2. Google Maps for route finding


i) "Complete graph contains n(n–1)/2 number of edges".

Answer: True. That's the formula for number of edges in a complete undirected graph.

j) What is synonym of hashing?

Answer: Hashing is also called key-to-address transformation.

✅ Q2) Attempt any four of the following. [4×2=8]

a) What is splay tree?

Answer: A splay tree is a self-adjusting binary search tree.

In splay tree, recently accessed node is moved to the root using rotations.

This reduces the access time for future operations.

b)Explain Mid-Square function in hashing with suitable example.

Answer: The Mid-Square method is a hashing technique used to determine the address (or
index) of a key in a hash table. It works by:

1. Squaring the key, and


2. Extracting a portion (middle digits) of the result to use as the hash address.

Example:

Step 1: Square the key

56=3136

Step 2: Extract the middle digits

• Since we want a 2-digit address (because table size is 100), we take the middle 2 digits of
3136.
• 3136 → Middle two digits = 13

Step 3: Hash value = 13

So, key 56 will be placed at index 13 in the hash table.


c) What is inverse adjacency list?

Answer: An Inverse Adjacency List is a variation of the adjacency list used in graph data structures —
specifically useful for directed graphs.

In a normal adjacency list, we store:

For each vertex, the list of vertices it points to outgoing edges.

But in an inverse adjacency list, we store:

For each vertex, the list of vertices points to incoming edges.

✅ Q3) Attempt any two of the following. [2×4=8]

b) Recursive function to count leaf nodes of BST:

int countLeaf(struct Node* root) {

if (root == NULL) return 0;

if (root->left == NULL && root->right == NULL)

return 1;

return countLeaf(root->left) + countLeaf(root->right);

✅ Q4) Attempt any two of the following. [2×4=8]

a) C function to insert node in BST:

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

if (root == NULL) return createNode(key);

if (key < root->data)

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


else

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

return root;

✅ Q5) Attempt any one of the following. [1×3=3]

a) Differentiate between B and B+ Tree.

Answer:

• B Tree stores data in all nodes.


B+ Tree stores data in leaf nodes only.

• B Tree is a bit slower in searching.


B+ Tree is faster for searching.

• In B Tree, leaf nodes are not linked.


In B+ Tree, leaf nodes are linked like a chain.

• B Tree is good for small data.


B+ Tree is good for large data.

• B Tree is harder for range queries.


B+ Tree is better for range queries.

• B Tree is used in some databases.


B+ Tree is used in most file systems.

__ Difference between linear and quadratic probing:

• Linear probing checks the next slot (i+1, i+2, ...).


Quadratic probing checks slots using squares (i+1², i+2², ...).

• Linear probing is simpler, but can cause clustering.


Quadratic probing reduces clustering.

• Linear probing is faster to implement.


Quadratic probing is a bit more complex.
• In linear probing, empty slot is found in a straight line.
In quadratic, it jumps in a pattern.

• Linear probing may search more slots.


Quadratic may skip some slots

Q2.e,d, 3.a, 3.c, 4.b,c, 5.b


P-1294

Q1) Attempt any eight of the following: [8 × 1 = 8]

a) Define min heap:


A min heap is a complete binary tree where the value at the root is minimum among all
nodes, and each parent node is less than or equal to its children.

b) What is level order traversal?


Level order traversal is a method of traversing a tree level by level, from left to right, using a
queue.

c) What is descendant in tree?


In a tree data structure, a descendant is any node that comes below a given node in the tree.

d) In B+ tree data can only be stored in leaf node. State true or false.
True.

e) List AVL tree Rotations.

• Left Rotation
• Right Rotation
• Left-Right Rotation
• Right-Left Rotation

f) List any two minimum spanning tree algorithms.

• Kruskal's Algorithm
• Prim's Algorithm

g) "DFS uses queue implementation". State true or false.


False. (DFS uses stack or recursion)

h) What is weighted graph?


A weighted graph is a graph in which each edge has an associated weight or cost.

i) What is load factor?


Load factor is the ratio of number of elements to the size of hash table (n/table size).

j) What is hashing?
Hashing is a process of converting a given key into an index in an array using hash functions.
Q2) Attempt any four of the following: [4 × 2 = 8]

a) Write a note on minimum spanning tree:


Out of all possible spanning trees, the Minimum Spanning Tree (MST) has the smallest total
weight. A Minimum Spanning Tree (MST) is a special way of connecting all points (called vertices)
in a weighted graph using the smallest total cost. Algorithms like Kruskal’s Algorithm and
Prim’s Algorithm are used to find MST.

b) Write a note on splay tree:


A splay tree is a self-adjusting binary search tree where recently accessed elements are
moved to the root using splaying. This helps improve access time for future operations.

c) Give any two differences between DFS & BFS:

• BFS explores level by level.


DFS goes deep into one path first.

• BFS uses a queue.


DFS uses a stack (or recursion).

• BFS is better for finding shortest path.


DFS is better for exploring all paths.

• BFS needs more memory.


DFS uses less memory.

• BFS is like moving in circles outward.


DFS is like going in a straight line deep

d) Explain any two properties of good hash function:

1. Uniform Distribution: Spreads keys evenly across the hash table.


2. Deterministic: Same input should always result in the same output.

e) Write a note on B tree

A self-balancing tree used in databases and file systems. Each node can have more than two
children. Keeps data sorted and allows logarithmic search, insertion, and deletion. In B Tree, data
is stored at both internal and leaf nodes
Q3) Attempt any two of the following: [2 × 4 = 8]

a) C function to calculate i) leaf nodes ii) non-leaf nodes:

int countLeaf(struct Node* root) {


if (!root) return 0;
if (!root->left && !root->right) return 1;
return countLeaf(root->left) + countLeaf(root->right);
}

int countNonLeaf(struct Node* root) {


if (!root || (!root->left && !root->right)) return 0;
return 1 + countNonLeaf(root->left) + countNonLeaf(root->right);
}

b) Program for indegree and outdegree:

#include <stdio.h>
#define V 4

int main() {
int graph[V][V] = {
{1, 1, 1, 0},
{0, 1, 1, 0},
{1, 0, 1, 1},
{0, 0, 0, 1}
};
int i, j, in, out;

for (i = 0; i < V; i++) {


in = out = 0;
for (j = 0; j < V; j++) {
out += graph[i][j];
in += graph[j][i];
}
printf("Vertex %d: In-degree = %d, Out-degree = %d\n", i, in, out);
}
return 0;
}

c) Program to insert element in hash table (linear probing):

#include <stdio.h>
#define SIZE 10

int hashTable[SIZE];

void insert(int key) {


int index = key % SIZE;
while (hashTable[index] != 0)
index = (index + 1) % SIZE;
hashTable[index] = key;
}

int main() {
insert(23);
insert(43);
insert(13);
for (int i = 0; i < SIZE; i++)
printf("%d ", hashTable[i]);
return 0;
}

Q5) Attempt any one of the following: [1 × 3 = 3]

a) Define the following terms:

Terminal Node:
A terminal node, also called a leaf node, is a node that has no children. It is the end point of a
branch in a tree.

Depth of a Node:
The depth of a node is the number of edges from the root node to that particular node. The
root has a depth of 0.

Root Node:
The root node is the top-most node of a tree. It is the starting point from which all other nodes
branch out.

Q4, 5.b

You might also like