# Tag Archives: spiral

## Print matrix elements diagonally in spiral form

Given a matrix arr[][] of dimensions N * M and an integer K, the task is to print all elements of the matrix starting from… Read More »

## Level order traversal in spiral form using stack and multimap

Given a binary tree of N nodes, the task is to print level order traversal in a spiral form. In spiral form, nodes at the… Read More »

## Convert given Matrix into sorted Spiral Matrix

Given a matrix, the task is to convert the given Matrix into sorted Spiral Matrix. Examples: Input: y[][] = { { 2, 5, 12 },… Read More »

## Form a Spiral Matrix from the given Array

Given an array, the task is to form a spiral matrix Examples: Input: arr[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9,… Read More »

## Recursive Program to Print extreme nodes of each level of Binary Tree in alternate order

Given a binary tree, the task is to print nodes of extreme corners of each level but in alternate order. Examples: Input : 1 /… Read More »

## Reverse Clockwise spiral traversal of a binary tree

Given a Binary Tree. The task is to print the circular reverse clockwise spiral order traversal of the given binary tree.Reverse Clockwise Traversal means to… Read More »

## Print a given matrix in counter-clock wise spiral form

Given a 2D array, print it in counter-clock wise spiral form. See the following examples. Examples : Input: 1 2 3 4 5 6 7… Read More »

## Find coordinates of a prime number in a Prime Spiral

Introduction The Ulam spiral is a graphical depiction of the set of prime numbers, devised by mathematician Stanislaw Ulam. It is constructed by writing the… Read More »

## Print a matrix in a spiral form starting from a point

Given a matrix of size n*m, and a point P(c, r). Print the matrix in a spiral form(clockwise) starting from the point P. Examples :… Read More »

## Print a given matrix in reverse spiral form

Given a 2D array, print it in reverse spiral form. We have already discussed Print a given matrix in spiral form. This article discusses how… Read More »

## Circular Matrix (Construct a matrix with numbers 1 to m*n in spiral way)

Given two values m and n, fill a matrix of size ‘m*n’ in spiral (or circular) fashion (clockwise) with natural numbers from 1 to m*n.… Read More »

## Sum of both diagonals of a spiral odd-order square matrix

We have given a spiral matrix of odd-order, in which we start with the number 1 as center and moving to the right in a… Read More »

## Rotate each ring of matrix anticlockwise by K elements

Given a matrix of order M*N and a value K, the task is to rotate each ring of the matrix anticlockwise by K elements. If… Read More »

## Print K’th element in spiral form of matrix

Given a 2D Matrix of order n X m, print K’th element in the spiral form of the matrix. See the following examples. Examples: Input:… Read More »

## Print n x n spiral matrix using O(1) extra space

Given a number n, print a n x n spiral matrix (of numbers from 1 to n x n) in clockwise direction using O(1) space.… Read More »