top of page
  • Facebook
  • Twitter
  • Instagram

Top Data-Structures Interview Questions

Mobiprep handbooks are free downloadable placement preparation resources that can help you ace any company placement process. We have curated a list of the 40 most important MCQ questions which are asked in most companies such as Infosys, TCS, Wipro, Accenture, etc. The placement handbooks also have detailed explanations for every question ensuring you revise all the questions with detailed answers and explanations.

Question

33

Explanation

Write C code to implement enque and dequeue operation in Queue.

void enqueue()
{
int add_item;
if (rear == MAX - 1)
printf("Queue Overflow \n");
else
{
if (front == - 1)
/*If queue is initially empty */
front = 0;
printf("Inset the element in queue : ");
scanf("%d", &add_item);
rear = rear + 1;
queue_array[rear] = add_item;
}
}

int dequeue() {
if(isempty())
return 0;

int data = queue[front];
front = front + 1;

return data;
}

Question

34

Explanation

How many undirected graphs (not necessarily connected) can be constructed out of a given set V= {V 1, V 2,…V n} of n vertices ?


In an undirected graph, there can be maximum n(n-1)/2 edges.
We can choose to have (or not have) any of the n(n-1)/2 edges. So, total number of undirected graphs with n vertices is 2^(n(n-1)/2).

Question

35

Explanation

Write a C function to reverse a list.

void reverse_list()
{
// Initialize current, previous and next pointers
Node *current = head;
Node *prev = NULL, *next = NULL;
while (current != NULL)
{
// Store next
next = current->next;
// Reverse current node's pointer
current->next = prev;
// Move pointers one position ahead
prev = current;
current = next;
}
head = prev;
}

Question

36

Explanation

Write a C function to find the shortest path in a graph.


int shortest_path(vector <int> edges[], int u, int v, int n)

{
vector<bool> visited(n, 0);

vector<int> distance(n, 0);

queue <int> queue1;

distance[u] = 0;

queue1.push(u);

visited[u] = true;

while (!queue1.empty())

{

int x = queue1.front();

queue1.pop();

for (int i=0; i<edges[x].size(); i++)

{

if (visited[edges[x][i]])

continue;

distance[edges[x][i]] = distance[x] + 1;

queue1.push(edges[x][i]);

visited[edges[x][i]] = 1;

}

}

return distance[v];

}

bottom of page