Write a c program to check whether a number is prime or not. Given an integer, We have to write an efficient code to check whether a number is prime or not.

### Categories

### Interview Questions

Technology Blog Where You Find Programming Tips and Tricks

Given **two sorted arrays**, Write a code to find common elements in two arrays. In other words, we have to write a code to find the intersection of two arrays.

Let’s assume following two sorted arrays arr1[] and arr2[].

int arr1[] = {2, 3, 4, 5, 6};

int arr2[] = {4, 6, 7, 8, 9};

Write an efficient program to generate prime numbers between 1 to N (Where N is 10, 100, 1000 etc). This question can also be asked like this, Generate prime numbers between 1 to 100 or 1 to 10 etc.

Suppose the value of N is 10, So the prime numbers between 1 to 10 is 2, 3, 5, 7. Now let’s learn the most efficient algorithm (**Sieve of Eratosthenes**) to generate Prime Numbers between 1 to N. Before solving this program, let’s understand what is a prime number.

MCQ on stack and queue data structure. The concept of Stack and Queue data structure is very important in computer science. In my previous post i have discussed following things.

Stack program in C using Array.

Queue data structure and their implementation.

The purpose of this objective questions is to test how well you understand the concept of stack and queue.

Write a Program to find the second largest number in an unsorted array. Given an array of unsorted values find the second largest number in an array.

For example – Let’s take an array.

arr[] = { 4, 1, 5, 2, 8, 0, 3, 55}

The second largest element in this array is 8. So how do you find the second largest number in an array ? There are multiple ways by which you can solve this problem.

**First Approach : Sort an Array**

The simple approach is to sort an array using sorting algorithm. After sorting an array **element at n-2 index** will be the second largest element.

You can use following sorting algorithms.

ii) Insertion Sort

iii) Bubble Sort

iv) Merge Sort

Selection sort, insertion sort and bubble sort are not suitable for large data sets as their **time complexity** is **O(n ^{2})** . You can use Merge Sort or Quick Sort for large data sets.

NOTE– If values of an array is repeated then this approach won’t work. Then the best approach is to traverse an array to find the second largest element.

**Second Approach : Traverse an array**

The best approach is to traverse an array to find the second largest number in an array. Using this approach maintain two flags one for highest and other for the second highest number. The time complexity of this approach is O(n).

Write a program to delete a linked list. Given a linked list, we have to write a code to delete a linked list.

To delete a complete linked list, traverse all the nodes of a linked list and delete one by one.

Print Middle Element of a Linked List

To delete a node one by one maintain **two pointers**. The first pointer points to head and the second pointer keeps the reference to next node. So when a node is free, you can assign the reference of next node using the second pointer.

What is insertion sort. How it’s different from Selection sort and Bubble sort. I discussed selection sort and bubble in my previous posts. In this post i’ll discuss another sorting algorithm insertion sort.