0% found this document useful (0 votes)
11 views10 pages

DS IA3 Scheme

The document outlines the CIE Test III for the Data Structures and Applications course at RNS Institute of Technology, detailing various programming tasks and theoretical questions related to data structures. It includes C functions for linked lists, tree data structures, binary trees, and hashing methods, along with definitions and diagrams for key concepts. The test aims to assess students' understanding of data structures through practical coding and theoretical explanations.
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)
11 views10 pages

DS IA3 Scheme

The document outlines the CIE Test III for the Data Structures and Applications course at RNS Institute of Technology, detailing various programming tasks and theoretical questions related to data structures. It includes C functions for linked lists, tree data structures, binary trees, and hashing methods, along with definitions and diagrams for key concepts. The test aims to assess students' understanding of data structures through practical coding and theoretical explanations.
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/ 10

RN SHETTY TRUST®

RNS INSTITUTE OF TECHNOLOGY


Autonomous Institution Affiliated to VTU, Recognized by GOK, Approved by AICTE
(NAAC ‘A+ Grade’ Accredited, NBA Accredited (UG - CSE, ECE, ISE, EIE and EEE)
Channasandra, Dr. Vishnuvardhan Road, Bengaluru - 560 098
Ph: (080)28611880,28611881 URL: www.rnsit.ac.in

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

CIE – TEST III


Course: Data Structures and
Course Code: BCS304 Semester : 3rd
Applications
Max. Marks : 50 Date: 17/12/2024 Faculty Name: Dr. Hemanth S

Scheme and Solution


Q. No Description Marks

1 Write C functions for DLL to i) insert front ii) insert rear iii) delete front iv) delete end v) search a
value
void insert_front()
{
node *n;
n=getnodeDLL();
if(start == NULL)
{
start = n;
return;
}
n->rptr=start;
start->lptr=n;
start=n;
}
5X2=10
void insert_rear()
{
node *n1,*temp = start;
n1=getnodeDLL();
if(start==NULL)
{
start=n1;
return;
}
while(temp->rptr!=NULL)
temp=temp->rptr;
temp->rptr=n1;
n1->lptr=temp;
}

void delete_front()
{
node *temp = start;
if(start==NULL)
{
printf(“\n List is empty”);
return;
}
Course Code: BCS304 Scheme and Solution

printf(“\nt%d\t is deleted ”,temp->info);


start=temp->rptr;
start->lptr=NULL;
free(temp);
}

void delete_end()
{
node *temp =start;
if(start==NULL)
{
printf(“\n Empty list”);
return;
}
if(start->next==NULL)
{
printf(“\nt%d\t is deleted”,start->info);
free(start);
start=NULL; return;
}
while(temp->rptr!=NULL)
temp=temp->rptr;
(temp->lptr)->rptr=NULL;
printf(“\nThe deleted node is %d\t”, temp->info);
free(temp);
}

void search_key()
{
int key;
node *new1,*temp = start;
if(start == NULL)
{
printf("empty ");
return;
}
printf("enter the key");
scanf("%d",&key);
while(temp != NULL && temp->info != key)
{
temp = temp->next;
}
if(temp == NULL)
{
printf("key not found");
return;
}
printf(" key found");
}
Course Code: BCS304 Scheme and Solution

2 Write a C function to add two polynomials represented in Singly Circular Linked List format.

10

3 Define and identify with a suitable diagram the following terms with respect to tree data structure.
i) Degree of a node ii) Degree of a tree iii) Leaf node iv) Non terminal node v) Level of a tree
Course Code: BCS304 Scheme and Solution

Degree of a node: In a tree data structure, the total number of children of a node is called as DEGREE of that
Node. In simple words, the Degree of a node is total number of children it has. The highest degree of a node among
all the nodes in a tree is called as 'Degree of Tree'.Ex: Degree of B is 3, A is 2 and of F is 0

Degree of a Tree: The highest degree of the node among all the nodes in a tree is called the Degree of Tree.

Leaf Node: In a tree data structure, the node which does not have a child is called as LEAF Node. In simple words, 5X2=10
a leaf is a node with no child. In a tree data structure, the leaf nodes are also called as External Nodes. External
node is also a node with no child. In a tree, leaf node is also called as 'Terminal' node.Ex: K,L,F,G,M,I,J are leaf
node

Non-Terminal Node: In a tree data structure, the node which has atleast one child is called as INTERNAL Node.
In simple words, an internal node is a node with atleast one child. In a tree data structure, nodes other than leaf
nodes are called as Internal Nodes. The root node is also said to be Internal Node if the tree has more than one
node. Internal nodes are also called as 'Non-Terminal' nodes.

Level of a Tree: In a tree data structure, the root node is said to be at Level 0 and the children of root node are at
Level 1 and the children of the nodes which are at Level 1 will be at Level 2 and so on... In simple words, in a tree
each step from top to bottom is called as a Level and the Level count starts with '0' and incremented by one at each
level (Step).
4 Write an explanatory note on the following representation of a tree with suitable diagrams. i) List
representation ii) Left Child-Right sibling representation iii) Representation as a Degree-two tree.

i) List representation

In this representation, we use two types of nodes one for representing the node with data called 'data node' and
another for representing only references called 'reference node'. We start with a 'data node' from the root node in the
tree. Then it is linked to an internal node through a 'reference node' which is further linked to any other node
directly. This process repeats for all the nodes in the tree.
The above example tree can be represented using List representation as follows...
Course Code: BCS304 Scheme and Solution

ii) Left Child-Right sibling representation


In this representation, every node's data field stores the actual value of that node. If that node has left a child, then
left reference field stores the address of that left child node otherwise stores NULL. If that node has the right
sibling, then right reference field stores the address of right sibling node otherwise stores NULL.
The above example tree can be represented using Left Child - Right Sibling representation as follows...
3

iii) Representation as a Degree-two tree.

To obtain degree-two tree representation of a tree, rotate the right- sibling pointers in the left child- right sibling tree
clockwise by 45 degrees. In a degree-two representation, the two children of a node are referred as left and right
children.

5. a Define the following types of binary trees, with suitable diagram. i) Full binary tree ii) Skewed tree
iii) Complete binary tree

i) Full binary tree


A full binary tree of depth ‘k’ is a binary tree of depth k having 2 k – 1 nodes, k ≥ 1.

3X2=6
Course Code: BCS304 Scheme and Solution

ii) Skewed tree


A skewed tree is a tree, skewed to the left or skews to the right. or It is a tree consisting of only left subtree or only
right subtree.

 A tree with only left subtrees is called Left Skewed Binary Tree.
 A tree with only right subtrees is called Right Skewed Binary Tree.

iii) Complete binary tree


A binary tree T is said to complete if all its levels, except possibly the last level, have the maximum number node 2i
, i ≥ 0 and if all the nodes at the last level appears as far left as possible.

5. b Mention the properties of a binary search tree.


Lemma 1: [Maximum number of nodes]:
(1) The maximum number of nodes on level i of a binary tree is 2
i-1, i ≥ 1.
(2) The maximum number of nodes in a binary tree of depth k is 2
k -1, k ≥ 1.
4
Lemma 2: [Relation between number of leaf nodes and degree-2 nodes]:
For any nonempty binary tree, T, if n0 is the number of leaf nodes and n2 the number of nodes of degree 2, then n0
= n2 + 1.

6. a Explain with a suitable diagram how a tree can be represented using an array. Mention the draw-
backs of the same if any.

Array representation:
A tree can be represented using an array, which is called sequential representation.
The nodes are numbered from 1 to n, and one dimensional array can be used to store the
nodes.
Position 0 of this array is left empty and the node numbered i is mapped to position i of
3
the array.
Below figure shows the array representation for both the trees of figure (a).
Course Code: BCS304 Scheme and Solution

Drawbacks 3

Write a C function to insert a node into a binary search tree.


6. b
struct node* insert(struct node* node, int key) {
/* If the tree is empty, return a new node */
if (node == NULL)
return newNode(key);

/* Otherwise, recur down the tree */


if (key < node->key)
node->left = insert(node->left, key); 4
else if (key > node->key)
node->right = insert(node->right, key);

/* return the (unchanged) node pointer */


return node;
}

7. a Explain with a suitable diagram and algorithm how threads can be created in a threaded binary
tree
Course Code: BCS304 Scheme and Solution

Explanation
3

typedef struct threadTree *threadPointer


typedef struct{
short int leftThread; threadPointer
leftChild;
char data;
threadPointer rightChild;
short int rightThread;
}threadTree;

7. b Define the following with respect to graph data structure. i) Path ii) Length of a path

Path
A “path” from vertex u to vertex v in graph G is a sequence of vertices u, i1, i2…..ik, v such that (u, i1), (i1, i2),
2X2=4
…..(ik, v) are edges in E(G).

Length of a path
The “Length of a path” is the number of edges on it.
Ex: Considering graph G1, path is (0, 1), (1, 3), (3, 2) is also written as 0, 1,3, 2. Paths 0, 1, 3, 2 and 0, 1, 3, 1 of G1
are both of length 3. 0, 1, 3, 2 is a simple path and 0, 1, 3, 1 is not a simple path.

8. a Define the following with respect to hashing. i) Static hashing ii) Dynamic hashing

Static Hashing:
Is a hashing technique in which the table(bucket) size remains the same (Fixed during compilation time) is called 3
static hashing.
 Various techniques of static hashing are linear probing and chaining
 As the size is fixed, this type of hashing consist handling overflow of elements (Collision) efficiently.

Dynamic Hashing: Dynamically increases the size of the hash table as collision occurs. There are two types:
1) Dynamic hashing using directory or (Extendible hashing) : uses a directory that grows or shrinks
depending on the data distribution. No overflow buckets 3
2) Directory less Dynamic hashing or (Linear hashing): No directory. Splits buckets in linear order,
uses overflow buckets
Course Code: BCS304 Scheme and Solution

8. b Define a forest and specify the algorithm to convert a forest into a binary tree.

A forest is a set of disjoint trees. Removing the root of a tree produces a forest. A forest can be transformed into a
single binary tree by linking the binary tree representations of each tree in the forest through the rightChild field. 2

Forest is a collection of some trees. As the tree can correspond to a unique binary tree,
the forest can also correspond to a unique binary tree [2].
If F={T1,T2,…,Tn} is a forest, according the following rules to convert F into a binary tree B={root,LB,RB}:
(1) If F is empty, that is n=0, B will be an empty tree;
(2) Otherwise, follow these steps to convert:
① The root of B (named root) is the root of the first tree of the forest
(ROOT(T1)); 2
② The left subtree of B (named LB) is a binary tree converted from F1=
{T11,T12,…,T1m}, which is the subtree forest of the root of T1;

9. a Define the following methods in hashing. i) Division method ii) Mid square method iii) Folding
method

Division Method: It is the most simple method of hashing an integer x. This method divides x by M and then uses
the remainder obtained. In this case, the hash function can be given as The division method is quite good for just 2
about any value of M and since it requires only a single division operation, the method works very fast. However,
extra care should be taken to select a suitable value for M. Generally, it is best to choose M to be a prime number
because making M a prime number increases the likelihood that the keys are mapped with a uniformity in the
output range of value

Mid square method: Here, the key K is squared. A number ‘l’ in the middle of K2 is selected by removing the
digits from both ends. H(k)=l 2
Example 1: Solution: Let key=2345, Its square is K 2 =574525 H (2345) =45=>by discarding 57 and 25

Folding method:
Step 1: Divide the key value into a number of parts. That is, divide k into parts k1, k2, ..., kn, where each part has
the same number of digits except the last part which may have lesser digits than the other parts.
Step 2: Add the individual parts. That is, obtain the sum of k1 + k2 + ... + kn. The hash value is produced by 2
ignoring the last carry, if any. Note that the number of digits in each part of the key will vary depending upon the
size of the hash table
9. b Write a note on representation of disjoint sets in the form a tree

Trees can be used for the representation of sets. Sets being considered are pairwise disjoint.If Si and Sj are two sets
and i≠j, then there is no element that is in both Si and Sj. If 10 elements numbered 0 through 9 are partitioned into 3
disjoint sets

S1={0, 6, 7, 8}, S2={1, 4, 9} and S3={2, 3, 5} 4


Course Code: BCS304 Scheme and Solution

10. a Convert the given infix expression a+b+c+d*e to an expression tree

Postfix form

ab+c+de*+

10. b Write a note on the winner tree and loser tree.


Winner tree
is a complete binary tree, in which each node is representing the smaller or greater of its two children, is called
winner tree. The root is holding the smallest or greatest node of the tree. The winner of the tournament tree is the
smallest or greatest n key in all the sequences. It is easy to see that winner tree can be formed in O(log n) time.
2
Looser Trees
are complete binary tree for n players where n external nodes and n – 1 internal nodes are present. The looser of the
match is stored in the internal nodes. But in this overall winner is stored at tree[0]. The looser is an alternative
representation, that stores the looser of a match at the corresponding node. An advantage of the looser is that, to
2
restructure the tree after winner tree been output, it is sufficient to examine node on the path from leaf to root rather
than the sibling of the nodes on this path.

Faculty Signature Scrutinizer Signature HOD Signature

You might also like