Topological Sort [Hackerearth]

A Topological sort of a Directed-Acyclic graph G is a linear ordering of all its vertices such that if G contains an edge E (u, v), then u appears before v in the ordering. And if the graph is not acyclic, then no linear ordering is possible.

How to find if two Binary trees are mirror images?

Mirror images mean right and left child of the two trees are interchanged. Thus, left child of first tree is right child of second tree. Traverse the Tree 1 and Tree 2 in Inorder fashion and store the node values of each Tree 1 & Tree 2 in two different arrays.

Which sorting algorithm makes minimum number of swaps?

Sorting means arranging a set of data in an order. There’re various algorithms to sort the data (in a data structure) in increasing or decreasing order. These algorithms can be divided on basis of various factors. Inplace sorting means that all the data which is to be sorted can be accommodated at a time in memory. Examples of inplace sorting algorithms are Selection sort, Bubble sort etc.

Segment Tree (Update) for Range Min Query and Range Sum Query

Update query (Range min query) For update query, we are given an index which needs to be updated. Let val be the value needed to be changed of a given node x. We start from the root of the segment tree and update all nodes (containing minimum value from given index) which have given index in their range. If a node doesn’t have a given index in its range, we don’t make any changes to that node.