Posts

Showing posts from May, 2018

Merge Sort

Image
Merge Sort in C In  computer science ,  merge sort  (also commonly spelled  mergesort ) is an efficient, general-purpose,  comparison-based   sorting algorithm . Most implementations produce a  stable sort , which means that the implementation preserves the input order of  equal  elements in the sorted output. Mergesort is a  divide and conquer algorithm  that was invented by  John von Neumann  in 1945. Algorithm Conceptually, a merge sort works as follows: Divide the unsorted list into  n  sublists, each containing 1 element (a list of 1 element is considered sorted). Repeatedly merge sublists to produce new sorted sublists until there is only 1 sublist remaining. This will be the sorted list.

DFS(Depth First Search) & BFS(Breath First Search) in C

Image
DFS v/s BFS Depth First Search Depth First 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. Pseudocode: Input : A graph  G  and a vertex  v  of G Output : All vertices reachable from  v  labeled as discovered A recursive implementation of DFS:

Heap Sort

Heap Sort in C Heap-sort can be thought of as an improved selection sort:  like that algorithm, it divides its input into a sorted and an unsorted region, and it iteratively shrinks the unsorted region by extracting the largest element and moving that to the sorted region. The improvement consists of the use of a  heap  data structure rather than a linear-time search to find the maximum. The heapsort algorithm can be divided into two parts. In the first step, a heap is built out of the data. The heap is often placed in an array with the layout of a complete  binary tree . The complete binary tree maps the binary tree structure into the array indices; each array index represents a node; the index of the node's parent, left child branch, or right child branch are simple expressions. For a zero-based array, the root node is stored at index 0; if  i  is the index of the current node, then 

Currency Conversion(Rupees to Dollar And Vice-Versa)

Currency Converter Hi guys, today I had shared a code to convert the currency from rupees to dollar and vice-versa. Lets, check out the code.