IMPORTANT VTU QUESTIONS - Prof.
Deepa H
1. Define Data structures. With a neat diagram, explain the classification of Data structures with
examples.
Data structure is a representation of the logical relationships existing between individual elements of data.
The logical or mathematical model of a particular organization of data is called a data structure.
Primitive data structures allow storing only one value at a particular location. Primitive data structures of
any programming language are the data types that are predefined in that programming language.
The type and size of those data types are defined already. The four main primitive data structures which are
defined in mostly all programming languages are float, character, boolean, and integer.
boolean:- The Boolean data type allows storing two values only i.e. true and false. Mostly boolean data type
is used for testing the conditions.
char:- The character data type allows you to store a single character. It stores ASCII assigned values of
the lower case alphabets, upper case alphabets and some special symbols.
integer:- Integer are used to store the value of the numeric type. It allows for storing both negative and
positive values.
float:- The float data type allows you to store the floating value.
double:- The double data type also allows you to store the floating value. But float and double differ from
each other in terms of their range, float allows to 32-bit value while double allows a 64-bit value
Non-primitive data structures are the data structure created by the programmer with the help of primitive data
structures. Non-primitive data structures are divided into linear and non-linear data structures. Arrays and
linked lists are examples of linear data structure and trees, graph are examples of non-linear data structure.
Array:- Array is a linear data structure that stores the elements of similar data types at a contiguous memory
location.
Stack:- Stack is a linear data structure that works on the principle of LIFO(Last In First Out) which allows
insertion and deletion of elements from one end only i.e. top.
Queue:- Queue is a linear data structure that works on the principle of FIFO(First In First Out) which allows
the insertion of elements at one end i.e. rear and deletion of elements from another end i.e. front.
Tree:- Tree is a non-linear data structure that stores the element as nodes in the form of a hierarchical (parent-
child) relationship.
Graph: A Graph is a non-linear data structure that consists of vertices (nodes) and edges.
2. Write a function to evaluate the postfix expression. Illustrate the same for the given postfix
expression: ABC-D*+E/F+ and assume A=6, B=3, C=2, D=5, E=1 and F=7.
3. Write the rules to convert infix to postfix and find the Postfix form of the following infix expression
using Stack A*(B*C+D*E)+F
4. What is String? Write functions in C for the following operations using built-in functions
i) Compare two strings.
ii) Concatenate two strings.
iii) Find substring in a string.
Concatenate two strings
Compare two strings
Find substring in a string
5. Define Stack. Give the Implementation for push(), pop() and display() Functions by considering its full
and Empty condition
6. Differentiate Structures and Unions with a suitable example.
7. What is pointer? Explain with Example
8. What is Dynamic memory Allocation? Explain with Example
Dynamic Memory Allocation can be defined as a procedure in which the size of a data structure (like Array)
is changed during the runtime. C provides some functions to achieve these tasks. There are 4 library functions
provided by C defined under <stdlib.h> header file to facilitate dynamic memory allocation in C programming.
They are:
➢ malloc()
➢ calloc()
➢ free()
➢ realloc()
malloc()
The name "malloc" stands for memory allocation.
The malloc() function reserves a block of memory of the specified number of bytes. And, it returns
a pointer of void which can be casted into pointers of any form.
Syntax of malloc()
ptr = (castType*) malloc(size);
Example
ptr = (float*) malloc(100 * sizeof(float));
calloc()
The name "calloc" stands for contiguous allocation.
The malloc() function allocates memory and leaves the memory uninitialized, whereas the calloc() function
allocates memory and initializes all bits to zero.
Syntax of calloc()
ptr = (castType*)calloc(n, size);
Example:
ptr = (float*) calloc(25, sizeof(float));
free()
Dynamically allocated memory created with either calloc() or malloc() doesn't get freed on their own. You must
explicitly use free() to release the space.
Syntax of free()
free(ptr);
This statement frees the space allocated in the memory pointed by ptr.
realloc()
If the dynamically allocated memory is insufficient or more than required, you can change the size of
previously allocated memory using the realloc() function.
Syntax of realloc()
ptr = realloc(ptr, x);
9. What is Linked list? Explain the Different types of Linked list with a neat diagram.
A linked list is a linear data structure, in which the elements are not stored at contiguous memory locations.
The elements in a linked list are linked using pointers. In simple words, a linked list consists of nodes where
each node contains a data field and a reference (link) to the next node in the list.
Types of Linked Lists:
1. Singly Linked List
2. Doubly Linked List
3. Singly Circular Linked List
4. Doubly Circular linked list
Singly Linked List
Singly linked list is the simplest type of linked list in which every node contains some data and a
pointer to the next node of the same data type. The node contains a pointer to the next node means that the
node stores the address of the next node in the sequence. A single linked list allows the traversal of data only
in one way.
Doubly Linked List
A doubly linked list or a two-way linked list is a more complex type of linked list that contains a
pointer to the next as well as the previous node in sequence. Therefore, it contains three parts of data, a pointer
to the next node, and a pointer to the previous node. This would enable us to traverse the list in the backward
direction as well.
Singly Circular Linked List
A Singly circular linked list is a type of linked list in which the last node’s next pointer points
back to the first node of the list, creating a circular structure. This design allows for continuous traversal of
the list, as there is no null to end the list.
Doubly Circular linked list
Doubly Circular linked list or a circular two-way linked list is a complex type of linked list that
contains a pointer to the next as well as the previous node in the sequence
10. What is Queue? Develop a C program to implement insertion, deletion and display operations on linear
queue.
(or)
Write the Enqueue, Dequeue operation in Queue?
11. Write the Insertion, Deletion and display operations used in Circular Queue?
12. What is Linked List? Give the Structure representation of Singly linked list and write the c function
for following:
• Insert a node at beginning
• Delete a node at the beginning
• Insert a node at an end
• Delete a node at the beginning
13. Write the C functions to add two Polynomials. Show the linked list representation of below two
polynomials.
P(x) = 3x^18 + 2x^8 + 1
Q(x) = 8x^14 – 3x^10 +10x^6
14. What is the drawback of Singly Linked List? Give the Structure representation of Doubly linked list
and write the c function for following:
• Insert a node at beginning
• Delete a node at the beginning
• Insert a node at an end
• Delete a node at the beginning
15. Define sparse matrix. For the given sparse matrix, give the linked list representation:
Sparse Matrix:
A sparse matrix is a matrix in which most of the elements are zero. This type of matrix is useful in
scenarios where storage and computational efficiency are critical, as we can store only the non-zero
elements rather than all elements, including the zeros.
In linked list, each node has four fields. These four fields are defined as:
• Row: Index of row, where non-zero element is located
• Column: Index of column, where non-zero element is located
• Value: Value of the non-zero element located at index – (row,column)
• Next node: Address of the next node.
REFER CLASS NOTES FOR SPARSE MATRIX USING CIRCULAR LINKED LIST
16. What is Tree Data structures? Write the terminologies of Tree.
17. Explain General Tree Representation
18. Define Binary Tree. Explain the Types of Binary Tree with a neat diagram.
A binary tree is a tree-type non-linear data structure with a maximum of two children for each parent. Every
node in a binary tree has a left and right reference along with the data element. The node at the top of the
hierarchy of a tree is called the root node. The nodes that hold other sub-nodes are the parent nodes.
A parent node has two child nodes: the left child and right child.
Types of Binary Tree
1. Skewed Binary Trees
2. Complete Binary Trees
3. Full Binary Tree
4. Extended Binary tree
Skewed Binary Trees
A skewed binary tree is a type of binary tree in which all the nodes have only either one child or no
child. There are two types of skewed binary tree: left skewed and right skewed binary tree.
Complete Binary Trees
A complete binary tree is a special type of binary tree where all the levels of the tree are filled
completely except the lowest level nodes which are filled from as left as possible.
Full Binary Tree
A perfect binary tree or Full Binary tree is a special type of binary tree in which all the leaf nodes are
at the same depth, and all non-leaf nodes have two children. In simple terms, this means that all leaf
nodes are at the maximum depth of the tree, and the tree is completely filled with no gaps.
Extended binary tree
Extended binary tree is a type of binary tree in which all the null sub tree of the original tree are
replaced with special nodes called external nodes whereas other nodes are called internal nodes
19. Write recursive C functions for in-order, pre-order and post-order traversals of a binary tree. Also,
find all the traversals for the given tree.
INORDER:
void inorder(struct Node* root) {
if (root == NULL)
return;
inorder (root->left);
printf("%d ", root->data);
inorder (root->right);
}
PRE-ORDER:
void preorder(struct Node* root) {
if (root == NULL)
return;
printf("%d ", root->data);
preorder (root->left);
preorder (root->right);
}
POST-ORDER:
void postorder(struct Node* root) {
if (root == NULL)
return;
postorder (root->left);
postorder (root->right);
printf("%d ", root->data);
}
inorder - D B H E I A F C G
preorder - A B D E H I C F G
postorder - D H I E B F G C A
20. Define Binary Search tree. Construct a binary search tree (BST) for the following elements: 100, 85,
45, 55, 120, 20, 70, 90, 115, 65, 130, 145. Traverse using in-order, pre-order, and post-order traversal
techniques. Write recursive C functions for the same.
Recursive c function:
INORDER:
void inorder(struct Node* root) {
if (root == NULL)
return;
inorder (root->left);
printf("%d ", root->data);
inorder (root->right);
}
PRE-ORDER:
void preorder(struct Node* root) {
if (root == NULL)
return;
printf("%d ", root->data);
preorder (root->left);
preorder (root->right);
}
POST-ORDER:
void postorder(struct Node* root) {
if (root == NULL)
return;
postorder (root->left);
postorder (root->right);
printf("%d ", root->data);
}
21. Define the Threaded binary tree. Construct Threaded binary for the following elements: A, B, C, D, E,
F, G, H, I.
22. Construct a binary tree from the Post-order and In-order sequence given below In-order: GDHBAEICF
Post-order: GHDBIEFCA.
(or)
Explain Stack permutation with example
23. Define selection tree. Construct min winner tree for the runs of a game given below. Each run consists
of values of players. Find the first 5 winners.
REFER CLASS NOTES FOR LOSER TREE.
24. Define forest with example
25. Explain the terminologies of graph.
26. Explain Graph Representation
27. Explain Elementary graph operation?
Elementary graph operations are:
BFS(Breadth first search)
DFS (Depth First Search)
Spanning trees
BFS (Breadth First Search):
DFS (Depth First Search):
28. Define hashing. Explain different hashing functions with examples.
A function that converts a given big number to a small integer value. The mapped integer value is used as an
index in the hash table.
Hash Location= KEY % SIZE
29. What is collision? What are the methods to resolve collision? Explain linear probing with an example.
30. Define the leftist tree. Give its declaration in C. Check whether the given binary tree is a leftist tree or
not. Explain your answer.
31. What is chained hashing? Discuss its pros and cons. Construct the hash table to insert the keys: 7, 24,
18, 52, 36, 54, 11 in a chained hash table of 9 memory locations. Use h(k) = k mod m.
Chained hashing, also known as separate chaining, is a technique used to resolve collisions in hash tables.
When two or more keys hash to the same index (known as a collision), chained hashing handles these collisions
by maintaining a linked list of all elements that hash to the same index.
Pros of Chained Hashing:
Simple Implementation: Chained hashing is relatively easy to implement.
Efficient Insertion and Deletion: Insertion and deletion operations are efficient in chained hashing.
Dynamic Data Sets: Chained hashing allows for dynamic resizing of the hash table.
Adaptability: Chained hashing can handle a wide range of input data distributions
Cons of Chained Hashing:
Memory Overhead: Chained hashing can have a higher memory overhead compared to other collision
resolution techniques.
Cache Inefficiency: cache inefficiency, particularly for large hash tables with long linked lists.
Performance Degradation
Poor Worst-Case Performance: Chained hashing does not guarantee constant-time performance for
lookup operations in the worst case
Hash table to insert the keys: 7, 24, 18, 52, 36, 54, 11 in a chained hash table of 9 memory locations using
hash function h(k) = k mod m.
32. Define min Leftist tree. Meld the given min leftist trees.