TCS Questions
TCS Questions
Data structure is a format for storing data in a structured manner. For example, data like photos, videos are store
data structure. It is not a separate programming language. It is just an implementation method and can be implem
programming language like C, C++, Java, etc.
For more applications of each of the data structures, check out the below links:
Applications of a Stack
Applications of Priority Queue
Applications of Depth First Search
Applications of Breadth-First Search
Consider a scenario, where we need to store large amount of data in an array. But, the memory to store that data
contiguously. In this case we cannot use array. Hence, we go for a linked list. Since each node is connected using
memory has to be contiguous.
Also, some of the major differences between a Linked List and an array are given below. For more, click h
Array elements can be accessed Random accessing is not possible in linked lists. The ele
randomly using the array index. will have to be accessed sequentially.
Data elements are stored in contiguous New elements can be stored anywhere and a reference i
locations in memory. created for the new element using pointers.
4) Write the syntax in C to create a node in the singly linked list.
struct node
{
int data;
struct node *next;
};
struct node *head, *ptr;
ptr = (struct node *)malloc(sizeof(struct node));
5) What is the use of a doubly-linked list when compared to that of a singly linked list?
In a singly linked list, we have only forward links. Hence, we cannot traverse the linked list in a backward manne
we go for a doubly linked list. In a doubly linked list, each node has three fields such as previous, data and n
such as a forward and backward link. The previous field of the first node and the address field of the last node
of the second node has the address of the first node and so on.
Also, accessing of elements can be done more efficiently incase of a doubly linked list.
Size of the stack keeps on changing as we insert and delete the element
Stack can store elements of different data type
7) What are the minimum number of Queues needed to implement the priority queue?
Two queues are needed. One queue is used to store the data elements, and another is used for storing priorities. C
implementation of a Priority Queue.
There are three main traversals of a tree such as In-order, Pre-order, Post-order.
9) Why it is said that searching a node in a binary search tree is efficient than that of a simple binary tree?
When searching any node in binary search tree, the value of the target node is compared with the parent node and
tree or right sub tree is searched. So, one has to compare only particular branches. Thus searching becomes effici
Graphs are used in circuit networks where points of connection are drawn as vertices and component wires bec
graph, in transport networks where stations are drawn as vertices and routes become the edges of the graph, in
cities/states/regions as vertices and adjacency relations as edges, in program flow analysis where procedures or
vertices and calls to these procedures are drawn as edges of the graph.
No, we cannot apply the binary search algorithm to a sorted linked list because finding the index of the middle el
12) When can you tell that a Memory Leak will occur?
A memory leak occurs when a program does not free a block of memory allocated dynamically.
13) How will you check if a given Binary Tree is a Binary Search Tree or not?
To know that you need to check the inorder traversal of a binary tree. If it is sorted, then the binary tree is BST. C
perform inorder traversal.
14) Which data structure is ideal to perform Recursion operation and why?
Stack is the most ideal for recursion operation. This is mainly because of its LIFO (Last In First Out) property,
their positions, so it exactly knows which one to return when a function is called.
Some of the important applications are given below. Check them out to know the detailed code & explanation.
16) Convert the below given expression to its equivalent Prefix And Postfix notations.
((A + B) * C – (D – E) ^ (F + G))
postfix Notation: AB + C * DE – – FG + ^
20) Program to return the nth node from the end in a linked list
22) Replace each element of the array by its rank in the array
--
Vinay Chopra
Head-Training and Placement
Guru Nanak Group of Institutions (JNTUH, NAAC A+, NBA, UGC Accredited)
Excellent Campus Placement Award and Excellent Innovation Institute Award
Ibrahimpatnam RR Distt, Hyderabad
8096609818, 7093746845