《Data Structure And Algorithm Analysis In C++》读书笔记一

本书旨在探讨程序对于大型输入的运行时间估算,比较不同程序的运行时间,以及提升确定瓶颈的程序速度。内容涵盖数学回顾,递归介绍,C++类和细节,模板使用以及矩阵应用。
摘要由CSDN通过智能技术生成

Chapter 1 Programming:A General Overview

1.1 What is This Book About?

Problem.

K-Selection Problem. Input a array and choose the k-th largest.

User Bubble-sort

#include <iostream>
#include <stdlib.h>


void swap(int array[], int i, int j) {
    if(i == j)
        return;
    int temp = array[j];
    array[j] = array[i];
    array[i] = temp;
}

void bubblesort(int array[], int nsize) {
    for (int i = 0; i < nsize; i++) {
        for(int j = 0; j < nsize - i - 1; j++) {
            if(array[j] > array[j + 1])
                swap(array, j, j + 1);
        }
    }
}

// Select the k-th largest number from a array.
int kthselection(int array[], int nsize, int k) {
    if(k > nsize)
        return -1;
    bubblesort(array, nsize);
    return array[nsize - k + 1];
}

int main(int argc, char ** argv) {
    
    int a[] = {5, 3, 2, 1, 9, 10, 7 ,6};
    int k = 0;
    std::cout << "Please the k-th largest from the array:\n";
    std::cin >> k;
    printf("The %d-th largest of the array is %d\n", k, 
        kthselection(a, _countof(a), k));
    return 0;
}

Optimized use BubbleSort for the first k-th

The algorithm related in the textbook is very complicated.(I think that we must use the link-list data structure)


A word puzzle find algorithm.


Find the word from horizontal, vertical, or diagonal directions.


The aim of this books :

To estimate the running time of a program for large inputs.

How to compare the running times of two programs without actually coding them.

To improve the speed of a program for a determing program bottlenecks.


1.2 Mathematics Review

1.2.1 Exponents



1.2.2 Logarithms



1.2.3 Series






A research about the second formula 

http://blog.csdn.net/acdreamers/article/details/38929067


The second formula means f(N) relative to const N。 just summation N times of the function f(N) thus the result is N * f(N)


1.2.4 Modular Arthmetic



the theorem1)could be proved by the basic arthematic theorem(universal factorization theorem the proof step refer the Notebook)

the theorem2)could be proved by the quotient-remainder theorem and the result of theorem1) and the property that if a|b then a<=b. the step refer the Notebook.

the theorem3 ) ?

1.2.5 The P Word (proof method)

1)Mathematica Induction







2)Proof by counterexample

3)Contradiction



(There is an issue in the proof above Because we still can‘t decude that N is a prime. The actual approach to refer the notebook for[ Discrete Mathematics with applicaton] chapter 3. Simple approach: To prove that N is divisible by some prime number called P ,but since p1~pk is all of the prime number ,them p must in p1~pk, but all all prime numbers from p1~pk can't disivile N. so we deducde that N is divisible by p and N is not divisible by p, which is a contradiction.)


1.3 A Brief Introduction to Recursion

A function that is defined in terms of itself is called recursive. (Using recursion for numerical calculations is usually a bad idea)

A C++ implementation for recursion function f(x) = 2(fx - 1) + x^2  (f(0) = 0)

int f(int x) {
    if (x == 0)
        return 0;
    else
        return 2 * f(x - 1) + x * x;
}

Is that the recursion just circular logic? 

f(5) by computing f(5)would be circular

f(5)by computing f(4) is not circular

Recursive calls will keep on being made until a base case is reached

f(-1)will cause a infinite loop and an undefined behavior(implementation depended)


Exp. A nonterminating recursive function.

int bad(int x) {
    if (x == 0)
        return 0;
    else
        return bad(x / 3 + 1) + x - 1;
}

In this case, bad(1) will failed because it will call bad(1) in else-routine of the if statement. and it will cause a infinite loop and run out of space(stack overflow)

It is the same as bad(2) because it will call bad(1)

the same for bad(3), bad(4), bad(5)...

It is only successful when bad(0) is called.


The two fundamental rules of recursion:

1) Base case. You must always have some base cases, which can be solved without recursion. (the return point for the function)

2) Making progress. For the cases that are to be solved recursively, the recursive ca

The fourth edition of Data Structures and Algorithm Analysis in C++ describes data structures, methods of organizing large amounts of data, and algorithm analysis, the estimation of the running time of algorithms. As computers become faster and faster, the need for programs that can handle large amounts of input becomes more acute. Paradoxically, this requires more careful attention to efficiency, since inefficiencies in programs become most obvious when input sizes are large. By analyzing an algorithm before it is actually coded, students can decide if a particular solution will be feasible. For example, in this text students look at specific problems and see how careful implementations can reduce the time constraint for large amounts of data from centuries to less than a second. Therefore, no algorithm or data structure is presented without an explanation of its running time. In some cases, minute details that affect the running time of the implementation are explored. Once a solution method is determined, a program must still be written. As computers have become more powerful, the problems they must solve have become larger and more complex, requiring development of more intricate programs. The goal of this text is to teach students good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amount of efficiency. This book is suitable for either an advanced data structures course or a first-year graduate course in algorithm analysis. Students should have some knowledge of intermediate programming, including such topics as pointers, recursion, and object-based programming, as well as some background in discrete math.
### 回答1: data structure and algorithm analysis in c是一本C语言数据结构算法分析的经典教材,由Mark Allen Weiss编写。该书的主要特点是对数据结构算法的讲解非常详细且透彻,采用了很多实例进行讲解,使得读者可以很快地掌握这些内容。此外,该书还特别强调了算法分析和设计的重要性,帮助读者理解复杂算法的实现方式,提高算法的优化能力。 而data structure and algorithm analysis in c的下载方式也非常简单,可以在网上找到相关的资源下载,并且也可以通过购买实体书的方式获得。对于想要深入学习C语言数据结构算法分析的人来说,这本书是非常值得推荐的一本入门教材。 ### 回答2: data structure and algorithm analysis in c是一本关于C语言数据结构算法分析的经典教科书。该书涵盖了广泛的数据结构算法,包括数组、链表、树、图、排序、查找等。本书不仅涵盖了基本概念和技术,而且提供了深入的分析和高级应用。书中有丰富的例子和习题,方便读者深入理解和应用。该书是学习数据结构算法的好材料,对于提高程序员的编程能力和解决问题的能力有很大的帮助。 ### 回答3: Data Structure and Algorithm Analysis in C是一本面向C++程序设计开发人员的算法数据结构分析书籍。它涵盖了许多重要的算法数据结构,如排序和搜索算法,二叉树,平衡树和图论等方面。本书旨在帮助读者深入了解算法数据结构的基本知识,并提供了许多实用的示例和演练题来帮助读者巩固自己的知识。 本书包含了许多实际的示例和演练题,这些题目涵盖了从简单到复杂的各种情况,有助于读者更好地理解和应用所学知识。与此同时,这本书也提供了大量的编码和调试技巧,帮助读者编写出高效和可维护的代码。 总之,Data Structure and Algorithm Analysis in C是一本优秀的参考书,无论你是刚接触算法数据结构或是已经具备一定的基础,它都可以提供丰富的知识和实践经验。如果你正在寻找一本深入了解算法数据结构的书籍,那么它一定是首选之一。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值