Skip to content

Instantly share code, notes, and snippets.

View rahulkushwaha12's full-sized avatar

Rahul Kushwaha rahulkushwaha12

View GitHub Profile
package main
func isCyclic(n int, adj [][]int) bool {
vis := make([]bool, n)
var dp = make([]bool, n) //true when all path traversed and with no loop i.e. memoization for no cycles starting this index
for i := 0; i < n; i++ {
if dp[i] {
continue
}
@rahulkushwaha12
rahulkushwaha12 / selection_sort.go
Created January 21, 2020 04:33
Selection sort in go
package main
import (
"fmt"
)
/*
5
25, 17, 31, 13, 2
@rahulkushwaha12
rahulkushwaha12 / bubble_sort.go
Created January 21, 2020 04:27
Bubble sort in go
package main
import (
"fmt"
)
/*
5
25, 17, 31, 13, 2
@rahulkushwaha12
rahulkushwaha12 / quick_sort.go
Created January 20, 2020 17:41
Quick sort in go
package main
import (
"fmt"
)
/*
5
25, 17, 31, 13, 2
sorted array [2 13 17 25 31]
@rahulkushwaha12
rahulkushwaha12 / merge_sort.go
Created January 20, 2020 17:40
Merge sort in go
package main
import (
"fmt"
)
/*
5
25, 17, 31, 13, 2
@rahulkushwaha12
rahulkushwaha12 / insertion_sort.go
Created January 20, 2020 17:37
Insertion Sort in go
package main
import (
"fmt"
)
/*
5
25, 17, 31, 13, 2
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "echo",
"type": "shell",
"command": "g++",
"args": [