First time user?    |

#### Select chapter

functions (3.papers)
loops (1.papers)
arrays (2.papers)
structures (3.papers)
unions (1.papers)
pointers (7.papers)
null pointers (1.papers)
strings (2.papers)
misc c concepts (1.papers)
Data structures (5.papers)
trees (1.papers)
basics (5.papers)
Hide

# c data structures interview questions and answers

1
```data structures in c:

What operation below function is doing?
And which data structure is this?

#define MAX_ELE 10 //assume maximum elements is 10
int cur; //points to current top element.

int fun (int ds[])
{
int val;
if (cur == -1)
{
val = -1;
}
else
{
val = ds [cur];
--cur;
}
return val;
}```
1. `this function is trying to retrieve an existing element from the array ds[]. here ds is an array data structure.`
2. `this function is trying to retrieve an existing element from top location of this data structure. So this is a stack. and operation here is pop operation.`
3. `this function is trying to retrieve an existing element from starting location of this data structure. So this is a stack. and operation here is pop operation.`
4. `this function is trying to retrieve an existing element from starting location of this data structure. So this is a queue. and operation here is deletion operation on queue.`
Share
2
```assume below things

#define MAX_ELE 10 //assume maximum elements is 10
int cur; //points to current top element.

and Which of the below function are correct implementation of a stack pop() function?```
1. ```int fun (int ds[])
{
int val;
if (cur == -1)
{
val = -1;
}
else
{
val = ds [cur];
--cur;
}
return val;
}```
2. ```int fun (int ds[])
{
int val;
if (cur == MAX_ELE)
{
val = -1;
}
else
{
val = ds [cur];
++cur;
}
return val;
}```
3. ```int fun (int ds[])
{
int val;
if (cur == 0)
{
val = -1;
}
else
{
val = ds [cur];
--cur;
}
return val;
}```
4. ```int fun (int ds[])
{
int val;
if (cur == 0)
{
val = -1;
}
else
{
val = ds [--cur];
}
return val;
}```
Share
Share
Share
Share
6
`what is deque in c? (hint:double )`
1. `removing element from the queue is called as deque.`
2. `inserting an element into the queue is called as deque`
3. `double ended queue, where we can insert and delete elements at both the ends.`
4. `double ended queue, where we can insert at only end but we can delete from both the ends.`
Share
7
`what is enqueue in c?`
1. `inserting element into the queue is called as enqueue operation.`
2. `queue where we can insert and delete at only one end is called as enqueue.`
3. `queue where we can insert and delete at the same end is called as enqueue.`
4. `queue where we can insert at only one end but can delete from any end.`
Share
8
```which of the below is not a queue?

i. circular queue
ii. deque
iii. priority queue
```
1. `i`
2. `ii`
3. `iii`
4. `all are types of a queues.`
Share
9
```How to implement a queue in c?

i. array
1. `i`
2. `i or ii`
3. `i or ii or iii`
4. `i or iii`
Share
10
```In a queue with elements c,b,a , where c is in front and a in the rear.
If we perform enqueue(d), then how does the queue look like?```
1. `d,c,b,a`
2. `c,b,a,d`
3. `either option 1 or option 2, we can't say`
4. `none of the above`
Share
Share
12
`What is the time complexity of implementing a queue using a double linked list in c?`
1. `O(n)`
2. `O(log n)`
3. `O(1)`
4. `O(n^2)`
Share
Share
Share
15
`What is a bounded queue in c?`
1. `Queue of fixed no of items.`
2. `Queue of unlimited no of items.`
3. `Queue which will not allow the value to be more than a bound value.`
4. `Queue which will allow the value to be always more than a bound value.`
Share
16
```linked list example in c:

What is below function fun() doing?
what is the operation, and what is this data structure?

struct node
{
int data;

void fun(int val)
{
struct node *temp = NULL;
temp=(struct node *)malloc(sizeof(struct node));
temp->data=val;
}```
1. `function fun() is trying to insert a new element into the singly linked list. operation here is insertion to the single linked list. data structure here is linked list.`
2. `function fun() is trying to insert a new element at the end of previous element. this operation is a push operation on stack(as we insert new elements in stack at the end). this data structure is implementation of push operation of stack using a linked list.`
3. `function fun() is trying to insert a new element at the end of previous element. this operation is a push operation on queue(as we insert new elements in queue at the end). this data structure is implementation of insert() operation of queue using a linked list.`
4. `it can be either option 2 or 3.`
Share
17
```Demo code for linked list in c:

What is below function disp() doing?
what is the operation, and what is this data structure?
assume that head is always pointing to the latest element added at the end.

struct node
{
int data;

void disp()
{
struct node *temp;
printf("data structure is empty\n");
else
{
printf("retrieving... %d\n",temp->data);
free(temp);
}
}```
1. `disp is removing top(end) element from this data structure. so it is a pop() operation of a stack using linked list.`
2. `disp is removing top element from this data structure. so it is a remove() operation of a queue using linked list.`
3. `disp is removing first element from this data structure. so it is a pop() operation of a stack using linked list.`
4. `disp is removing first(old) element from this data structure. so it is a remove() operation of a queue using linked list.`
Share
18
```What is below function move() doing?
What is the name this famous program?
For which data structure, this is an example?

void move(int n,char *s,char *i,char *d)
{
if(n>0)
{
move(n-1,s,d,i);
printf("moving %d disk from %S to %s", n, s, d);
move(n-1,i,s,d);
}
}```
1. `move is recursive function call to move 'n' number of rings from source 's' to destination 'd' towers respectively. this is famous towers of hanoi program. this is an example of stack architecture.`
2. `move is recursive function call to move 'n' number of rings from source 's' to destination 'd' towers respectively. this is famous towers of hanoi program. this is an example of queue architecture.`
3. `move is recursive function call to move 'n' number of rings from source 's' to destination 'i' towers respectively. this is famous towers of hanoi program. this is an example of stack architecture.`
4. `move is recursive function call to move 'n' number of rings from source 's' to destination 'i' towers respectively. this is famous towers of hanoi program. this is an example of queue architecture.`
Share
19
```in what order parameters passed to a function will be stored in the system's stack segment?

eg: If a function is taking 3 arguments int a, int b, int c . .like fun(int a, int b, int c){..} then when some body makes a call to this function with three parameters fun(x,y,z); then in what order these 3 variables will be stored in stack segment?```
1. `stack will store in x,y,z order.. where z is the top most element inserted and it is the top most element to be popped out.`
2. `stack will store in z,y,x order.. where x is the top most element inserted and it is the top most element to be popped out.`
3. `it can be either option 1 or option2 but there is no guarantee.`
4. `it really doesn't matter in which order it is going to store.`
`when a function calls other function in c language, then where does PC(program counter) will be stored? on top of the stack or below the local variables?`
1. `first local variables will be stored in the stack of that function, and then on the top PC will be stored.`
2. `first PC will be stored, and then the local variables of that function.`
3. `it can be either option 1 or option2 but there is no guarantee.`
4. `it really doesn't matter in which order it is going to store.`