随笔分类 - [41]Algorithm算法
-
JS实现图结构
摘要:JavaScript实现图结构 JavaScript实现图结构 一、图论 1.1.图的简介 什么是图? 图结构是一种与树结构有些相似的数据结构; 图论是数学的一个分支,并且,在数学中,树是图的一种; 图论以图为研究对象,研究顶点和边组成的图形的数学理论和方法; 主要的研究目的为:事物之间的联系,顶点 阅读全文
-
时间复杂度
摘要:时间复杂度到底怎么算 算法(Algorithm)是指用来操作数据、解决程序问题的一组方法。对于同一个问题,使用不同的算法,也许最终得到的结果是一样的,但在过程中消耗的资源和时间却会有很大的区别。 那么我们应该如何去衡量不同算法之间的优劣呢? 主要还是从算法所占用的「时间」和「空间」两个维度去考量。 阅读全文
-
算法时间复杂度
摘要:算法时间复杂度分析 算法时间复杂度分析 在看一个算法是否优秀时,我们一般都要考虑一个算法的时间复杂度和空间复杂度。现在随着空间越来越大,时间复杂度成了一个算法的重要指标,那么如何估计一个算法的时间复杂度呢? 时间复杂度直观体现 首先看一个时间复杂度不同的两个算法,解决同一个问题,会有多大的区别。下面 阅读全文
-
数学
摘要:人工智能、深度学习领域数学基础 偏导数、方向导数、梯度、微积分 一、偏导数 对于一元函数y=f(x)只存在y随x的变化,但是二元函数z=f(x,y)存在z随x变化的变化率,随y变化的变化率,随x﹑y同时变化的变化率。如下图所示 1、偏导数定义 设函数z=f(x,y)z=f(x,y)在点(x0,y0) 阅读全文
-
托马斯·贝叶斯 (Thomas Bayes)
摘要:朴素贝叶斯 Day15,开始学习朴素贝叶斯,先了解一下贝爷,以示敬意。 托马斯·贝叶斯 (Thomas Bayes),英国神学家、数学家、数理统计学家和哲学家,1702年出生于英国伦敦,做过神甫;1742年成为英国皇家学会会员;1763年4月7日逝世。贝叶斯曾是对概率论与统计的早期发展有重大影响的两 阅读全文
-
动态规划算法(Dynamic Programming,简称 DP)
摘要:动态规划算法(Dynamic Programming,简称 DP) 浅谈动态规划 动态规划算法(Dynamic Programming,简称 DP)似乎是一种很高深莫测的算法,你会在一些面试或算法书籍的高级技巧部分看到相关内容,什么状态转移方程,重叠子问题,最优子结构等高大上的词汇也可能让你望而却步 阅读全文
-
Trie字典树
摘要:关闭页面特效 1|0Trie字典树 Trie字典树又称前缀树,顾名思义,是查询前缀匹配的一种树形数据结构 可以分为插入(创建) 和 查询两部分。参考地址极客时间 下图为插入字符串的过程: 创建完成后,每个字符串最后一个字母标记为终结点(图中显示为红色) 下图为查询字符串:“her”的过程:绿色箭头表 阅读全文
-
数据结构与算法1
摘要:降维打击!为什么我认为数据结构与算法对前端开发很重要 > 事情要从 GitHub 上的一个 issue 谈起:https://github.com/LeuisKen/leuisken.github.io/issues/2,需求里面的我指代为 issue 里面的我。 从一个需求谈起 在我之前的项目中, 阅读全文
-
图的最小生成树
摘要:图的最小生成树 图的最小生成树 对于一张图,我们有一个定理:n个点用n-1条边连接,形成的图形只可能是树。我们可以这样理解:树的每一个结点都有一个唯一的父亲,也就是至少有n条边,但是根节点要除外,所以就是n-1条边。还有一种理解:树里不存在环,那么既要连接n个点又不能形成环,只能用n-1条边。 那么 阅读全文
-
时间复杂度
摘要:时间复杂度 我们常常在武侠小说中看到一位内力精深的高手在学习新的招式的时候修炼速度异常惊人,我心目中最经典的片段就是倚天屠龙记中张无忌学习乾坤大挪移和太极拳的时候了,他能在极短的时间内领会常人数十年所不能掌握的东西,即使拍了很多版本,每次看到这,我都大呼过瘾,仍然看的津津有味~ 数据结构和算法对于程 阅读全文
-
堆
摘要:何为堆? 堆是一种特殊的树,只要满足下面两个条件,它就是一个堆: (1)堆是一颗完全二叉树; (2)堆中某个节点的值总是不大于(或不小于)其父节点的值。 其中,我们把根节点最大的堆叫做大顶堆,根节点最小的堆叫做小顶堆。 堆详解 满二叉树 满二叉树是指所有层都达到最大节点数的二叉树。比如,下面这颗树: 阅读全文
-
算法就是设计
摘要:算法就是设计 插入排序的套路 坚持我之前的说法,学习算法设计关键是要学习算法套路。一些经典排序算法,很好的体现了一些重要的套路,值得想一想。本文介绍插入排序的算法套路,即重用与增量有序的思想。 先要注意,排序的结果一般都是升序的,也就是从小到大(与上图相反)。 插入排序的算法很好理解,形式上,跟排扑 阅读全文
-
对称密码体制和非对称密码体制
摘要:对称密码体制和非对称密码体制 一、对称加密 (Symmetric Key Encryption) 对称加密是最快速、最简单的一种加密方式,加密(encryption)与解密(decryption)用的是同样的密钥(secret key)。对称加密有很多种算法,由于它效率很高,所以被广泛使用在很多加密 阅读全文
-
调整数组顺序使奇数位于偶数前面
摘要:剑指offer:调整数组顺序使奇数位于偶数前面 题目 输入一个整数数组,实现一个函数来调整该数组中数字的顺序,使得所有奇数位于数组的前半部分,所有偶数位于数组的后半部分。 分析 事实上,这个题比较简单,很多种方式都可以实现,但是其时间复杂度或空间复杂度不尽相同。 解法一 书中作者提到一种初始的做法是 阅读全文
-
算法的时间和空间复杂度
摘要:算法的时间和空间复杂度 算法(Algorithm)是指用来操作数据、解决程序问题的一组方法。对于同一个问题,使用不同的算法,也许最终得到的结果是一样的,但在过程中消耗的资源和时间却会有很大的区别。 那么我们应该如何去衡量不同算法之间的优劣呢? 主要还是从算法所占用的「时间」和「空间」两个维度去考量。 阅读全文
-
数据结构
摘要:准备下次编程面试前你应该知道的数据结构 国外 IT 教育学院 Educative.io 创始人 Fahim ul Haq 写过一篇过万赞的文章《The top data structures you should know for your next coding interview》,总结了程序员 阅读全文
-
一致性哈希算法(Consistent Hashing Algorithm)
摘要:一致性哈希算法(Consistent Hashing Algorithm) 浅谈一致性Hash原理及应用 在讲一致性Hash之前我们先来讨论一个问题。 问题:现在有亿级用户,每日产生千万级订单,如何将订单进行分片分表? 小A:我们可以按照手机号的尾数进行分片,同一个尾数的手机号写入同一片/同一表中。 阅读全文
-
位操作Bit Operation算法题
摘要:一道让你拍案叫绝的算法题 这是一道看完答案会觉得很简单,但做之前很难想到答案的题目!!! 不信? Let us go ! 题目描述 给定一个非空整数数组,除了某个元素只出现一次以外,其余每个元素均出现两次。找出那个只出现了一次的元素。 说明: 你的算法应该具有线性时间复杂度。 你可以不使用额外空间来 阅读全文
-
布隆过滤---判断一个元素在亿级数据中是否存在
摘要:如何判断一个元素在亿级数据中是否存在? https://www.cnblogs.com/crossoverJie/p/10018231.html 前言 最近有朋友问我这么一个面试题目: 现在有一个非常庞大的数据,假设全是 int 类型。现在我给你一个数,你需要告诉我它是否存在其中(尽量高效)。 需求 阅读全文
-
Viterbi算法和隐马尔可夫模型(HMM)算法
摘要:隐马尔可夫模型(HMM)及Viterbi算法 https://www.cnblogs.com/jclian91/p/9954878.html HMM简介 对于算法爱好者来说,隐马尔可夫模型的大名那是如雷贯耳。那么,这个模型到底长什么样?具体的原理又是什么呢?有什么具体的应用场景呢?本文将会解答这些疑 阅读全文