Skip to content

Instantly share code, notes, and snippets.

View hkaya15's full-sized avatar

Hüseyin Kaya hkaya15

View GitHub Profile
package main
import "testing"
func Benchmark_tabulation_stairs(b *testing.B) {
n := 1000
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
// Tabulation
func tabulation_getminstairs(n int) int {
table := make([]int, n+1)
for i := 2; i <= n; i++ {
if (i%2 == 0) && i%3 != 0 {
table[i] = 1 + int(math.Min(float64(table[i-1]), float64(table[i/2])))
} else if (i%3 == 0) && i%2 != 0 {
table[i] = 1 + int(math.Min(float64(table[i-1]), float64(table[i/3])))
package main
import "testing"
func Benchmark_tabulation_knapsack(b *testing.B) {
capacity := 50
value := []int{60, 100, 120}
weight := []int{10, 20, 30}
n := 3
// Tabulation
func tabulation_knapsack(weight, value []int, capacity, n int) int {
table := make([][]int, n+1)
for i := 0; i <= n; i++ {
table[i] = make([]int, capacity+1)
}
for i := 0; i <= n; i++ {
for j := 0; j <= capacity; j++ {
package main
import (
"testing"
)
func Benchmark_fibonacci(b *testing.B) {
b.ReportAllocs()
for i:=0; i<b.N;i++{
// Recursion
func fibonacci(n int) int {
if n <= 2 {
return 1
}
return fibonacci(n-1) + fibonacci(n-2)
}
// Slice Append - Dynamic
func fibDynamic(n int) int {