algorithm

command module
v0.0.0-...-a52c104 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 8, 2021 License: Apache-2.0 Imports: 1 Imported by: 0

README

Algorithm

介绍

golang 算法题目

写算法, 说实话golang用来写算法不是很好, 同样也是同样好的; leetcodeN: 可以直接查找leetcode上面的相关算法题目

其中也有一些测试数据 大量的测试用例使用leetcode 进行标准测试;

学习 使用 一种脚本语言来构建整体的环境问题; 如果使用了一个完整的机器, 这样就不需要每个机器每个机器的一个一个的安装环境了;

软件架构

软件架构说明

Basic Algorithms, sort
  1. Insertion Sort
  2. Bubble Sort
  3. Merge Sort
  4. Fast Sort
  5. Heap Sort
使用二分查找注意的问题
  1. 数量划分:

如果总数 t=5
t/2 划分左边的 2+3 {0,1} {2, 3, 4}

(t+1)/2 划分 3+2 {0,1, 2} {3, 4}

  1. 索引划分:

总数 t=5 {0,1,2, 3, 4} 表示区间[0, 4] 通常使用 mid := left + (right - left)/2 都是2分法; 这个其实就是向上取整; mid = 2;
mid := left + (right - left + 1)/2 mid = 2;

看看哪些死循环了

所有的区间都是 [] 左右均 闭区间

二分针对是奇数情况; 个数为例; arr[5] (right - left) >> 1 标识向下取整; 5/2 = 2 分成两份 2 + 3 长度和索引差一; 这样划分{0, 1} {2,3,4}

(right - left + 1) >> 1 标识向上取整; 6/2=3, 3 + 2 {0, 1, 2} {3, 4}

上面对于偶数来说 结果都是一样的; arr[4] 都是平分2+2

还有一种情况 使用向下取整会出现 死循环的情况; left + 1 = right;

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL