摘要: 这道题又是一道回溯算法的问题。关于回溯算法,并不是特别擅长,这道题真的是不错的练手题目。可以通过这道题更加深刻的理解下回溯算法是怎么回事。这道题一开始有几个疑惑的地方,就是回溯的时候怎么处理有的点进行了多次递归的问题。答案之中用了一个动态数组就轻松解决了这个问题。这道题可以用四个函数来解决这个问题。... 阅读全文
posted @ 2015-02-25 22:12 程序员小王 阅读(1269) 评论(0) 推荐(0) 编辑
摘要: 这一章主要讨论整数的排序。 7.2 插入排序 插入算法是学习排序的最基本的算法。非常简单好理解的算法,大意是,位置X上面的元素前面的元素都是排过序的。当这个元素需要排序时,在前面之中,为X上面的元素找到一个合适的位置。 void InsertionSort(int* a, int n) { int i, j; int temp;//用于替... 阅读全文
posted @ 2015-02-22 14:19 程序员小王 阅读(280) 评论(0) 推荐(0) 编辑
摘要: 这一章要讲的数据结构基本以实用为主。 12.1 自顶而下的伸展树 一些定义 展开:对于树的操作,叶结点X被插入之后,经过旋转使X成为新的树根。 摊还时间:在摊还分析中的一个概念,就是求一个操作的所有情况的平均时间。和O()的时间不同,后者体现的是最糟糕的情况下程序完成所要花费的时间。 P345之中,还有一些内容不是很明白,比如图12.1之中,为什么旋转之后树之间是断开的。我不是很清楚这是... 阅读全文
posted @ 2015-02-21 14:55 程序员小王 阅读(149) 评论(0) 推荐(0) 编辑
摘要: 中序遍历(左中右)普通树有两种遍历方式: 深度优先遍历。 先根遍历 –> 二叉树中的先序遍历(中左右) 后根遍历 –> 二叉树中的后序遍历(左右中) 作为树的特例,二叉树还有一种特殊的遍历方式:中序遍历(左中右) 宽度优先遍历。 二叉树的三种遍历方式: 先序遍历(中左右) 中序遍历(左中右) 后序遍历(左右中) 阅读全文
posted @ 2015-02-10 11:43 程序员小王 阅读(637) 评论(0) 推荐(0) 编辑
摘要: 题目:There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). 题目分析: 题目中没有说清楚的一点是,假如中间的数... 阅读全文
posted @ 2015-02-10 11:06 程序员小王 阅读(103) 评论(0) 推荐(0) 编辑
摘要: 概念题 定义一个空的类,里面没有任何成员变量和成员函数。对该类型求sizeof,会得到的结果是1。因为虽然没有成员变量和成员函数,没有有用信息,但是声明实例的时候,它必须在内存之中占用一定的空间,空间的大小由编译器决定,Visual Studio其分配空间为1。哪怕类内定义了构造函数和析构函数,这个结果仍然不会改变,仍然会是1。因为在实例需要初始化或者析构的时候,只需要调用这两个函数,即取... 阅读全文
posted @ 2015-01-22 20:12 程序员小王 阅读(123) 评论(0) 推荐(0) 编辑
摘要: Divide Two Integers Total Accepted: 26724 Total Submissions: 167045My Submissions Question Solution Divide two integers without using multiplication, division and mod operator. If it is overflow, ... 阅读全文
posted @ 2015-01-19 12:23 程序员小王 阅读(151) 评论(0) 推荐(0) 编辑
摘要: Given a non-negative number represented as an array of digits, plus one to the number. The digits are stored such that the most significant digit is at the head of the list 这道题的题目意思花了好长时间才能明白。明白了... 阅读全文
posted @ 2015-01-13 09:19 程序员小王 阅读(127) 评论(0) 推荐(0) 编辑
摘要: Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \ 3 4 4 3 But the following is ... 阅读全文
posted @ 2015-01-12 21:27 程序员小王 阅读(144) 评论(0) 推荐(0) 编辑
摘要: Write a program to find the node at which the intersection of two singly linked lists begins. For example, the following two linked lists: A: a1 → a2 ↘ ... 阅读全文
posted @ 2015-01-07 21:20 程序员小王 阅读(126) 评论(0) 推荐(0) 编辑