Giter Site home page Giter Site logo

ua-nick / data-structures-and-algorithms Goto Github PK

View Code? Open in Web Editor NEW
2.7K 76.0 344.0 44 KB

Data Structures and Algorithms implementation in Go

License: MIT License

Go 100.00%
datastructures algorithms algorithms-datastructures algorithms-and-data-structures golang go algorithm data-structures

data-structures-and-algorithms's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

data-structures-and-algorithms's Issues

func RemoveByValue in doublylinkedlist.go may have one problem

the block as below

current := list.head
	for current.next != nil {
		if current.next.data == i {
			if current.next.next != nil {
				current.next.next.prev = current
			}
			current.next = current.next.next
			return true
		}
		current = current.next
	}

there should no current.next.next==nil condition, if current.next.next==nil, then current.next will be the list.tail

Question on Exponential Search

Why do you add 1 to the boundValue here https://github.com/floyernick/Data-Structures-and-Algorithms/blob/master/ExponentialSearch/ExponentialSearch.go#L11 in the exponential search algorithm?

After trying a test case where I search for an element that is not in the data slice I get an error panic: runtime error: index out of range. I'm not sure why a +1 was added but when I remove it the problem goes away.

All of my code:

package main

import "fmt"

func exponential_search(data []int, key int) int {
  bound_value := 1
  for bound_value < len(data) && data[bound_value] < key {
    bound_value *= 2
  }
  if bound_value > len(data) {
    bound_value = len(data) - 1
  }
  return binary_search(data, bound_value, key)
}

func binary_search(data []int, bound int, key int) int {
  min := 0
  max := bound

  for min <= max {
    mid := int((max + min) / 2)
    if data[mid] == key {
      return mid
    } else if data[mid] < key {
      min = mid + 1
    } else if data[mid] > key {
      max = mid - 1
    }
  }
  return -1
}

func main() {
  data1 := []int{0,1,2,3,4,5,6,7,8,9}
  data2 := []int{}

  keys := []int{0,4,9,11,2,3,8,-1}

  for _, key := range keys {
    fmt.Println("Searching for", key)
    if index := exponential_search(data1, key); index != -1 {
      fmt.Println("Position:", index, "data:", data1[index])
    } else {
      fmt.Println("Key", key, "not found")
    }
  }
  // Search for an element in an empty slice.
  fmt.Println("Position:", exponential_search(data2, 11))
}

Output:

Searching for 0
Position: 0 data: 0
Searching for 4
Position: 4 data: 4
Searching for 9
Position: 9 data: 9
Searching for 11
Key 11 not found
Searching for 2
Position: 2 data: 2
Searching for 3
Position: 3 data: 3
Searching for 8
Position: 8 data: 8
Searching for -1
Key -1 not found
Position: -1

func RemoveByIndex in DoublyLinkedList.go has a problem

the block below has a problem that the previous head can still be referred to

if i == 0 {
	list.head.prev = nil
	list.head = list.head.next
	return true
}

it should be like this

if i == 0 {
	list.head = list.head.next
        list.head.prev = nil
	return true
}

Items in README.md should be linked

Data Structures and Algorithms

Go Report Card Build Status License

Clean and simple implementation in Go

Implementation

There are several data structures and algorithms implemented in this project. The list will be replenished with time.

Data structures

Some Changes for MergeSort

#18
It Make MergeSort faster than before and I Commit a pull request.
————————————————————————————————————
Benchmark_MergeSort_new
Benchmark_MergeSort_new-12 10 101394033 ns/op 209956300 B/op 1000041 allocs/op
Benchmark_MergeSort_new-12 10 103156080 ns/op 209956320 B/op 1000041 allocs/op
Benchmark_MergeSort_new-12 10 105631558 ns/op 209956272 B/op 1000041 allocs/op
Benchmark_MergeSort_old
Benchmark_MergeSort_old-12 4 322263281 ns/op 582174710 B/op 4052123 allocs/op
Benchmark_MergeSort_old-12 3 333629871 ns/op 582175192 B/op 4052124 allocs/op
Benchmark_MergeSort_old-12 3 350259903 ns/op 582174706 B/op 4052122 allocs/op

Make repo go get-able by adding a .go file to top folder level

You need to make the top level of the repo a Go package in order to make it go get-able. Otherwise, it returns an error:

package github.com/floyernick/Data-Structures-and-Algorithms: no Go files in /Users/philip/src/github.com/floyernick/Data-Structures-and-Algorithms

It can as simple as a package declaration and it will work, i.e. in new file dsa.go at the top level of the package, just have a single line of package dsa and you're good to go.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.