GeeksforGeeks

A computer science portal for geeks

Depth First Traversal (or Search) for a graph is similar to Depth First Traversal of a tree. The only catch here is, unlike trees, graphs may contain cycles, so we may come to the same node again. To avoid processing a node more than once, we use a boolean visited array.

Read More »

Following questions have been asked in GATE 2012 exam.

Read More »

We have discussed AVL insertion in the previous post. In this post, we will follow a similar approach for deletion.

Read More »

Given a Binary Tree, find vertical sum of the nodes that are in same vertical line. Print all sums through different vertical lines.

Read More »

Following questions have been asked in GATE 2012 exam.

Read More »

Following questions have been asked in GATE 2012 exam.

Read More »

AVL tree is a self-balancing Binary Search Tree (BST) where the difference between heights of left and right subtrees cannot be more than one for all nodes.

Read More »

Following questions have been asked in GATE 2012 exam.

Read More »

Predict the output of following C programs.

Read More »

In the previous post, we discussed how Asymptotic analysis overcomes the problems of naive way of analyzing algorithms

Read More »

Given a Binary Tree, write a function that returns the size of the largest subtree which is also a Binary Search Tree (BST). If the complete Binary Tree is BST, then return the size of whole tree.

Read More »

Most of the times declarations are simple to read, but it is hard to read some declarations which involve pointer to functions. For example, consider the following declaration from “signal.h”.

Read More »

Given a Binary Tree where each node has positive and negative values. Convert this to a tree where each node contains the sum of the left and right sub trees in the original tree. The values of leaf nodes are changed to 0.

Read More »

Following are common definition of Binomial Coefficients. 1) A binomial coefficient C(n, k) can be defined as the coefficient of X^k in the expansion of (1 + X)^n.

Read More »

Given three strings A, B and C. Write a function that checks whether C is an interleaving of A and B.

Read More »

Given two strings str1 and str2, write a function that prints all interleavings of the given two strings. You may assume that all characters in both strings are different

Read More »

Given a string of length n, print all permutation of the given string. Repetition of characters is allowed. Print these permutations in lexicographically sorted order

Read More »

Given a Doubly Linked List which has data members sorted in ascending order. Construct a Balanced Binary Search Tree which has same data members as the given Doubly Linked List. The tree must be constructed in-place (No new node should be allocated for tree conversion)

Read More »

Given a sequence of matrices, find the most efficient way to multiply these matrices together.

Read More »

Given a value N, if we want to make change for N cents, and we have infinite supply of each of S = { S1, S2, .. , Sm} valued coins, how many ways can we make the change? The order of coins doesn’t matter.

Read More »

Given a Binary Tree where each node has following structure, write a function to populate next pointer for all nodes.

Read More »

Given an array of integers where each element represents the max number of steps that can be made forward from that element. Write a function to return the minimum number of jumps to reach the end of the array (starting from the first element).

Read More »

Write a function to count number of smaller elements on right of each element in an array.

Read More »

Difficulty Level: Rookie Given a stream of numbers, print average (or mean) of the stream at every point. For example, let us consider the stream as 10, 20, 30, 40, 50, 60, … Average of 1 numbers is 10.00 Average of 2 numbers is 15.00 Average of 3 numbers is 20.00 Average of 4 numbers [...]

Read More »

Given a sorted array. Write a function that creates a Balanced Binary Search Tree using array elements.

Read More »