
分治递推关系
外太空の神
这个作者很懒,什么都没留下…
展开
-
算法-计算逆序对个数
求逆序对的个数特点:利用归并排序中合并的步骤,计算逆序对int merge_inversion(int *arr,int start,int end,int middle);int count_inversion(int *arr,int start,int end){ if(start<end) { int middle = (start + end)/2; int left = count_inversion(arr,start,middle原创 2021-06-19 23:40:57 · 426 阅读 · 0 评论 -
算法-二分查找
二分查找特点:T(n) = T(n/2 - 1) + c时间复杂度O(lgn)前提:需要已排序的集合int binary_search(int *arr,int start,int end,int key){ if(start<end) { int middle = (start+end)/2; if(arr[middle] == key) return middle; if(key<arr[middle-1])原创 2021-06-19 18:01:19 · 183 阅读 · 0 评论 -
算法-二分搜索-找出最大值和次大值
二分搜索<2>找出最大值和第二大值,时间复杂度O(n)class Program { static void Main(string[] args) { List<int> list = new List<int> { 10, 3, 6, 4, 7, 1, 9, 2 }; var v = getMax(list, 0, list.Count - 1); }原创 2021-06-15 17:44:05 · 359 阅读 · 0 评论 -
算法-二分搜索-找出最大值和最小值
二分搜索问题找出最大值和最小值 时间复杂度O(n)using System;using System.Collections.Generic;namespace dataLearn{ class Program { static void Main(string[] args) { List<int> list = new List<int> { 10, 3, 6, 4, 7, 1, 9, 2 };原创 2021-06-15 17:38:06 · 756 阅读 · 0 评论 -
算法-排序-归并排序
归并排序特点:非原址排序,比较排序,时间复杂度O(nlogn)//// Created by 许加权 on 2021/6/18.//#include <iostream>void merge_sort(int *arr,int start,int end){ if(start != end) { int middle = (start + end)/2; merge_sort(arr,start,middle); m原创 2021-06-18 22:44:24 · 100 阅读 · 0 评论 -
算法-找出最近点对问题
using System;using System.Collections.Generic;namespace dataLearn{struct Coordinate{public float x;public float y;public Coordinate(float x,float y){this.x = x;this.y = y;}public override string ToString(){return $“x:{x},y:{y}”;}public voi原创 2021-06-15 17:26:25 · 219 阅读 · 0 评论 -
算法-连续项的最大和问题(最大子数组问题)三种不同解法
连续项的最大和问题using System;using System.Collections.Generic;namespace dataLearn{ class Program { static void Main(string[] args) { List<int> list1 = new List<int> { -2, 4, -1, 3, 5, -6, 1, 2 }; Li原创 2021-06-15 21:43:24 · 167 阅读 · 0 评论