![](https://img-blog.csdnimg.cn/20201014180756738.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
数据结构与算法
rodman177
这个作者很懒,什么都没留下…
展开
-
创建堆以及实现堆排序
什么是堆???可以把堆看成是一颗完全二叉树,并且这颗完全二叉树有一个特点:根节点比其左右叶子结点的值都大或者都小。如果每一个根节点比其左右叶子节点的值都大,则称之为大顶堆,反之就称为小顶堆。这一规则必须在完全二叉树的任一子树都满足。完全二叉树的特点:设根节点的索引值为index;(1)左节点的索引值为 2indexe +1;(2)右节点的索引值为 2index+2;(3)其父节点的值为(...原创 2019-04-27 10:23:35 · 465 阅读 · 0 评论 -
剑指offer:把二叉树打印成多行
题目:把二叉树打印成多行,即每一层打印为一行代码如下://非递归public ArrayList<ArrayList<Integer>> printLevel(TreeNode root){ if(root == null) return null; ArrayList<ArrayList<Integer>> arrs =...原创 2019-05-01 22:42:53 · 149 阅读 · 0 评论 -
8中排序算法及其优化:采用Java语言描述
1、 冒泡排序及其优化核心思想: 通过每一轮的比较,把较大的数字放在末尾,每一轮比较完之后,下一轮的比较的次数为该数组的长度减去循环次数再减一。举例: 有以下数组 5 4 6 7 1 9 8第一次循环:第一趟比较:4 5 6 7 1 8 9第二趟比较:4 5 6 1 7 8 9第三趟比较:4 5 1 6 7 8 9第四、五、六趟比较结果与第三趟一样第二次循环:第一趟比较:4 1...原创 2019-04-27 19:49:37 · 174 阅读 · 0 评论 -
赫夫曼树的构建
赫夫曼树:带权路径最小的二叉树public class HuffmanTree{ publlic class Node implements Comparable<Node > { int weight; Node left = null; Node right = null; pu...原创 2019-05-02 16:26:32 · 438 阅读 · 0 评论 -
二叉排序树(二叉查找树、二叉搜索树)
什么是二叉查找树:根节点的值大于其左子树中任意一个节点的值,小于其右节点中任意一节点的值,这一规则适用于二叉查找树中的每一个节点。本文章重点来讨论一下关于二叉查找树删除节点的问题。有一下二叉查找树,如图:在删除节点的时候我们只需考虑一下三种情况:(1)要删除的节点是叶子结点,如图:(2)要删除的节点有左节点但是没有右节点,或者有右节点但是没有左节点,如图:(3)要删除的节点既有...原创 2019-05-03 00:16:08 · 108905 阅读 · 14 评论 -
Longest Substring Without Repeating Characters(无重复最长子串)
Given a string, find the length of the longest substring without repeating characters.Example 1:Input: “abcabcbb”Output: 3Explanation: The answer is “abc”, with the length of 3.Example 2:Input: ...原创 2019-05-10 20:31:08 · 72 阅读 · 0 评论 -
Two Sum
Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you may not use the same e...原创 2019-05-10 20:54:32 · 94 阅读 · 0 评论 -
Longest Palindromic Substring(最长回文)
Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.Example 1:Input: “babad”Output: “bab”Note: “aba” is also a valid answer.Example ...原创 2019-05-11 11:06:13 · 89 阅读 · 0 评论 -
Zigzag Conversion
The string “PAYPALISHIRING” is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)P A H NA P L S I I G...原创 2019-05-11 23:55:54 · 70 阅读 · 0 评论