functions (3.papers)

loops (1.papers)

Conditional statements (2.papers)

arrays (2.papers)

structures (3.papers)

unions (1.papers)

Enums and TypeDefs (3.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)

bitwise operators (1.papers)

1

How to find an element in an unsorted array in c?

By comparing a given element with all the elements of array.

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.

By using binary search algorithm on that array.

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

2

what will be time complexity of linear search algorithm on an unsorted array?

O(n)

O(log n/2)

O(1)

O(log n)

Show Answer

3

Rank of an element in a given array is calculated as no of smaller elements in that array + no of equal elements to its left. With this formula find the Rank of element 3 that appears in two locations in below array = [5,0,3,4,3];

1, 1 respectively.

2,1 respectively

1,2 respectively

2,2 respectively

Show Answer

4

What is a Rank sort in c? What is the time complexity of Rank sort?

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.

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.

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.

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

Show Answer

6

What is the sorting algorithm used in below program? #include <stdio.h> int arr[10] = {12,2,3,0,1,17,23,90,24,7}; int main(void) { sort(10); for(int i=0; i<10; i++){ printf("%d ", arr[i]); } return 0; } void sort(int n){ for(int i=0; i<n-1; i++){ for(int j=0; j<n-i-1; j++){ if(arr[j] > arr[j+1]){ int temp = arr[j]; arr[j] = arr[j+1]; arr[j+1] = temp; } } } }

selection sort

quick sort

bubble sort

rank sort

Show Answer

7

What is the time complexity of the bubble sort algorithm in worst case?

O(log n)

O(n^2)

O(n)

O(n log n)

Show Answer

8

In a stack with elements c,b,a where c is at the bottom and a is at the top of stack. And if below operations are performed push(d), pop(), push(e), then how does the stack look like after performing operations?

b,a,d,e

c,b,d,e

e,d,c,b

c,b,a,e

Show Answer

Show Answer

Show Answer

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; } }

the function fun is trying to push a new element into the array ds[]. this is a stack push() implementation.

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.

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.

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

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; } }

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.

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.

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.

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

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; } }

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.

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.

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.

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

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); } }

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.

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.

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.

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

Show Answer

16

what is the time complexity of implementing dequeue() of queue using array? Assuming that we are not using two pointers to indicate which is front and which back. i.e we are not using a circular queue.

O(1)

O(n)

O(log n)

O(log n/2)

Show Answer

17

what is the time complexity of implementing dequeue() of queue using array? Assuming that we are using a circular queue.

O(n)

O(log n/2)

O(1)

O(log n)

Show Answer

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; }

the function fun is trying to push a new element into the array ds[]. this is a circular stack push() implementation.

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.

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.

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

19

what are the number of comparisons and swapping done for bubble sort algorithm for worst case?

n^2

2(n^2)

2 log(n^2)

log n

Show Answer

20

What is the time complexity of selection sort algorithm in c?

total no of comparisons are 3(n)

total no of comparisons are n(n+1)/2

total no of comparisons are (n-1)n/2

total no of comparisons are n^2

Show Answer