算法和数据结构
鲲鹏飞九万里
过好每一天,就是过好这一生。
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
算法:散列表(HASH TABLES)
散列表(HASH TABLES)文章目录散列表(HASH TABLES)概要一、哈希查询算法由两部分组成1.1 一个哈希函数(a hash function)1.2 冲突解决过程(a collision-resolution process)二、哈希函数(Hash functions)2.1 模哈希(modular hashing)2.2 对于字符串2.3 Java惯例:`hashCode()`...原创 2020-02-07 17:02:05 · 413 阅读 · 0 评论 -
基于二分查询树(BinarySearchTrees)实现的键值对表(symbole-table)
概述 二叉树BSTs很容易实现,并且如果BSTs的键插入的顺序非常接近随机模型,那么BSTs能够提供快速搜索和插入。 很多程序开发者选用BSTs来实现symbol-table(键值对表),因为这样的实现支持快速的rank(查询第几位的值),select、delete、和范围查询操作。 但是,最坏的情况下,使用二叉树,其性能仍然是不能让人忍受的。基于二叉树的实现,好的...原创 2019-10-18 07:56:52 · 393 阅读 · 0 评论 -
包(Bag)、队列(Queue)、堆栈(Stack)的实现
本文记录用Java来实现包(Bag)、队列(Queue)、堆栈(Stack)一、包(Bag)特点: 只进不出package com.hef.algorithms.fundamentals.bags_queues_stacks;import java.util.Iterator;/** * FILO first in last out * @param <Item...原创 2019-09-08 17:42:28 · 430 阅读 · 0 评论 -
(二叉树)堆排序:HeapSort
读英文版的《Algorithms》确实有挑战,当读明白了的时候真是痛快。下面将自己对HeapSort的理解过程记录下来。 (为了简洁,使用术语“heap”代表“binary heap”)定义: 二叉树堆(a binary heap) 是一组键的集合,按堆顺序排列在一个完整的二进制树中,按数组的级别顺序表示(不使用第一个条目)。一、理解用数组表示的二叉树数组表示的二叉树有两个非常简单、重要...原创 2019-08-17 12:15:11 · 265 阅读 · 0 评论 -
树结构:一个在任何算法中用于描述比较的数据工具
树的一些特性树必须至少有N! 个叶子,因为有N!个排列组合;N! = N * (N-1) *(N-2)…*1在树中,一个从根到叶子的路径中,内部的节点数量是比较的次数,我们最感兴趣的是树中最长的路径,因为这个路径代表着最坏情况下的排序情况,我们称这个最长的路径为“树的高度(tree height)”;对于二叉树,这儿有个基本的属性:一个高为h的树,拥有不超过2h个叶子;一个高为h的二叉树...原创 2019-07-07 08:46:56 · 162 阅读 · 0 评论 -
算法研究的步骤
算法研究的步骤1. 决定一个完整和具体问题陈述,包括确定问题和API固有的基本抽象操作;Decide on a complete and specific problem statement, including identifying fundamental abstract operations that are intrinsic to the problem and an API....翻译 2019-06-10 07:13:10 · 3818 阅读 · 1 评论 -
基础算法:排序算法
典型的排序算法有:选择排序(selection sort)、插入排序(insertion sort)、希尔排序(shellsort)、合并排序(mergesort)、快速排序(quicksort)、堆排序(heapsort)。选择哪种排序算法,要考虑三个条件: 是否依赖输入值(input values)、是否需要额外空间(extra memory)、对于相等键如何处理。基础概念:An...原创 2019-06-19 07:11:10 · 448 阅读 · 0 评论 -
1.1.35 Dice simulation 筛子模拟
该题目来源于Robert Sedgewick 的《算法》。1.1.37 Dice simulation. The following code computes the exact probability distribution for the sum of two dice: int SIDES = 6; double[] d...原创 2019-01-26 08:40:03 · 586 阅读 · 0 评论 -
1.1.32 Histogram 直方图
该题目来源于Robert Sedgewick 的《算法》。1.1.32 Histogram. Suppose that the standard input stream is a sequence of double values. Write a program that takes an integer N and two double values l and r from ...原创 2019-01-20 09:34:33 · 470 阅读 · 0 评论 -
1.1.31 Random connection. 随机连接
该题目来源于Robert Sedgewick 的《算法》。1.1.31 Random connections. Write a program that takes as command-line arguments an integer N and a double value p (between 0 and 1), plots N equally spaced dots of ...原创 2019-01-19 10:38:36 · 377 阅读 · 0 评论 -
二项分布(1.1.27 Binomial distribution)的递归算法,基于数组进行改进
在Robert Sedgewick的《算法》(Algorithms)书中,有这么一道习题:1.1.27 Binomial distribution. Estimate the number of recursive calls that would be used by the codepublic static double binomial(int N, int k, dou...原创 2019-01-12 10:38:52 · 947 阅读 · 0 评论
分享