Skip to content

Instantly share code, notes, and snippets.

View prasadwrites's full-sized avatar

Prasad prasadwrites

View GitHub Profile
@prasadwrites
prasadwrites / BBSort.java
Created November 23, 2014 00:01
Bubblesort algorithm in Java
public class BBSort
{
private void bubblesort(int [] arr)
{
int i = 1, temp;
boolean swapped = true;
while(swapped)
{
swapped = false;
for(int j=0; j < arr.length - i ; j++)
@prasadwrites
prasadwrites / QuickSortAlgo.java
Created November 23, 2014 06:36
Quicksort Algorithm in Java
public class QuickSortAlgo{
private void quicksort(int [] arr, int first, int last)
{
int left = first, pivot = first, right = last, temp;
if (first<last)
{
while(left<right)
{
def mergeSort(alist):
print("Splitting ",alist)
if len(alist)>1:
mid = len(alist)//2
lefthalf = alist[:mid]
righthalf = alist[mid:]
mergeSort(lefthalf)
mergeSort(righthalf)
@prasadwrites
prasadwrites / insertionsort.py
Last active August 29, 2015 14:10
InsertionSort in Python
def insertionsort(arr):
for i in range(1,len(arr)):
temp = arr[i]
k = i
while k>0 and temp < arr[k-1] :
arr[k] = arr[k-1]
k-=1
arr[k] = temp
@prasadwrites
prasadwrites / RotationMatrix90.py
Created November 30, 2014 23:40
Rotating a matrix by 90 degree
pixel = [ [0,1,2,3],
[10,11,12,13],
[20,21,22,23],
[30,31,32,33] ]
def rotateMatrix90(pixel):
pixel_temp = [[0]*4 for _ in range(4)]
print(pixel_temp)
@prasadwrites
prasadwrites / allcomb.py
Last active August 29, 2015 14:10
All combinations printing numbers
a = [ 2,2,3,4]
b = []
print(a)
temp = 1
length = len(a)
for k in range(1,length):
valk = k
for i in range(length):
for j in range(i+1,length):
temp = 1
@prasadwrites
prasadwrites / allcombchar.py
Last active August 29, 2015 14:10
All combination charachters
a = [ 'a','b','c','d']
b = []
length = len(a)
print(a)
print(length)
temp = 1
for k in range(1,length):
valk = k
for i in range(length):
for j in range(i+1,length):
@prasadwrites
prasadwrites / aligned_malloc.c
Created December 6, 2014 05:11
n byte aligned malloc implementation
/*
* nMalloc.cpp
*
* Created on: Dec 5, 2014
* Author: prasadnair
*/
#include <stdlib.h>
#include <stdio.h>
@prasadwrites
prasadwrites / combPowerSet.java
Last active August 29, 2015 14:10
Algoritim to print all combinations of array in order.
package combinations;
import java.util.*;
import java.math.*;
public class combPowerSet {
//printing the charachters as per the number sent.
void printNumber(int number, char [] items)
{
@prasadwrites
prasadwrites / Kadane.py
Last active August 15, 2023 23:46
Kadane's Algorithm for finding Maximum Subarrary
#! /usr/env/path python
class Solution:
##Complete this function
#Function to find the sum of contiguous subarray with maximum sum.
def maxSubArraySum(self,arr,N):
##Your code here
if (N < 1) or (N > 1000000):
print("error : invalid array size")