Skip to content

Instantly share code, notes, and snippets.

View unnisworld's full-sized avatar

Unnikrishnan unnisworld

View GitHub Profile
@unnisworld
unnisworld / gist:6239262
Last active December 21, 2015 02:59
Java code to print permutation of a String. Impl is based on logic described here - http://www.ardendertat.com/2011/10/28/programming-interview-questions-11-all-permutations-of-string/
import java.util.List;
import java.util.ArrayList;
public class Test {
public static void main(String []args)
{
List<String> output = permut("ABC");
System.out.println("===== Output =====");
@unnisworld
unnisworld / QuickSort.java
Last active March 14, 2019 18:08
Implementation of Quick sort using strategy explained by Dr. Rob Edwards from San Diego State University - https://www.youtube.com/watch?v=ZHVk2blR45Q . A good asymptotic analysis of quick sort can be found here https://www.youtube.com/watch?v=-qOVVRIZzao
import java.util.Arrays;
public class QuickSort
{
static int partitionCounter = 0;
public static void main(String[] args)
{
// Test cases
// 1. Unsorted array with event no. of elements
public class LinkedList<T> {
private Node<T> head;
// Having a tail will help in making append O(1).
private Node<T> tail;
/**
* Appends a value to the end of the list.
*
public class LinkedList {
private Node head;
public static void main(String[] args) {
LinkedList ll = new LinkedList();
ll.add(1);
ll.add(2);
ll.add(3);
ll.add(4);
// https://www.geeksforgeeks.org/inorder-successor-in-binary-search-tree/
public class BSTInorderSuccessor {
public static void main(String[] args) {
BinarySearchTree tree = new BinarySearchTree();
Node n20 = new Node(20);
tree.insert(n20);
Node n8 = new Node(8);
tree.insert(n8);
object HelloWorld {
def main(args: Array[String]) {
println("Hello Scala!")
// Writing scala applications
// The entry point of a scala application is a main method with
// this signature - def main(args: Array[String])
// The declaration "object HelloWorld" is a way to create Signleton objects
// in scala. You will learn more about that later.
@unnisworld
unnisworld / GraphDFS
Last active December 19, 2018 07:01
DFS of an Adjacency Matrix Graph
// The Graph used in example :
//
// (A)
// |
// (B) - (H)
// | |
// (C) - (E) - (G)
// | |
// (D) (F)
//
@unnisworld
unnisworld / AdjacencyListGraphDFS
Last active April 1, 2019 10:38
Graph - DFS of Adjacency List representation
// The Graph used in example :
//
// (A)
// |
// (B) - (H)
// | |
// (C) - (E) - (G)
// | |
// (D) (F)
//
// Based on - https://www.baeldung.com/java-dijkstra
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
public class DijkstrasAlgorithm {
import java.util.Arrays;
public class QuickSort {
public static void main(String[] args) {
int arr[] = {11,12,13,14,15,16,17,10};
sort(arr, 0, arr.length-1);
System.out.println("Sorted Array :"+ Arrays.toString(arr));