算法
文章平均质量分 84
algorithm
mitre
夜尽天明...
展开
-
动态规划(Dynamic Programming)
Dynamic programming, like the divide-and-conquer method, solves problems bycombining the solutions to subproblems. (“Programming” in this context refersto a tabular method, not to writing computer code.)动态规划 和 分治法 相似, 都是通过 组合子问题的解 来 求解原问题. (“programing”原创 2021-09-15 01:04:23 · 93 阅读 · 0 评论 -
算法基础-快速排序
与 归并排序 一样, 快速排序 也使用了 分治思想(divide-and-conquer paradigm).对于包含n个元素的数组来说, 快速排序是一种 最坏情况时间复杂度 O(n2), 平均时间复杂度 O(n*lgn).1 快速排序描述下面是对一个子数组 A[p..r] 进行快速排序的分治过程:分解: 数组 A[p..r] 被划分为两个(可能为空)子数组 A[p..q-1] 和 A[q+1..r] , 使得 A[p..q-1] 中的每一个元素都小于等于 A[q] , 而 A[q] 也小于等于 A原创 2021-09-14 00:56:11 · 218 阅读 · 0 评论 -
算法基础-堆排序
堆排序(heapsort) 和 归并排序 一样, 它的时间复杂度也是 O(nlgn).回忆一下, 归并排序 使用的 算法设计方法: 分治法.而 堆排序 使用另一种算法设计技术: 使用 堆(heap) 的数据结构进行信息管理.虽然 堆 这一词源自 堆排序, 但是目前它已经被引申为 “垃圾收集存储机制”, 比如 Java 中内存模型的 堆 结构.1 堆在介绍堆之前, 需要了解 树 的基础知识. 若已了解, 直接看 1.2. 1.1 树的基础知识对于一棵有根树 T(根为r) 中的 结点x, x 的原创 2021-09-13 23:44:16 · 153 阅读 · 0 评论 -
算法基础-归并排序
在介绍 归并排序(merge sort) 算法之前, 我们先学习一下 分治法 .原创 2021-09-12 18:47:55 · 202 阅读 · 0 评论 -
算法基础-排序
很多计算机科学家认为 排序 是 算法研究中最基础的问题[1].如果输入数组中仅有 常数 个元素需要在排序过程中存储在数组之外, 则称排序算法是 原址的(in place).比较排序: 在排序的最终结果中, 各元素的次序依赖于它们之间的 比较.非比较排序(运算排序): 用 运算 而不是比较来确定排序顺序.下表总结了常见的比较算法:算法特性描述最坏情况运行时间平均情况运行时间冒泡排序原址, 比较O(n2)O(n2)梳排序原址, 比较O(n2)O(n2/2p)原创 2021-09-12 18:25:34 · 95 阅读 · 0 评论 -
算法导论12章-二叉搜索树(Binary Search Trees)
这是我的第一篇 算法导论(Introduction to Algorithms, Third Edition) 读书笔记. 旨在记录重点, 强化自己对算法的学习效果.这里不会像书本那样详细, 给出复杂的推理证明, 这里只是一点学习心得.我看到是 算法导论(中文版) 的书, 这里有原著(提取码:cz4v)(英文版PDF) 可以对照阅读.1 什么是二叉搜索树一棵 二叉搜索树(BST) 是以一棵 二叉树 来组织的.二叉搜索树 可以使用一个 链表数据结构(linked data structure ) 表原创 2021-09-12 00:44:50 · 747 阅读 · 0 评论 -
LeetCode95: Unique Binary Search Trees II
1 问题问题描述:Given an integer n, return all the structurally unique BST’s (binary search trees), which has exactly n nodes of unique values from 1 to n. Return the answer in any order.Example 1:Input: n = 3Output: [[1,null,2,null,3],[1,null,3,2],[2,1,3],原创 2021-09-11 12:08:06 · 144 阅读 · 0 评论 -
LeetCode96: Unique Binary Search Trees
1 问题问题描述:Given an integer n, return the number of structurally unique BST’s (binary search trees) which has exactly n nodes of unique values from 1 to n.Example 1:Input: n = 3Output: 5Example 2:Input: n = 1Output: 1Constraints:1 <= n <=原创 2021-09-04 20:53:01 · 133 阅读 · 0 评论 -
LeetCode234: Palindrome Linked List
1. 问题问题描述:Given the head of a singly linked list, return true if it is a palindrome.Example 1:Input: head = [1,2,2,1]Output: trueExample 2:Input: head = [1,2]Output: falseConstraints:The number of nodes in the list is in the range [1, 105].0原创 2021-09-02 23:56:01 · 132 阅读 · 0 评论 -
LeetCode970: Powerful Integers
1. 问题问题描述(原文):Given three integers x, y, and bound, return a list of all the powerful integers that have a value less than or equal to bound.An integer is powerful if it can be represented as xi + yj for some integers i >= 0 and j >= 0.You may re原创 2021-09-02 00:57:30 · 95 阅读 · 0 评论 -
LeetCode34: Find First and Last Position of Element in Sorted Array
1 问题问题描述(原文):Given an array of integers nums sorted in ascending order, find the starting and ending position of a given target value.If target is not found in the array, return [-1, -1].You must write an algorithm with O(log n) runtime complexity.Exa原创 2021-08-31 23:23:16 · 69 阅读 · 0 评论