Category Archives: Arrays

View algorithms on Arrays

Print a matrix in spiral form.

Question: Write a program in C to print the given matrix in spiral order. Input: 1    2    3    4 5    6    7    8 9   10   11  12 13  14  15  16 Output: 1 2 3 4 8 12 16 15 14 13 9 5 6  7 11 10 Printing a matrix in… Read More »

Find the median of a sequence of n integers.

Question: Given a sequence of integers, find the median of the integers? Input: arr [] = {15, 23, 4, 16, 8, 42}. Find median. Output: 15 Since the question does not specify anything we cannot assume that the given array is a sorted one. The definition of median is the (n/2)th element of a sorted sequence of integers.… Read More »

Print 2 repeating elements in a given array. (Method 3)

Question: Given an array with n+2 elements, all elements of the array are in range 1 to n and also all elements occur only once except 2 numbers which occur twice. Find those 2 repeating numbers. Input: arr[] = {6, 2, 6, 5, 2, 3, 1} Output: 6 2 We discussed a method to perform this task using… Read More »