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)
linked lists (3.papers)
trees (1.papers)
basics (5.papers)
Hide

Sponsored Links


  

c data structures interview questions and answers

1
How to find an element in an unsorted array in c?
  1. By comparing a given element with all the elements of array.
  2. By comparing a given element with all the elements of the array, and if the element is found in between the iterations, then break the loop.
  3. By using binary search algorithm on that array.
  4. since we have manually entered all the elements into that array, then we don't need to traverse array. we can directly say where that item is located.
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
4
What is a Rank sort  in c? What is the time complexity of Rank sort?
  1. Rank sort is moving all the elements of an array in ascending order based on their ranks. Less the rank more the left it will be moved towards 0th index. time complexity of rank sort is O(n^2) as no of comparisons in rank sort is (n-1)n/2 + no of movements is 2n. so its almost equal to n^2.
  2. Rank sort is moving all the elements of an array in descending order based on their ranks. Less the rank more the right it will be moved towards last index. time complexity of rank sort is O(n^2) as no of comparisons in rank sort is (n-1)n/2 + no of movements is 2n. so its almost equal to n^2.
  3. Rank sort is moving all the elements of an array in ascending order based on their ranks. Less the rank more the left it will be moved towards 0th index. time complexity of rank sort is O(log n^2) as no of comparisons in rank sort is log (n-1)n/2 + no of movements is 2n. so its almost equal to log n^2.
  4. Rank sort is moving all the elements of an array in descending order based on their ranks. Less the rank more the right it will be moved towards last index. time complexity of rank sort is O(log n^2) as no of comparisons in rank sort is log (n-1)n/2 + no of movements is 2n. so its almost equal to log n^2.
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
11
what is below function doing?
what is this data structure ds used in below program?

#define MAX 10
int ds[MAX];
int f = - 1;
int r = - 1;

fun(int item)
{
    if (r == MAX - 1)
            printf("full or Overflow");
    else
    {
        if (f == - 1)
             f = 0;
        r = r + 1;
        queue_arr[r] = item;
    }
}
  1. the function fun is trying to push a new element into the array ds[]. this is a stack push() implementation.
  2. the function fun is trying to insert a new element at the front of the array ds[]. this is the implementation of enqueue functionality of a queue.
  3. the function fun is trying to insert a new element at the rear of the array ds[]. this is the implementation of enqueue functionality of a queue.
  4. the function fun is trying to push a new element at the rear of the array ds[]. this is a stack push() implementation.
Show Answer
Share Facebook gmail Twitter
12
what is below function doing?
what is this data structure ds used in below program?

#define MAX 10
int ds[MAX];
int f = - 1;
int r = - 1;

remove()
{
    if (f == - 1 || f > r)
    {
        printf("Underflow");
    }
    else
    {
        printf("Element deleted %d",ds[front]);
        f = f + 1;
    }
}
  1. function remove is trying to remove element from the end of the data structure ds[]. this is an implementation of dequeue functionality of a queue using array.
  2. function remove is trying to remove element from the front of the data structure ds[]. this is an implementation of dequeue functionality of a queue using array.
  3. function remove is trying to remove element from the front of the data structure ds[]. this is an implementation of pop functionality of a stack using array.
  4. function remove is trying to remove element from the end of the data structure ds[]. this is an implementation of pop functionality of a stack using array.
Show Answer
Share Facebook gmail Twitter
13
What is below function fun() doing?
what is the operation, and what is this data structure?

 struct node
 {
 int data;
 struct node *link;
 }*head=NULL, *tail=NULL;


 void fun(int val)
 {
 struct node *temp = NULL;
 temp=(struct node *)malloc(sizeof(struct node));
 temp->data=val;
 temp->link=NULL;

 if(head==NULL)
 {
     head = temp;
     tail = temp;
 }else{
     tail->link = temp;
     tail = temp;     
 }

 }
  1. function fun is trying to insert a new value at the top of the stack. Here we are trying to implement push() using a single linked list.
  2. function fun is trying to insert a new value at the rear of the queue. Here we are trying to implement enqueue() using a single linked list.
  3. function fun is trying to insert a new value at the front  of the queue. Here we are trying to implement enqueue() using a single linked list.
  4. function fun is trying to insert a new value at the front location of the stack. Here we are trying to implement push() using a single linked list.
Show Answer
Share Facebook gmail Twitter
14
Sample code for single linked list:

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

 struct node
 {
 int data;
 struct node *link;
 }*head=NULL, *tail=NULL;


 void rem()
 {

 if(head==NULL)
 {
     printf("underflow");        
 }else{
     struct node *temp = head;
     head = head->link;
     free(temp);        
 }

 }
  1. function rem is trying to delete a value from the top of the stack. Here we are trying to implement pop() using a single linked list.
  2. function rem is trying to delete a value at the rear of the queue. Here we are trying to implement dequeue() using a single linked list.
  3. function fun is trying to remove a value from the front  of the queue. Here we are trying to implement dequeue() using a single linked list.
  4. function fun is trying to remove a value from the front location of the stack. Here we are trying to implement pop() using a single linked list.
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
18
circular queue example in c:

what is below function doing?
what is this data structure ds?

#define MAX 10
int ds[MAX];
int f = - 1;
int r = - 1;

void fun(int item)
{
     int x;
     if((f == 0 && r == max-1)||(f==r+1))                         
     {
          printf("overflow");
          return;
     }
     if(f==-1)
     {
          f=r=0;
     }
     else
     {
          if(r==max-1)
          {
               r=0;
          }
          else
          {
               r++;
          }
     }

     ds[r]=item;
}
  1. the function fun is trying to push a new element into the array ds[]. this is a circular stack push() implementation.
  2. the function fun is trying to insert a new element at the front of the array ds[]. this is the implementation of enqueue functionality of a circular queue.
  3. the function fun is trying to insert a new element at the rear of the array ds[]. this is the implementation of enqueue functionality of a circular queue.
  4. the function fun is trying to push a new element at the rear of the array ds[]. this is a circular stack push() implementation.
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
20
What is the time complexity of selection sort algorithm in c?
  1. total no of comparisons are 3(n)
  2. total no of comparisons are n(n+1)/2
  3. total no of comparisons are (n-1)n/2
  4. total no of comparisons are n^2
Show Answer
Share Facebook gmail Twitter
Read more papers :