Skip to content

Instantly share code, notes, and snippets.

View shafiqshams's full-sized avatar
😇
Its ok to fail, everyone fails, failure is not opposite of success, its a part.

Shafiq Shams shafiqshams

😇
Its ok to fail, everyone fails, failure is not opposite of success, its a part.
View GitHub Profile
@shafiqshams
shafiqshams / AlbumList.js
Created April 11, 2017 08:36
BoilerPlate for functional ReactNative component.
import React from 'react';
import { Text, View } from 'react-native';
const AlbumList = () => (
<View>
<Text> AlbumList </Text>
</View>
);
export default AlbumList;
@shafiqshams
shafiqshams / HeapSort.txt
Created February 22, 2017 09:59
HeapSort The algorithm runs in two steps. Given an array of data, first, we build a heap and then turn it into a sorted list by calling deleteMin. The running time of the algorithm is O(n log n). Example. Given an array {3, 1, 6, 5, 2, 4}.
1. build a heap 1, 2, 4, 5, 3, 6
2. turn this heap into a sorted list
deleteMin
1, 2, 4, 5, 3, 6 swap 1 and 6
6, 2, 4, 5, 3, 1 restore heap
2, 6, 4, 5, 3, 1
2, 3, 4, 5, 6, 1
deleteMin
@shafiqshams
shafiqshams / InsertionMinHeap.Java
Created February 21, 2017 09:46
Insert The new element is initially appended to the end of the heap (as the last element of the array). The heap property is repaired by comparing the added element with its parent and moving the added element up a level (swapping positions with the parent). This process is called "percolation up". The comparison is repeated until the parent is …
//The following code example demonstrates the algorithm
public void insert(Comparable x)
{
if(size == heap.length - 1) doubleSize();
//Insert a new item to the end of the array
int pos = ++size;
//Percolate up
public class minHeap {
public int size;
public int [] mH;
public int position;
public minHeap(int size){
this.size=size;
mH = new int [size+1];
position = 0;
}
public void createHeap(int [] arrA){
/* Deleting a node from Binary search tree */
#include<iostream>
using namespace std;
struct Node {
int data;
struct Node *left;
struct Node *right;
};
//Function to find minimum in a tree.
Node* FindMin(Node* root)