Linear Search如果我们要查找数组中等于5的值,需要遍历数组。时间复杂度 $ O(N) $
Binary Serach二分查找,前提是集合有序。
123Low = 0High = n-1Mid = (Low + High)/2
首先找到中间值比较,如果大于当前值,就往低处找,否则往高处找。直道当前值等于中间值。时间复杂度:$ \log_2 N $
123456789101112...
Java JDK 时间线
Java SE 9 特性Possible Release Date : September 22, 2016
Proposed features are:
Support for multi-gigabyte heaps
Better native code integration
Self-tuning JVM
Java Module System
Money and Currency ...
Bit Manipulation
一些使用位操作提高性能的算法和技巧.
判断一个整数是2的幂常规的方法:O(logN)12345678910bool isPowerOfTwo(int x) { if(x == 0) return false; else { while(x % 2 == 0) x /= 2; ...
Java 8 多线程基础
Java Concurrency API 从Java 5开始引入,到现在做了很多改进。
Part 1: Threads and Executors现在操作系统通过进程和线程实现并发。进程拥有独立的资源,一个进程中可有创建多个线程,折线线程共享进程的资源。
Thread1234567891011Runnable task = () -> { String threadNa...
Java 8 奇淫异巧
字符串连接字符串12String.join(":", "foobar", "foo", "bar");// => foobar:foo:bar
使用正则表达式过滤12345Pattern pattern = Pattern.compile(".*@gmail\\.com");Stream.of("bob@gmail.com", "alice@hotmail.com") .filt...