diff --git a/docs/JY_FENG/Semiconductor Physics and Devices/1 The Crystal Structure of Solids.md b/docs/JY_FENG/Semiconductor Physics and Devices/1 The Crystal Structure of Solids.md new file mode 100644 index 00000000..a51eedb7 --- /dev/null +++ b/docs/JY_FENG/Semiconductor Physics and Devices/1 The Crystal Structure of Solids.md @@ -0,0 +1,212 @@ +# 1 The Crystal Structure of Solids + +## 1.0 Preview + +In this chapter, we will: +■ Describe three classifications of solids—amorphous 非晶体, polycrystalline 多晶体, and single crystal. +■ Discuss the concept of a unit cell. +■ Describe three simple crystal structures and determine the volume and surfacedensity of atoms in each structure. +■ Describe the diamond crystal structure. +■ Briefly discuss several methods of forming single-crystal semiconductor materials. + +## 1.3 Space Lattices + +*lattice point* 晶格点 + +*unit cell* a small volume of the crystal that can be used to reproduce the entire crystal + +*primitive cell* the smallest unit cell that can be repeated to form the lattice. + +### 1.3.2 Basic Crystal Structures + +#### Volume Density of Atoms + +1.5 (b) +$$ +\frac1{8}\times8+1=2\\ +Volume\space Density=\frac{\#atoms\space per\space unit\space cell}{volume\space of \space unit\space cell}={2\over a^3} +$$ + +#### Three lattice types: + +![image-20240404233603766](./assets/image-20240404233603766.png) + +(a) simple cubic, (b) body-centered cubic, (c) face-centered cubic. + +### 1.3.3 Crystal Planes and Miller Indices + +surface matters a lot + +the intercepts of the plane 平面的截距 + +#### Miller indices + +hkl plane + +![image-20240404234517741](./assets/image-20240404234517741.png) + +取截距倒数?the use of infinity is avoided + +take the reciprocal(倒数) of the intercepts(截距) + +distance between nearest equivalent parallel planes + +surface concentration + +#### surface density + +![image-20240404235422381](./assets/image-20240404235422381.png) + +### 1.3.4 Directions in Crystals + +[1,1,1]平面法向量 + +## 1.4 The Diamond Structure + +tetrahedral 四面体 + +![image-20240404235735774](./assets/image-20240404235735774.png) + +![image-20240404235924203](./assets/image-20240404235924203.png) + +#### zincblende (sphalerite) structure + +![image-20240405000105070](./assets/image-20240405000105070.png) + +## 1.5 Atomic Bonding + +qualitative understanding + +valence electrons 价电子 + +ions 离子 + +coulomb attraction 库伦吸引 + + + +#### ionic bond 离子键 + +NaCl + +#### covalent bonding 共价键 + +H~2~ + +the outer silicon atoms always have valence electrons available for additional covalent bonding - infinite structure + +#### metallic bonding 金属键 + +#### Van der Waals bond 范德华~ + +nonsymmetry - small electric dipole - interact with each other + + + +## 1.6 imperfections and impurities in solids + +electrical parameters + +### 1.6.1 imperfections in solids + +atomic thermal vibration + +##### lattice vibration + +thermal energy(function of temperature) - atom randomly fluctuate + +##### point defect + +lack of an atom - **vacancy** + +image-20240410102423914 + +多了一个 **interstitial** + +* **Frenkel defect** + +##### line dislocation + +### 1.6.2 impurities in Solids + +##### lattice defects + +*substitutional* impurities + +*interstital* impurities + +![image-20240410103330800](./assets/image-20240410103330800.png) + +##### doping (参杂原子) + +* impurity diffusion + + high temperature - vacancy - impurity partical move from high concentration to lower - low down the temp + +* ion implantation + + low temp - ions be accelerated + + defect: lattice displacement damage + + solve: thermal anneal 热退火 + + + +## 1.7 growth of semiconductor materials + +### 1.7.1 growth from a melt + +#### Czochralski Method(Growth) + +seed - the same material in liquid phase - pulled - bigger + +#### zone refining(Purify) + +At the solid–liquidinterface, there is a distribution of impurities between the two phases. The parameter that describes this distribution is called the **segregation coefficient**: the ratio of the +concentration of impurities in the solid to the concentration in the liquid. + +r-f coil 射频线圈 + +#### 切割 + +flat(110)plane + +#### polish + +chemecal etch + +### 1.7.2 Epitaxial Growth + +外延生长 + +single-crystal substrate + +*homoepitaxy* one material + +*heteroepitaxy* e.g. Growing epitaxial layers of the ternary alloy AlGaAs on a GaAs substrate + +#### CVD chemical vapor-phase deposition + +chemical reaction release material atom to deposit on the material + +#### Liquid-phase epitaxy + +melt temp lower than the semiconductor itself + +practiced at low temp (III-V) + +#### Molecular Beam Epitaxy + +vacuum iat temp 0f 400-800 + +semiconductor and dopant atoms evaporated onto the surface of the substrate + +## 1.8 Summary + +**substrate** A semiconductor wafer or other material used as the starting material for further semiconductor processing, such as epitaxial growth or diffusion. + +**ternary semiconductor** A three-element compound semiconductor, such as aluminum gallium arsenide (AlGaAs). + +**elemental semiconductor** A semiconductor composed of a single species of atom, such as silicon or germanium. + diff --git a/docs/JY_FENG/Semiconductor Physics and Devices/2 Introduction to Quantum Mechanics.md b/docs/JY_FENG/Semiconductor Physics and Devices/2 Introduction to Quantum Mechanics.md new file mode 100644 index 00000000..ef0e37ca --- /dev/null +++ b/docs/JY_FENG/Semiconductor Physics and Devices/2 Introduction to Quantum Mechanics.md @@ -0,0 +1,370 @@ +# 2 Introduction to Quantum Mechanics + +## 2.0 Preview + +In this chapter, we will: + +* Discuss a few basic principles of quantum mechanics that apply to semiconductor device physics. +* State Schrodinger’s wave equation and discuss the physical meaning of the wave function. +* Consider the application of Schrodinger’s wave equation to various potential functions to determine some of the fundamental properties of electron behavior in a crystal. +* Apply Schrodinger’s wave equation to the one-electron atom. The result of this analysis yields the four basic quantum numbers, the concept of discrete energy bands, and the initial buildup of the periodic table. + +## 2.1 Principles of Quantum Mechanics + +### 2.1.1 Energy Quanta + +photoelectric effect +$$ +E=hv\space (h=6.625\times 10^{-34}J\cdot s) +$$ +**photon** the particle- like packet of energy + +**work function** The minimum energy required to remove an electron + +The **maximum kinetic energy** of the **photoelectron** +$$ +T= \frac1{2}mv^2=hv-\Phi +$$ + +### 2.1.2 Wave -Particle Duality + +#### Compton effect + +A portion of the x-ray beam was defl ected and +the frequency of the defl ected wave had shifted compared with the incident wave. + +#### Brogile wave-particle duality principle + +$$ +p=\frac{h}{\lambda} +$$ + +$\lambda$​ *de Broglie wavelength* + +##### Davisson Germer experiment + +![image-20240410115450394](./assets/image-20240410115450394.png) + +![image-20240410115912308](./assets/image-20240410115912308.png) + +### 2.1.3 The Uncertainty Principle + +#### Heisenberg uncertainty principle + +$$ +\Delta p\Delta x\ge \hbar\\ +\Delta E\Delta t\ge \hbar +$$ + +to *probability density function* + +## 2.2 Schrodinger's Wave Equation + +**wave-particle** + +### 2.2.1 The Wave Equation + +one-dimensional, nonrelativistic Schrodinger's wave equation +$$ +\frac{-\hbar}{2m}\cdot\frac{\partial^2\Psi(x,t)}{\partial x^2}+V(x)\Psi(x,t)=j\hbar\frac{\partial\Psi(x,t)}{\partial t} +$$ +$\Psi(x,t)$ wave function + +$V(x)$ potential function +$$ +\Psi(x,t)=\psi(x)\phi(t)\\ +(use\ the\ technique\ of\ seperation\ of\ variables)\\ +\frac{-\hbar}{2m}\frac1{\psi(x)}\frac{\partial^2\psi(x)}{\partial x^2}+V(x)=j\hbar\frac1{\phi(t)}\frac{\partial\phi(t)}{\partial t} +$$ +Since the left side of Equation (2.9) is a function of position x only and the right side of the equation is a function of time t only, **each side of this equation must be equal to a constant**. +$$ +\eta=j\hbar\cdot\frac1{\phi(t)}\cdot \frac{\partial\phi(t)}{t}\\ +\Rightarrow \phi(t)=e^{-j(\eta/\hbar)t}\\ +E=hv=\frac{h\omega}{2\pi}\Rightarrow\omega=\frac{\eta}{\hbar}=\frac{E}{\hbar}\Rightarrow\phi(t)=e^{-j\omega t}\\ +\therefore \frac{-\hbar^2}{2m}\cdot\frac1{\psi(x)}\cdot\frac{\partial^2\psi(x)}{\partial x^2}+V(x)=E\\ +$$ + +$$ +\Rightarrow \frac{\partial^2\phi(x)}{\partial x^2}+\frac{2m}{\hbar^2}(E-V(x))\psi(x)=0 +$$ + + + +### 2.2.2 Physical Meaning of the Wave Function + +the relation between the function and the electron +$$ +\Psi(x,t)=\psi(x)\phi(t)=\psi(x)e^{-j(E/\hbar)t}=\psi(t)e^{-j\omega t} +$$ +$\Psi$不代表任何实际的物理含义 + +$\bold{\left|\Psi(x,t)\right|^2dx}$ the probability of finding the particle between x and $x + dx$ at a given time +$$ +\begin{align} +\left|\Psi(x,t)\right|^2&=\Psi(x,t)\cdot\Psi^*(x,t)\\ +&=[\psi(x)e^{-j(E/\hbar)t}][\psi^*(x)e^{+j(E/\hbar)t}]\\ +&=\psi(x)\psi^*(x)=\left|\psi(x)\right|^2\\ +\end{align} +$$ + +### 2.2.3 Boundary Conditions + +$$ +\int^{\infin}_{-\infin}\left|\psi(x)\right|^2 dx =1 +$$ + +$E\ and\ V(x) are\ finite$ + +impose postulate(都是假设) + +* $\psi(x)$​​must finite, single valued, and continuous + + > If the probability density were to become infinite at some point in space, then the probability of finding the particle at this position would be certain and the uncertainty principle would be violated. + +* $\psi'(x)$​must finite, single valued, and continuous + + > If the total energy E and the potential V(x) are finite + > everywhere, then from **Equation (8)**, **the second derivative must be finite**, which implies that the first derivative must be continuous. The first derivative is related to the particle momentum, which must be finite and single-valued. + +![image-20240410133831842](./assets/image-20240410133831842.png) + +For these cases, the first derivative will not necessarily be continuous, but the remaining boundary conditions will still hold. + +## 2.3 Applications of Schrodinger's Wave equation + +### 2.3.1 Electron in Free Space + +$$ +\frac{\partial^2\phi(x)}{\partial x^2}+\frac{2m}{\hbar^2}(E-V(x))\psi(x)=0 +$$ + +If there is no force acting on the particle, then the potential function V(x) will be constant and we must have E>V(x). Assume $V(x)=0$, ​ + +$(14)\Rightarrow\\$ +$$ +\frac{\partial^2\phi(x)}{\partial x^2}+\frac{2mE}{\hbar^2}\psi(x)=0\\ +$$ + +$$ +\psi(x)=A\ \exp[\frac{jx\sqrt{2mE}}{\hbar}]+B\ \exp[\frac{-jx\sqrt{2mE}}{\hbar}]\\ +\Rightarrow \psi(x)=A\ \exp[jkx]+B\ \exp[-jkx]\\ +\small{k=\frac{\sqrt{2mE}}{\hbar}} +$$ + +$$ +\therefore \Psi(x,t)=A\exp[j(kx-\omega t)]+B\exp[-j(kx+\omega t)] +$$ + +**wave function** that a particle moving in free space is represented by a traveling wave. + +$A\exp[j(kx-\omega t)]$ 正行波 + +$B\exp[-j(kx+\omega t)]$ 负行波 + + + +假设B=0, 此时物质仅仅由正行波A决定 +$$ +k=\sqrt{\frac{2mE}{\hbar^2}}=\frac{p}{\hbar}\\ +E=\frac{p}{2m}此时把并未考虑相对论效应,只能说E\approx \frac{p}{2m}\\ +\small{(当动量p很小,即远小于静止质量能量m_0c^2时)} +$$ +利用德布罗意方程 +$$ +p=\frac{h}{\lambda}\\ +k=\frac{2\pi}{\lambda} +$$ +A free particle with a well-defined energy will also have a well-defined wavelength and momentum. But it can be found anywhere since $|\Psi(x,y)|^2=AA^*$. + +**wave packet** + +### 2.3.2 The Infinite Potential Well + +![image-20240410144417644](./assets/image-20240410144417644.png) +$$ +\frac{\partial^2\phi(x)}{\partial x^2}+\frac{2m}{\hbar^2}(E-V(x))\psi(x)=0\\ +$$ +**E** total energy of the particle. If E is finite, the wave function must be zero $\psi(x)=0$​ in region I and III. + +>A particle cannot penetrate these infinite potential barriers, so the probability of finding the particle in regions I and III is zero. + +$$ +\frac{\partial^2\phi(x)}{\partial x^2}+\frac{2mE}{\hbar^2}\psi(x)=0\\ +$$ + +in region II: V=0 +$$ +\psi(x)=A_1 \cos kx+A_2\sin kx\\ +k=\sqrt{\frac{2mE}{\hbar^2}} +$$ +boundary condition: + +* $\psi(x=0)=\psi(x=a)=0$ + +$$ +\therefore A_1=0\\ +and\ k=\frac{n\pi}{a}\\ +$$ + +**Negative values of n are not considered** Negative values of n simply introduce a negative sign in the wave function and yield redundant solutions for the probability density function. + +而$A_2$的解可以由$\int^{\infin}_{-\infin}\left|\psi(x)\right|^2 dx =1$给出。 + +如果波函数为实数,则 +$$ +\because \int_0^a A_2^2\sin^2 kx\ dx=1\\ +\therefore A_2=\sqrt{\frac2{a}} +$$ + +$$ +\psi(x)=\sqrt{\frac2{a}}\sin(\frac{n\pi x}{a})\ (n=1,2,3,\cdots) +$$ + +**standing wave** 驻波 + +上述方程为驻波解,电子被束缚在这个驻波解中 + +k的取值只能为n,因此E的取值也只能为限定值(E和k的关系式) + +> This result means that the energy of the particle is quantized. That is, the energy of the particle can only have particular discrete values. + +$$ +E=E_n=\frac{\hbar^2n^2\pi^2}{2ma^2}, where\ n=1,2,3,\cdots +$$ + +* We may note that as the energy increases, the probability of fi nding the particle at any given value of x becomes more uniform. + +![image-20240410150546021](./assets/image-20240410150546021.png) + +### 2.3.3 The Step Potential Function + +image-20240410150845804 + +We will assume that the particles are traveling in the +x direction and that they originated at $x=-\infin$​. + +讨论一个比较特殊的案例$E + +image-20240630194138160 + +transmission coefficient T +$$ +T=\frac{v_t\cdot A_3\cdot A_3^*}{v_i\cdot A_1\cdot A_1^*}=\frac{A_3\cdot A_3^*}{A_1\cdot A_1^*}\approx 16(\frac{E}{V_0})(1-\frac{E}{V_0})exp(-2k_2a) +$$ + +## 2.4 Extensions of the Wave Theory to Atoms + +### 2.4.1 The One-Electron Atom + +the potential function of H +$$ +V(r)=\frac{-e^2}{4\pi \epsilon_0 r} +$$ + +$$ +\grad ^2\phi(r,\theta,\phi)+\frac{2m_0}{\hbar^2}(E-V(r))\phi(r,\theta,\psi)=0 +$$ + +$\phi$ can be written in the form of +$$ +\phi(r,\theta,\phi)=R(r)\cdot\Theta(\theta)\cdot \Phi(\phi) +$$ + then, we obtain +$$ +{\sin^2\theta\over R}\cdot\frac{\partial}{\partial r}(r^2\frac{\partial R}{\partial r})+\frac1{\Phi}\cdot\frac{\partial^2\phi}{\partial \phi^2}+\frac{\sin\theta}{\Theta}\cdot \frac{\partial}{\partial\theta}(\sin\theta\cdot \frac{\partial\Theta}{\partial\theta})+r^2\sin^2\theta\sdot\frac{2m_0}{\hbar^2}(E-V)=0 +$$ + +$$ +\frac1{\Phi}\cdot\frac{\partial\Phi}{\partial\phi^2}=-m^2 +$$ + +the solution is +$$ +\phi=e^{jmp} +$$ +m is integer, $m=0,\pm1,\pm2,\dots$ + +we can further seperate the variables $\theta$ and $r$ and generate two additional seperation-of-variables constants l and n +$$ +\text{the principle quantum number } n=1,2,3,\dots\\ +\text{the angular quantum number }l=n-1,n-2,n-3,\dots,0\\ +\text{the magnetic quantum number} \abs{m}=l,l-1,\dots,0 +$$ +the electron energy is, +$$ +E_n=\frac{-m_0e^4}{(4\pi\epsilon_0)^2\cdot 2\hbar^2n^2} +$$ diff --git a/docs/JY_FENG/Semiconductor Physics and Devices/3 Introduction to the Quantum Theory of Solids.md b/docs/JY_FENG/Semiconductor Physics and Devices/3 Introduction to the Quantum Theory of Solids.md new file mode 100644 index 00000000..834e8509 --- /dev/null +++ b/docs/JY_FENG/Semiconductor Physics and Devices/3 Introduction to the Quantum Theory of Solids.md @@ -0,0 +1,94 @@ +## 3.1 Allowed and Forbidden Energy Bands + +image-20240704140255482image-20240704140432020 + + + +image-20240704140502040 + + + +image-20240704144925972 + +### 3.1.3 The $k$-Space Diagram + +the k comes from that all one-electron wave functions, for problems involving periodically varying potential energy functions, must be of the form $\psi(x)=u(x)e^{jkx}$ +$$ +P'\frac{\sin\alpha a}{\alpha a}+\cos \alpha a=\cos ka\\ +P'=\frac{mV_0ba}{\hbar^2} +$$ +Equation gives the relation between the parameter $k$ total energy +$E$ (through the parameter $\alpha$), and the potential barrier $bV_0$. + +We assume that $V_0=0$, then we acquire +$$ +\cos \alpha a=\cos ka\\ +or\quad +\alpha =k +$$ +$\alpha$ is given by$\sqrt{\frac{2mE}{\hbar^2}}=\frac{p}{\hbar}=k$, so we obtain the relationship between $k$ and $E$ +$$ +E=\frac{k^2\hbar^2}{2m} +$$ +image-20240704144228103 + +Now, we consider the relation between $E$ and $k$ form Equation for the particle in the single-crystal lattice. + +define the left side of the Equation as +$$ +f(\alpha a)=P'\frac{\sin\alpha a}{\alpha a}+\cos\alpha a +$$ +to the right side, we also have, +$$ +f(\alpha a)=\cos ka +$$ +![image-20240704145326035](./assets/image-20240704145326035.png) + +image-20240704145501812 + +the right side can also be written as $\cos ka=\cos(ka+2n\pi)=\cos(ka-2n\pi)$ + +then we gain + +image-20240704150237183 + +## 3.2 Electrical Conduction In Solids + +### 3.2.1 The Energy Band and the Bond Model + +image-20240704140810574 + +image-20240704141325933 + + + +### 3.2.2 Drift Current + +the drift current density +$$ +J=qNv_d\qquad A/cm^2\\ +or\quad J=q\sum^N_{i=1}v_i +$$ +if a force is applied to a particle and the particle moves. +$$ +dE=Fdx=Fv\cdot dt +$$ +image-20240704141339201 + +### 3.2.3 Electron Effective Mass + +$$ +F_{\text{total}}=F_{\text{ext}}+F_{\text{int}}=ma +$$ + +and we add $m^*$ as effective mass +$$ +F_{ext}=m^*a +$$ +then back to the Equation, we obtain, +$$ +\frac{dE}{dk}=\frac{\hbar^2k}{m}=\frac{\hbar p}{m}\\ +\frac1{\hbar}\frac{dE}{dk}=\frac{p}m=v\\ +$$ +and, if we take the second derivative of $E$ with respect to $k$ + diff --git a/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240404233603766.png b/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240404233603766.png new file mode 100644 index 00000000..09181044 Binary files /dev/null and b/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240404233603766.png differ diff --git a/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240404234517741.png b/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240404234517741.png new file mode 100644 index 00000000..a49f8f56 Binary files /dev/null and b/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240404234517741.png differ diff --git a/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240404235422381.png b/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240404235422381.png new file mode 100644 index 00000000..cc10b6f1 Binary files /dev/null and b/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240404235422381.png differ diff --git a/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240404235735774.png b/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240404235735774.png new file mode 100644 index 00000000..8acb7e29 Binary files /dev/null and b/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240404235735774.png differ diff --git a/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240404235915454.png b/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240404235915454.png new file mode 100644 index 00000000..d7a1a97e Binary files /dev/null and b/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240404235915454.png differ diff --git a/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240404235924203.png b/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240404235924203.png new file mode 100644 index 00000000..d7a1a97e Binary files /dev/null and b/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240404235924203.png differ diff --git a/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240405000105070.png b/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240405000105070.png new file mode 100644 index 00000000..73d2ce3d Binary files /dev/null and b/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240405000105070.png differ diff --git a/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240410102423914.png b/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240410102423914.png new file mode 100644 index 00000000..4ead2840 Binary files /dev/null and b/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240410102423914.png differ diff --git a/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240410103330800.png b/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240410103330800.png new file mode 100644 index 00000000..83b1e8d5 Binary files /dev/null and b/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240410103330800.png differ diff --git a/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240410115450394.png b/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240410115450394.png new file mode 100644 index 00000000..f2abfffd Binary files /dev/null and b/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240410115450394.png differ diff --git a/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240410115912308.png b/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240410115912308.png new file mode 100644 index 00000000..9b3258a0 Binary files /dev/null and b/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240410115912308.png differ diff --git a/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240410133831842.png b/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240410133831842.png new file mode 100644 index 00000000..e2b9f3bc Binary files /dev/null and b/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240410133831842.png differ diff --git a/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240410144417644.png b/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240410144417644.png new file mode 100644 index 00000000..505dab77 Binary files /dev/null and b/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240410144417644.png differ diff --git a/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240410150546021.png b/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240410150546021.png new file mode 100644 index 00000000..af1f1f45 Binary files /dev/null and b/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240410150546021.png differ diff --git a/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240410150845804.png b/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240410150845804.png new file mode 100644 index 00000000..c7f01380 Binary files /dev/null and b/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240410150845804.png differ diff --git a/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240630193928719.png b/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240630193928719.png new file mode 100644 index 00000000..e17ccd2c Binary files /dev/null and b/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240630193928719.png differ diff --git a/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240630194138160.png b/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240630194138160.png new file mode 100644 index 00000000..7497477d Binary files /dev/null and b/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240630194138160.png differ diff --git a/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240704140255482.png b/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240704140255482.png new file mode 100644 index 00000000..9981b2cf Binary files /dev/null and b/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240704140255482.png differ diff --git a/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240704140432020.png b/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240704140432020.png new file mode 100644 index 00000000..ddc89a1a Binary files /dev/null and b/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240704140432020.png differ diff --git a/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240704140502040.png b/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240704140502040.png new file mode 100644 index 00000000..975bcc00 Binary files /dev/null and b/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240704140502040.png differ diff --git a/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240704140810574.png b/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240704140810574.png new file mode 100644 index 00000000..04075466 Binary files /dev/null and b/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240704140810574.png differ diff --git a/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240704141325933.png b/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240704141325933.png new file mode 100644 index 00000000..6cb730cf Binary files /dev/null and b/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240704141325933.png differ diff --git a/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240704141339201.png b/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240704141339201.png new file mode 100644 index 00000000..f360c287 Binary files /dev/null and b/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240704141339201.png differ diff --git a/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240704144228103.png b/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240704144228103.png new file mode 100644 index 00000000..f2844c1a Binary files /dev/null and b/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240704144228103.png differ diff --git a/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240704144925972.png b/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240704144925972.png new file mode 100644 index 00000000..ded6dc1b Binary files /dev/null and b/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240704144925972.png differ diff --git a/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240704145326035.png b/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240704145326035.png new file mode 100644 index 00000000..2a09e0ca Binary files /dev/null and b/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240704145326035.png differ diff --git a/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240704145501812.png b/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240704145501812.png new file mode 100644 index 00000000..4ba291c3 Binary files /dev/null and b/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240704145501812.png differ diff --git a/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240704150237183.png b/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240704150237183.png new file mode 100644 index 00000000..4861cdb6 Binary files /dev/null and b/docs/JY_FENG/Semiconductor Physics and Devices/assets/image-20240704150237183.png differ diff --git a/material/overrides/home.html b/material/overrides/home.html index 6054405e..2691bb58 100644 --- a/material/overrides/home.html +++ b/material/overrides/home.html @@ -70,22 +70,28 @@

JY-HF Learning Site___'; - const taglineHTML = 'Share the knowledge to you and Us'; + const headerHTML = 'JY-HF Learning Site___'; + const taglineHTML = 'Share the knowledge to you and Us'; - headerElement.textContent = ''; - taglineElement.textContent = ''; + headerElement.textContent = ''; + taglineElement.textContent = ''; - typeWriter(headerElement, headerHTML, 150, () => { - headerElement.classList.remove('typewriter'); - console.log('Typing complete, pausing cursor animation for', headerElement); - typeWriter(taglineElement, taglineHTML, 150); - }); + typeWriter(headerElement, headerHTML, 150, () => { + headerElement.classList.remove('typewriter'); + console.log('Typing complete, pausing cursor animation for', headerElement); + typeWriter(taglineElement, taglineHTML, 150); + }); + } + + startTyping(); + setInterval(startTyping, 20000); // Repeat every 20 seconds }); +
diff --git a/mkdocs.yml b/mkdocs.yml index 11201d0c..91263267 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -164,6 +164,10 @@ nav: - Lab 12 一位全加器和四位加法器: JY_FENG/2 电路电子技术II实验/Lab12/Lab12.md - Lab 13 数字钟(Quartus): JY_FENG/2 电路电子技术II实验/Lab13/Lab13.md - Lab 14 步进电机脉冲分配器: JY_FENG/2 电路电子技术II实验/Lab14/Lab14.md + - Semiconductor Physics and Devices: + - 1 The Crystal Structure of Solids: JY_FENG\Semiconductor Physics and Devices\1 The Crystal Structure of Solids.md + - 2 Introduction to Quantum Mechanics: JY_FENG\Semiconductor Physics and Devices\2 Introduction to Quantum Mechanics.md + - 3 Introduction to the Quantum Theory of Solids: JY_FENG\Semiconductor Physics and Devices\3 Introduction to the Quantum Theory of Solids.md - Other: - Linux服务器运维(x)把玩(√): Others/linux 启动.md diff --git a/site/404.html b/site/404.html index d583f5e4..67d75742 100644 --- a/site/404.html +++ b/site/404.html @@ -143,6 +143,50 @@ + + +
@@ -232,10 +276,16 @@ + + + + + +
  • - + Jy Hu CS @@ -248,6 +298,9 @@ + + + @@ -509,7 +562,7 @@ - 1 数字逻辑设计 + 大二下 @@ -519,7 +572,1995 @@ + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + @@ -2509,7 +4517,7 @@

    404 - Not found

    - + diff --git "a/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/Final/Final/index.html" "b/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/Final/Final/index.html" index 410cf66d..34c8ff66 100644 --- "a/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/Final/Final/index.html" +++ "b/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/Final/Final/index.html" @@ -147,6 +147,50 @@ + + +
    @@ -236,10 +280,16 @@ + + + + + +
  • - + Jy Hu CS @@ -251,6 +301,9 @@ + + + @@ -517,7 +570,7 @@ - 1 数字逻辑设计 + 大二下 @@ -527,7 +580,1995 @@ + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + +
  • + + + + + + + + + + + + + + + + @@ -2622,7 +4630,7 @@

    WLab Final

    - + diff --git "a/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/Lab1/Lab1 \345\270\270\347\224\250\344\273\252\345\231\250\344\275\277\347\224\250\347\273\203\344\271\240\345\256\236\351\252\214/index.html" "b/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/Lab1/Lab1 \345\270\270\347\224\250\344\273\252\345\231\250\344\275\277\347\224\250\347\273\203\344\271\240\345\256\236\351\252\214/index.html" index d2127398..788ccb27 100644 --- "a/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/Lab1/Lab1 \345\270\270\347\224\250\344\273\252\345\231\250\344\275\277\347\224\250\347\273\203\344\271\240\345\256\236\351\252\214/index.html" +++ "b/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/Lab1/Lab1 \345\270\270\347\224\250\344\273\252\345\231\250\344\275\277\347\224\250\347\273\203\344\271\240\345\256\236\351\252\214/index.html" @@ -152,6 +152,50 @@ + + +
    @@ -241,10 +285,16 @@ + + + + + +
  • - + Jy Hu CS @@ -256,6 +306,9 @@ + + + @@ -522,7 +575,7 @@ - 1 数字逻辑设计 + 大二下 @@ -532,7 +585,1995 @@ + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + +
  • + + + + + + + + + + + + + + + + @@ -3624,7 +5632,7 @@

    实验结果

    - + diff --git "a/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/Lab2/Lab2 \345\215\212\345\257\274\344\275\223\344\272\214\346\236\201\347\256\241\347\211\271\346\200\247\346\265\213\350\257\225/index.html" "b/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/Lab2/Lab2 \345\215\212\345\257\274\344\275\223\344\272\214\346\236\201\347\256\241\347\211\271\346\200\247\346\265\213\350\257\225/index.html" index c93de5ad..bccb4670 100644 --- "a/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/Lab2/Lab2 \345\215\212\345\257\274\344\275\223\344\272\214\346\236\201\347\256\241\347\211\271\346\200\247\346\265\213\350\257\225/index.html" +++ "b/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/Lab2/Lab2 \345\215\212\345\257\274\344\275\223\344\272\214\346\236\201\347\256\241\347\211\271\346\200\247\346\265\213\350\257\225/index.html" @@ -152,6 +152,50 @@ + + +
    @@ -241,10 +285,16 @@ + + + + + +
  • - + Jy Hu CS @@ -256,6 +306,9 @@ + + + @@ -522,7 +575,7 @@ - 1 数字逻辑设计 + 大二下 @@ -532,7 +585,1995 @@ + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + +
  • + + + + + + + + + + + + + + + + @@ -3435,7 +5443,7 @@

    结果分析

    - + diff --git "a/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/Lab3/Lab3 \346\225\260\345\255\227\347\224\265\350\267\257\351\200\273\350\276\221\350\256\276\350\256\241/index.html" "b/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/Lab3/Lab3 \346\225\260\345\255\227\347\224\265\350\267\257\351\200\273\350\276\221\350\256\276\350\256\241/index.html" index f237d59e..e56d2d2c 100644 --- "a/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/Lab3/Lab3 \346\225\260\345\255\227\347\224\265\350\267\257\351\200\273\350\276\221\350\256\276\350\256\241/index.html" +++ "b/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/Lab3/Lab3 \346\225\260\345\255\227\347\224\265\350\267\257\351\200\273\350\276\221\350\256\276\350\256\241/index.html" @@ -152,6 +152,50 @@ + + +
    @@ -241,10 +285,16 @@ + + + + + +
  • - + Jy Hu CS @@ -256,6 +306,9 @@ + + + @@ -522,7 +575,7 @@ - 1 数字逻辑设计 + 大二下 @@ -532,7 +585,1995 @@ + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + +
  • + + + + + + + + + + + + + + + + @@ -3561,7 +5569,7 @@

    实验成果

    - + diff --git "a/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/Lab4/lab4 \344\270\211\346\236\201\347\256\241\345\222\214\351\227\250\347\224\265\350\267\257\347\211\271\346\200\247\346\265\213\350\257\225/index.html" "b/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/Lab4/lab4 \344\270\211\346\236\201\347\256\241\345\222\214\351\227\250\347\224\265\350\267\257\347\211\271\346\200\247\346\265\213\350\257\225/index.html" index 091d676f..ac13dfc4 100644 --- "a/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/Lab4/lab4 \344\270\211\346\236\201\347\256\241\345\222\214\351\227\250\347\224\265\350\267\257\347\211\271\346\200\247\346\265\213\350\257\225/index.html" +++ "b/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/Lab4/lab4 \344\270\211\346\236\201\347\256\241\345\222\214\351\227\250\347\224\265\350\267\257\347\211\271\346\200\247\346\265\213\350\257\225/index.html" @@ -152,6 +152,50 @@ + + +
    @@ -241,10 +285,16 @@ + + + + + +
  • - + Jy Hu CS @@ -256,6 +306,9 @@ + + + @@ -522,7 +575,7 @@ - 1 数字逻辑设计 + 大二下 @@ -532,7 +585,1995 @@ + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + +
  • + + + + + + + + + + + + + + + + @@ -3367,7 +5375,7 @@

    实验结果与分析

    - + diff --git "a/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/Lab5/Lab5 \345\260\217\350\275\246\346\243\200\346\265\213\347\224\265\350\267\257\345\222\214\347\224\265\346\234\272\351\251\261\345\212\250\347\224\265\350\267\257\346\265\213\350\257\225/index.html" "b/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/Lab5/Lab5 \345\260\217\350\275\246\346\243\200\346\265\213\347\224\265\350\267\257\345\222\214\347\224\265\346\234\272\351\251\261\345\212\250\347\224\265\350\267\257\346\265\213\350\257\225/index.html" index ffa7161c..fa17bc73 100644 --- "a/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/Lab5/Lab5 \345\260\217\350\275\246\346\243\200\346\265\213\347\224\265\350\267\257\345\222\214\347\224\265\346\234\272\351\251\261\345\212\250\347\224\265\350\267\257\346\265\213\350\257\225/index.html" +++ "b/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/Lab5/Lab5 \345\260\217\350\275\246\346\243\200\346\265\213\347\224\265\350\267\257\345\222\214\347\224\265\346\234\272\351\251\261\345\212\250\347\224\265\350\267\257\346\265\213\350\257\225/index.html" @@ -152,6 +152,50 @@ + + +
    @@ -241,10 +285,16 @@ + + + + + +
  • - + Jy Hu CS @@ -256,6 +306,9 @@ + + + @@ -522,7 +575,7 @@ - 1 数字逻辑设计 + 大二下 @@ -532,7 +585,1995 @@ + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + +
  • + + + + + + + + + + + + + + + + @@ -3119,7 +5127,7 @@

    测试过程与结果

    - + diff --git "a/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/Lab6/Lab6 \346\231\272\350\203\275\345\260\217\350\275\246\346\216\247\345\210\266/index.html" "b/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/Lab6/Lab6 \346\231\272\350\203\275\345\260\217\350\275\246\346\216\247\345\210\266/index.html" index e26e2b30..73177252 100644 --- "a/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/Lab6/Lab6 \346\231\272\350\203\275\345\260\217\350\275\246\346\216\247\345\210\266/index.html" +++ "b/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/Lab6/Lab6 \346\231\272\350\203\275\345\260\217\350\275\246\346\216\247\345\210\266/index.html" @@ -152,6 +152,50 @@ + + +
    @@ -241,10 +285,16 @@ + + + + + +
  • - + Jy Hu CS @@ -256,6 +306,9 @@ + + + @@ -522,7 +575,7 @@ - 1 数字逻辑设计 + 大二下 @@ -532,7 +585,1995 @@ + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + +
  • + + + + + + + + + + + + + + + + @@ -3011,7 +5019,7 @@

    结果分析

    - + diff --git "a/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/WLab1/WLab1/index.html" "b/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/WLab1/WLab1/index.html" index 3bfc4d57..fd9827a6 100644 --- "a/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/WLab1/WLab1/index.html" +++ "b/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/WLab1/WLab1/index.html" @@ -147,6 +147,50 @@ + + +
    @@ -236,10 +280,16 @@ + + + + + +
  • - + Jy Hu CS @@ -251,6 +301,9 @@ + + + @@ -517,7 +570,7 @@ - 1 数字逻辑设计 + 大二下 @@ -527,7 +580,1995 @@ + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + +
  • + + + + + + + + + + + + + + + + @@ -2490,7 +4498,7 @@

    WLab 1

    - 2024-07-02 + 2024-07-03 @@ -2622,7 +4630,7 @@

    WLab 1

    - + diff --git "a/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/WLab2/WLab2/index.html" "b/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/WLab2/WLab2/index.html" index 3e744e1b..f8245e31 100644 --- "a/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/WLab2/WLab2/index.html" +++ "b/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/WLab2/WLab2/index.html" @@ -147,6 +147,50 @@ + + +
    @@ -236,10 +280,16 @@ + + + + + +
  • - + Jy Hu CS @@ -251,6 +301,9 @@ + + + @@ -517,7 +570,7 @@ - 1 数字逻辑设计 + 大二下 @@ -527,7 +580,1995 @@ + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + +
  • + + + + + + + + + + + + + + + + @@ -2622,7 +4630,7 @@

    WLab 2

    - + diff --git "a/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/WLab3/WLab3/index.html" "b/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/WLab3/WLab3/index.html" index 89841709..b016bb5c 100644 --- "a/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/WLab3/WLab3/index.html" +++ "b/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/WLab3/WLab3/index.html" @@ -147,6 +147,50 @@ + + +
    @@ -236,10 +280,16 @@ + + + + + +
  • - + Jy Hu CS @@ -251,6 +301,9 @@ + + + @@ -517,7 +570,7 @@ - 1 数字逻辑设计 + 大二下 @@ -527,7 +580,1995 @@ + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + +
  • + + + + + + + + + + + + + + + + @@ -2622,7 +4630,7 @@

    WLab 3

    - + diff --git "a/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/WLab4/WLab4/index.html" "b/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/WLab4/WLab4/index.html" index 8e49d719..570fff4d 100644 --- "a/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/WLab4/WLab4/index.html" +++ "b/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/WLab4/WLab4/index.html" @@ -147,6 +147,50 @@ + + +
    @@ -236,10 +280,16 @@ + + + + + +
  • - + Jy Hu CS @@ -251,6 +301,9 @@ + + + @@ -517,7 +570,7 @@ - 1 数字逻辑设计 + 大二下 @@ -527,7 +580,1995 @@ + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + +
  • + + + + + + + + + + + + + + + + @@ -2622,7 +4630,7 @@

    WLab 4

    - + diff --git "a/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/WLab6/WLab6/index.html" "b/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/WLab6/WLab6/index.html" index 41592049..11d5ddf8 100644 --- "a/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/WLab6/WLab6/index.html" +++ "b/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/WLab6/WLab6/index.html" @@ -147,6 +147,50 @@ + + +
    @@ -236,10 +280,16 @@ + + + + + +
  • - + Jy Hu CS @@ -251,6 +301,9 @@ + + + @@ -517,7 +570,7 @@ - 1 数字逻辑设计 + 大二下 @@ -527,7 +580,1995 @@ + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + +
  • + + + + + + + + + + + + + + + + @@ -2622,7 +4630,7 @@

    WLab 6

    - + diff --git "a/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/WLab7/WLab7/index.html" "b/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/WLab7/WLab7/index.html" index 7ce358e4..eaa12021 100644 --- "a/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/WLab7/WLab7/index.html" +++ "b/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/WLab7/WLab7/index.html" @@ -147,6 +147,50 @@ + + +
    @@ -236,10 +280,16 @@ + + + + + +
  • - + Jy Hu CS @@ -251,6 +301,9 @@ + + + @@ -517,7 +570,7 @@ - 1 数字逻辑设计 + 大二下 @@ -527,7 +580,1995 @@ + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + +
  • + + + + + + + + + + + + + + + + @@ -2622,7 +4630,7 @@

    WLab 7

    - + diff --git "a/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/lab7/index.html" "b/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/lab7/index.html" index 968c5fb5..57a33700 100644 --- "a/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/lab7/index.html" +++ "b/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/lab7/index.html" @@ -152,6 +152,50 @@ + + +
    @@ -241,10 +285,16 @@ + + + + + +
  • - + Jy Hu CS @@ -256,6 +306,9 @@ + + + @@ -522,7 +575,7 @@ - 1 数字逻辑设计 + 大二下 @@ -532,7 +585,1995 @@ + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + +
  • + + + + + + + + + + + + + + + + @@ -2870,7 +4878,7 @@
    - + diff --git "a/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/preview/index.html" "b/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/preview/index.html" index 5482045c..b92d198e 100644 --- "a/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/preview/index.html" +++ "b/site/JY_FENG/1 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257I\345\256\236\351\252\214/preview/index.html" @@ -152,6 +152,50 @@ + + +
    @@ -241,10 +285,16 @@ + + + + + +
  • - + Jy Hu CS @@ -256,6 +306,9 @@ + + + @@ -522,7 +575,7 @@ - 1 数字逻辑设计 + 大二下 @@ -532,7 +585,1995 @@ + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + +
  • + + + + + + + + + + + + + + + + @@ -2546,7 +4554,7 @@

    学习内容

    冬学期:电路原理部分实验。实际上涉及较多模电实验的内容。姚缨英老师主要负责。姚老师虽然看上去事情很多,实际上事情也是真的多。PPT上的实验内容也比较杂乱,但可以根据往届的实验报告推测老师的实验要求。同时有任何不理解的内容和要求,也建议主动问姚老师。姚老师会非常耐心地解答。

    考试

    秋学期:期末考试以笔试形式考察秋学期的所有实验内容,认真阅读PPT

    -

    冬学期:姚老师基本上会以各种方式提示期末考试的内容

    +

    冬学期:姚老师基本上会以各种方式提示期末考试的内容,认真复习姚老师所给材料

    @@ -2569,7 +4577,7 @@

    考试

    - 2024-07-02 + 2024-07-04 @@ -2701,7 +4709,7 @@

    考试

    - + diff --git "a/site/JY_FENG/2 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257II\345\256\236\351\252\214/Lab1/Lab1/index.html" "b/site/JY_FENG/2 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257II\345\256\236\351\252\214/Lab1/Lab1/index.html" index dacfe73b..4cfc1731 100644 --- "a/site/JY_FENG/2 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257II\345\256\236\351\252\214/Lab1/Lab1/index.html" +++ "b/site/JY_FENG/2 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257II\345\256\236\351\252\214/Lab1/Lab1/index.html" @@ -147,6 +147,50 @@ + + +
    @@ -236,10 +280,16 @@ + + + + + +
  • - + Jy Hu CS @@ -251,6 +301,9 @@ + + + @@ -517,7 +570,7 @@ - 1 数字逻辑设计 + 大二下 @@ -527,7 +580,1995 @@ + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + +
  • + + + + + + + + + + + + + + + + @@ -2622,7 +4630,7 @@

    Lab 1 PSpice使用练习

    - + diff --git "a/site/JY_FENG/2 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257II\345\256\236\351\252\214/Lab10/Lab10/index.html" "b/site/JY_FENG/2 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257II\345\256\236\351\252\214/Lab10/Lab10/index.html" index 89908583..093d4edd 100644 --- "a/site/JY_FENG/2 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257II\345\256\236\351\252\214/Lab10/Lab10/index.html" +++ "b/site/JY_FENG/2 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257II\345\256\236\351\252\214/Lab10/Lab10/index.html" @@ -147,6 +147,50 @@ + + +
    @@ -236,10 +280,16 @@ + + + + + +
  • - + Jy Hu CS @@ -251,6 +301,9 @@ + + + @@ -517,7 +570,7 @@ - 1 数字逻辑设计 + 大二下 @@ -527,7 +580,1995 @@ + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + +
  • + + + + + + + + + + + + + + + + @@ -2622,7 +4630,7 @@

    Lab 10 触发器

    - + diff --git "a/site/JY_FENG/2 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257II\345\256\236\351\252\214/Lab11/Lab11/index.html" "b/site/JY_FENG/2 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257II\345\256\236\351\252\214/Lab11/Lab11/index.html" index 0ffaf566..4a9abbd1 100644 --- "a/site/JY_FENG/2 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257II\345\256\236\351\252\214/Lab11/Lab11/index.html" +++ "b/site/JY_FENG/2 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257II\345\256\236\351\252\214/Lab11/Lab11/index.html" @@ -147,6 +147,50 @@ + + +
    @@ -236,10 +280,16 @@ + + + + + +
  • - + Jy Hu CS @@ -251,6 +301,9 @@ + + + @@ -517,7 +570,7 @@ - 1 数字逻辑设计 + 大二下 @@ -527,7 +580,1995 @@ + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + +
  • + + + + + + + + + + + + + + + + @@ -2622,7 +4630,7 @@

    Lab 11 时序电路

    - + diff --git "a/site/JY_FENG/2 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257II\345\256\236\351\252\214/Lab12/Lab12/index.html" "b/site/JY_FENG/2 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257II\345\256\236\351\252\214/Lab12/Lab12/index.html" index 84400f08..06fa046b 100644 --- "a/site/JY_FENG/2 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257II\345\256\236\351\252\214/Lab12/Lab12/index.html" +++ "b/site/JY_FENG/2 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257II\345\256\236\351\252\214/Lab12/Lab12/index.html" @@ -147,6 +147,50 @@ + + +
    @@ -236,10 +280,16 @@ + + + + + +
  • - + Jy Hu CS @@ -251,6 +301,9 @@ + + + @@ -517,7 +570,7 @@ - 1 数字逻辑设计 + 大二下 @@ -527,7 +580,1995 @@ + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + +
  • + + + + + + + + + + + + + + + + @@ -2622,7 +4630,7 @@

    Lab 12 一位全加器和四位加法器

    - + diff --git "a/site/JY_FENG/2 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257II\345\256\236\351\252\214/Lab13/Lab13/index.html" "b/site/JY_FENG/2 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257II\345\256\236\351\252\214/Lab13/Lab13/index.html" index 0c215c52..fb8f4e84 100644 --- "a/site/JY_FENG/2 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257II\345\256\236\351\252\214/Lab13/Lab13/index.html" +++ "b/site/JY_FENG/2 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257II\345\256\236\351\252\214/Lab13/Lab13/index.html" @@ -147,6 +147,50 @@ + + +
    @@ -236,10 +280,16 @@ + + + + + +
  • - + Jy Hu CS @@ -251,6 +301,9 @@ + + + @@ -517,7 +570,7 @@ - 1 数字逻辑设计 + 大二下 @@ -527,7 +580,1995 @@ + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + +
  • + + + + + + + + + + + + + + + + @@ -2622,7 +4630,7 @@

    Lab 13 数字钟(Quartus)

    - + diff --git "a/site/JY_FENG/2 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257II\345\256\236\351\252\214/Lab14/Lab14/index.html" "b/site/JY_FENG/2 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257II\345\256\236\351\252\214/Lab14/Lab14/index.html" index 3c525942..0b807954 100644 --- "a/site/JY_FENG/2 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257II\345\256\236\351\252\214/Lab14/Lab14/index.html" +++ "b/site/JY_FENG/2 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257II\345\256\236\351\252\214/Lab14/Lab14/index.html" @@ -147,6 +147,50 @@ + + +
    @@ -236,10 +280,16 @@ + + + + + +
  • - + Jy Hu CS @@ -251,6 +301,9 @@ + + + @@ -517,7 +570,7 @@ - 1 数字逻辑设计 + 大二下 @@ -527,7 +580,1995 @@ + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + +
  • + + + + + + + + + + + + + + + + @@ -2622,7 +4630,7 @@

    Lab 14 步进电机脉冲分配器

    - + diff --git "a/site/JY_FENG/2 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257II\345\256\236\351\252\214/Lab2/Lab2/index.html" "b/site/JY_FENG/2 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257II\345\256\236\351\252\214/Lab2/Lab2/index.html" index 57d20d20..1d9ed86d 100644 --- "a/site/JY_FENG/2 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257II\345\256\236\351\252\214/Lab2/Lab2/index.html" +++ "b/site/JY_FENG/2 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257II\345\256\236\351\252\214/Lab2/Lab2/index.html" @@ -147,6 +147,50 @@ + + +
    @@ -236,10 +280,16 @@ + + + + + +
  • - + Jy Hu CS @@ -251,6 +301,9 @@ + + + @@ -517,7 +570,7 @@ - 1 数字逻辑设计 + 大二下 @@ -527,7 +580,1995 @@ + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + +
  • + + + + + + + + + + + + + + + + @@ -2622,7 +4630,7 @@

    Lab 2 信号发生电路实验

    - + diff --git "a/site/JY_FENG/2 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257II\345\256\236\351\252\214/Lab3/Lab3/index.html" "b/site/JY_FENG/2 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257II\345\256\236\351\252\214/Lab3/Lab3/index.html" index cf2ba5b3..9fd7ae58 100644 --- "a/site/JY_FENG/2 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257II\345\256\236\351\252\214/Lab3/Lab3/index.html" +++ "b/site/JY_FENG/2 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257II\345\256\236\351\252\214/Lab3/Lab3/index.html" @@ -147,6 +147,50 @@ + + +
    @@ -236,10 +280,16 @@ + + + + + +
  • - + Jy Hu CS @@ -251,6 +301,9 @@ + + + @@ -517,7 +570,7 @@ - 1 数字逻辑设计 + 大二下 @@ -527,7 +580,1995 @@ + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + +
  • + + + + + + + + + + + + + + + + @@ -2622,7 +4630,7 @@

    Lab 3 电压比较器

    - + diff --git "a/site/JY_FENG/2 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257II\345\256\236\351\252\214/Lab4/Lab4/index.html" "b/site/JY_FENG/2 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257II\345\256\236\351\252\214/Lab4/Lab4/index.html" index 1340ddad..570e1fa6 100644 --- "a/site/JY_FENG/2 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257II\345\256\236\351\252\214/Lab4/Lab4/index.html" +++ "b/site/JY_FENG/2 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257II\345\256\236\351\252\214/Lab4/Lab4/index.html" @@ -147,6 +147,50 @@ + + +
    @@ -236,10 +280,16 @@ + + + + + +
  • - + Jy Hu CS @@ -251,6 +301,9 @@ + + + @@ -517,7 +570,7 @@ - 1 数字逻辑设计 + 大二下 @@ -527,7 +580,1995 @@ + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + +
  • + + + + + + + + + + + + + + + + @@ -2622,7 +4630,7 @@

    Lab 4 光耦合电路及其应用实验

    - + diff --git "a/site/JY_FENG/2 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257II\345\256\236\351\252\214/Lab5/Lab5/index.html" "b/site/JY_FENG/2 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257II\345\256\236\351\252\214/Lab5/Lab5/index.html" index 994de116..0ed2e80d 100644 --- "a/site/JY_FENG/2 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257II\345\256\236\351\252\214/Lab5/Lab5/index.html" +++ "b/site/JY_FENG/2 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257II\345\256\236\351\252\214/Lab5/Lab5/index.html" @@ -147,6 +147,50 @@ + + +
    @@ -236,10 +280,16 @@ + + + + + +
  • - + Jy Hu CS @@ -251,6 +301,9 @@ + + + @@ -517,7 +570,7 @@ - 1 数字逻辑设计 + 大二下 @@ -527,7 +580,1995 @@ + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + +
  • + + + + + + + + + + + + + + + + @@ -2623,7 +4631,7 @@

    Lab 5 仪用放大电路及其应用实验

    - + diff --git "a/site/JY_FENG/2 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257II\345\256\236\351\252\214/Lab6/Lab6/index.html" "b/site/JY_FENG/2 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257II\345\256\236\351\252\214/Lab6/Lab6/index.html" index ff5521c7..3d69e3f4 100644 --- "a/site/JY_FENG/2 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257II\345\256\236\351\252\214/Lab6/Lab6/index.html" +++ "b/site/JY_FENG/2 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257II\345\256\236\351\252\214/Lab6/Lab6/index.html" @@ -147,6 +147,50 @@ + + +
    @@ -236,10 +280,16 @@ + + + + + +
  • - + Jy Hu CS @@ -251,6 +301,9 @@ + + + @@ -517,7 +570,7 @@ - 1 数字逻辑设计 + 大二下 @@ -527,7 +580,1995 @@ + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + +
  • + + + + + + + + + + + + + + + + @@ -2623,7 +4631,7 @@

    Lab 6 滤波器的设计与实现

    - + diff --git "a/site/JY_FENG/2 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257II\345\256\236\351\252\214/Lab7/Lab7/index.html" "b/site/JY_FENG/2 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257II\345\256\236\351\252\214/Lab7/Lab7/index.html" index e2bf05e8..c9dafd27 100644 --- "a/site/JY_FENG/2 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257II\345\256\236\351\252\214/Lab7/Lab7/index.html" +++ "b/site/JY_FENG/2 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257II\345\256\236\351\252\214/Lab7/Lab7/index.html" @@ -147,6 +147,50 @@ + + +
    @@ -236,10 +280,16 @@ + + + + + +
  • - + Jy Hu CS @@ -251,6 +301,9 @@ + + + @@ -517,7 +570,7 @@ - 1 数字逻辑设计 + 大二下 @@ -527,7 +580,1995 @@ + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + +
  • + + + + + + + + + + + + + + + + @@ -2623,7 +4631,7 @@

    Lab 7 扩音机电路的设计制作与测试

    - + diff --git "a/site/JY_FENG/2 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257II\345\256\236\351\252\214/Lab8/Lab8/index.html" "b/site/JY_FENG/2 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257II\345\256\236\351\252\214/Lab8/Lab8/index.html" index 04ff3c27..9c6838ec 100644 --- "a/site/JY_FENG/2 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257II\345\256\236\351\252\214/Lab8/Lab8/index.html" +++ "b/site/JY_FENG/2 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257II\345\256\236\351\252\214/Lab8/Lab8/index.html" @@ -147,6 +147,50 @@ + + +
    @@ -236,10 +280,16 @@ + + + + + +
  • - + Jy Hu CS @@ -251,6 +301,9 @@ + + + @@ -517,7 +570,7 @@ - 1 数字逻辑设计 + 大二下 @@ -527,7 +580,1995 @@ + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + +
  • + + + + + + + + + + + + + + + + @@ -2622,7 +4630,7 @@

    Lab 8 数字钟

    - + diff --git "a/site/JY_FENG/2 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257II\345\256\236\351\252\214/Lab9/Lab9/index.html" "b/site/JY_FENG/2 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257II\345\256\236\351\252\214/Lab9/Lab9/index.html" index f82e980e..9b4d046d 100644 --- "a/site/JY_FENG/2 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257II\345\256\236\351\252\214/Lab9/Lab9/index.html" +++ "b/site/JY_FENG/2 \347\224\265\350\267\257\347\224\265\345\255\220\346\212\200\346\234\257II\345\256\236\351\252\214/Lab9/Lab9/index.html" @@ -147,6 +147,50 @@ + + +
    @@ -236,10 +280,16 @@ + + + + + +
  • - + Jy Hu CS @@ -251,6 +301,9 @@ + + + @@ -517,7 +570,7 @@ - 1 数字逻辑设计 + 大二下 @@ -527,7 +580,1995 @@ + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + +
  • + + + + + + + + + + + + + + + + @@ -2623,7 +4631,7 @@

    Lab 9 全加器与奇偶位检验电路

    - + diff --git "a/site/JY_FENG/3 \347\224\265\347\275\221\347\273\234\345\210\206\346\236\220/Preview/index.html" "b/site/JY_FENG/3 \347\224\265\347\275\221\347\273\234\345\210\206\346\236\220/Preview/index.html" index e14bd40b..cdd89c54 100644 --- "a/site/JY_FENG/3 \347\224\265\347\275\221\347\273\234\345\210\206\346\236\220/Preview/index.html" +++ "b/site/JY_FENG/3 \347\224\265\347\275\221\347\273\234\345\210\206\346\236\220/Preview/index.html" @@ -148,6 +148,50 @@ + + +
    @@ -237,10 +281,16 @@ + + + + + +
  • - + Jy Hu CS @@ -253,6 +303,9 @@ + + + @@ -514,7 +567,7 @@ - 1 数字逻辑设计 + 大二下 @@ -524,7 +577,1995 @@ + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + @@ -2470,7 +4478,7 @@

    写在前面 for 电网络分析

    - 2024-07-03 + 2024-07-03 @@ -2480,7 +4488,7 @@

    写在前面 for 电网络分析

    - 2024-07-03 + 2024-07-03 @@ -2564,7 +4572,7 @@

    写在前面 for 电网络分析

    - + diff --git a/site/JY_FENG/JY-Feng/index.html b/site/JY_FENG/JY-Feng/index.html index 3803db6e..725005ac 100644 --- a/site/JY_FENG/JY-Feng/index.html +++ b/site/JY_FENG/JY-Feng/index.html @@ -11,7 +11,7 @@ - + @@ -147,6 +147,50 @@ + + +
    @@ -236,10 +280,16 @@ + + + + + +
  • - + Jy Hu CS @@ -251,6 +301,9 @@ + + + @@ -517,7 +570,7 @@ - 1 数字逻辑设计 + 大二下 @@ -527,7 +580,1995 @@ + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + +
  • + + + + + + + + + + + + + + + + @@ -2510,7 +4518,7 @@

    Preview

    - 2024-07-02 + 2024-07-03 @@ -2555,7 +4563,7 @@

    Preview

    - + diff --git "a/site/JY_HU/1 \346\225\260\345\255\227\351\200\273\350\276\221\350\256\276\350\256\241/\346\225\260\345\255\227\351\200\273\350\276\221\350\256\276\350\256\241 notes/index.html" "b/site/JY_HU/1 \346\225\260\345\255\227\351\200\273\350\276\221\350\256\276\350\256\241/\346\225\260\345\255\227\351\200\273\350\276\221\350\256\276\350\256\241 notes/index.html" deleted file mode 100644 index fb0075a4..00000000 --- "a/site/JY_HU/1 \346\225\260\345\255\227\351\200\273\350\276\221\350\256\276\350\256\241/\346\225\260\345\255\227\351\200\273\350\276\221\350\256\276\350\256\241 notes/index.html" +++ /dev/null @@ -1,2782 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - 理论部分 - JY-HF learning site - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - - - - 跳转至 - - -
    -
    - -
    - - - - -
    - - -
    - -
    - - - - - - - - - -
    -
    - - - -
    -
    -
    - - - - - - - - - -
    -
    -
    - - - - -
    -
    - - - - - - - -

    数字逻辑设计 notes

    -

    SOP:sum of minterms

    -

    对函数求complement

    -

    Implicant: squares in the map

    -

     product term obtained by combining adjacent squares in the map into a rectangle with the number of squares a power of 2.

    -

    A Prime Implicant is a product term obtained by combining the maximum possible number of adjacent squares in the map into a rectangle with the number of squares a power of 2.

    -

    A prime implicant is called an Essential Prime Implicant if it is the only prime implicant that covers (includes) one or more minterms.

    -

    简单来说就是如果没有这个圈有的格子就包裹不进去,就是 essential prime implicant

    -

    1.3 implicant -蕴含项其实就是我们文章最开始提到的“圈”,每一种可能的圈就是一个蕴含项

    -

    在这里插入图片描述

    -

    上图中就有7个一次蕴含项,6个二次蕴含项和1个四次蕴含项,共计14个蕴含项

    -

    1.4 prime implicant -质蕴含项就是不能与其它蕴含项合并的蕴含项,在1.3中,我们发现四次蕴含项中有4个二次蕴含项,那么它们就不是质蕴含项

    -

    在这里插入图片描述

    -

    可以看到上图中的每一个圈都不能和其它圈合并,所以上图有共计4个质蕴含项

    -

    1.5 essential prime implicant -实质本源蕴含项中必须含有至少一个没被包含在其它蕴含项中的项,而且不能被更大的圈包裹

    -

    在这里插入图片描述

    -

    上图中有三个实质本源蕴含项,而我们找到最简SOP的方式就是找到所有的实质本源蕴含项

    -

    cost criteria

    -

    Literal cost L

    -

    gate input cost G

    -

    gate input cost with NOTs GN

    -

    propagation delay \(t_{pd} = max{(t_{PLH},t_{PHL})}\)

    -

    \(t_{PHL}\)

    -

    propagation : 传输

    -

    分为transport delay 和 inertia delay(有rejection time属性)

    -

    image-20231015200001435

    -

    image-20231015200046111

    -

    三个串联?四个可以吗

    -

    74LS00与非门传输延迟测量:3个74LS00门串联,4个可以吗?

    -

    \((\overline{A B})\)

    -

    image-20231017153245413

    -

    2-12怎么化简

    -

    4位全加器的延时较长

    -

    因此采用carry look ahead adder

    -

    16位加法器使用4个CLA串联

    -

    64位 组超前进位

    -

    将G0~3, P0~3传给下一层?

    -

    C4 = G3 +P3G2 + P3P2G1+P3P2P1G0+P3P2P1P0C0

    -

    ​ = G0~3 + P0~3*C0

    -

    C8 = G4~7 + P4~7*C4

    -

    同理,C12 = G8~11+ P8~11*C8

    -

    C16 = G12~15+ P12~15*C12

    -

    依赖关系和4位的CLA相似

    -

    Carry Lookahead Adder in VHDL and Verilog with Full-Adders

    -

    小测1 复习

    -

    1、逻辑表达式化简:

    -

    \(A+\overline{A}B=(A+B)(A+\overline{A})=A+B\)

    -

    \(逻辑表达式可重复使用\)

    -

    2、门代价计算:

    -

    3、卡诺图化简

    -

    4变量的卡诺图,16个格子,圈的大小为8->1个变量

    -

    image-20231113230459090

    - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - - - -
    - - - -
    -
    -
    -
    - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git "a/site/JY_HU/1 \346\225\260\345\255\227\351\200\273\350\276\221\350\256\276\350\256\241/\346\225\260\351\200\273\345\256\236\351\252\214/index.html" "b/site/JY_HU/1 \346\225\260\345\255\227\351\200\273\350\276\221\350\256\276\350\256\241/\346\225\260\351\200\273\345\256\236\351\252\214/index.html" deleted file mode 100644 index 6352fcf4..00000000 --- "a/site/JY_HU/1 \346\225\260\345\255\227\351\200\273\350\276\221\350\256\276\350\256\241/\346\225\260\351\200\273\345\256\236\351\252\214/index.html" +++ /dev/null @@ -1,2694 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - 实验过程 - JY-HF learning site - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - - - - 跳转至 - - -
    -
    - -
    - - - - -
    - - -
    - -
    - - - - - - - - - -
    -
    - - - -
    -
    -
    - - - - - - - - - -
    -
    -
    - - - - -
    -
    - - - - - - - -

    数逻实验过程笔记

    -

    image-20231120201822638

    -

    发现只要是在这个文件结构下的图片都会正常显示

    -

    因为实际上typora编辑器的设置中拷贝图片时会将assets会单独复制一份

    -

    image-20231120201554458

    -

    然而,拷贝后进行缩放,就是改为了html格式,就不能够正常渲染?

    -

    image-20231120201906942

    -

    image-20231120202158410

    -

    发现mkdocs在渲染导出HTML时是会将除了md格式的所有东西都拷贝一份到自己的目录下面的

    - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - - - -
    - - - -
    -
    -
    -
    - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git "a/site/JY_HU/2 \346\225\260\346\215\256\347\273\223\346\236\204/labs&hw/FDS Lab&hw review/index.html" "b/site/JY_HU/2 \346\225\260\346\215\256\347\273\223\346\236\204/labs&hw/FDS Lab&hw review/index.html" deleted file mode 100644 index a15d8673..00000000 --- "a/site/JY_HU/2 \346\225\260\346\215\256\347\273\223\346\236\204/labs&hw/FDS Lab&hw review/index.html" +++ /dev/null @@ -1,2642 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - Labs & hw - JY-HF learning site - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - -
    -
    - -
    - - - - -
    - - -
    - -
    - - - - - - - - - -
    -
    - - - -
    -
    -
    - - - - - - - - - -
    -
    -
    - - - - -
    -
    - - - - - - - -

    Labs & hw

    - -

    FDS Lab&hw review

    - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - - - -
    - - - -
    -
    -
    -
    - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git "a/site/JY_HU/2 \346\225\260\346\215\256\347\273\223\346\236\204/mynotes/midterm/index.html" "b/site/JY_HU/2 \346\225\260\346\215\256\347\273\223\346\236\204/mynotes/midterm/index.html" deleted file mode 100644 index 6633e6f2..00000000 --- "a/site/JY_HU/2 \346\225\260\346\215\256\347\273\223\346\236\204/mynotes/midterm/index.html" +++ /dev/null @@ -1,3631 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - midterm - JY-HF learning site - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - - - - 跳转至 - - -
    -
    - -
    - - - - -
    - - -
    - -
    - - - - - - - - - -
    -
    - - - -
    -
    -
    - - - - - - - - - -
    -
    -
    - - - - -
    -
    - - - - - - - -

    midterm

    -

    易错复杂度分析

    -

    建堆(不是一个个插入)的算法:\(O(N)\),对i=n/2到1的所有节点都pecolate down

    -

    指针比较多,注意调试不要打印或者访问NULL的某个属性,避免越界等段错误

    -

    因此所有的find percolate insert都先判断是否为NULL节点,再访问节点的left/right

    -

    从二叉树中删除节点:

    -

    先找到元素,找到NULL则说明要删除的元素不存在

    -

    再看有几个子节点,若0或1个则直接替换(用Null)替换也可

    -

    若有两个则用左子树中的最大节点或右子树中最小的节点替换,替换过程中只先改变根节点的数值,再执行delete那个底下的重复节点

    -

    插入新元素

    -

    插在最后,向上percolate,注意percolate up自然是不用比较大小的,down需要比较大小

    -
    -

    Percolate

    -
    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    -14
    -15
    -16
    -17
    -18
    -19
    -20
    -21
    -22
    -23
    -24
    -25
    -26
    -27
    -28
    void PercolateUp(int p, PriorityQueue H)
    -{
    -    int i;
    -    for (i = p; i > 1;){
    -        if( H->Elements[i / 2] > H->Elements[i]){
    -             ElementType temp = H->Elements[i/2];
    -             H->Elements[i/2] = H->Elements[i];
    -             H->Elements[i] = temp;
    -              i = i/2;
    -        }
    -        else break;
    -    }
    -}
    -void PercolateDown(int p, PriorityQueue H)
    -{
    -    int i, Child;
    -    for (i = p; i * 2 <= H->Size; i = Child)
    -    {
    -        Child = i * 2;
    -        if (Child != H->Size && H->Elements[Child + 1] < H->Elements[Child])
    -            Child++;
    -        if (H->Elements[i] > H->Elements[Child]){
    -             ElementType temp = H->Elements[Child];
    -             H->Elements[Child] = H->Elements[i];
    -             H->Elements[i] = temp;
    -        }
    -    }
    -}
    -
    -

    弹出最小值(DeleteMin)并维护堆的性质:

    -

    用最后一个元素替换堆顶元素,并进行minHeapify

    -

    minHeapify过程,就是percolate down的过程

    -

    递归传递的参数为堆指针和当前节点的下标i,首先计算出左右节点下标(2i,2i+1),比较左右节点选出较小值与根节点交换,递归持续进行到越界或最小值就是i结束。

    -

    1.堆:

    -

    2.栈、队列

    -

    3.并查集:

    -

    naive implementaion:

    -
    C
    1
    -2
    -3
    -4
    union(r1,r2):
    -    S[r2]=r1  //将r2指向r1
    -//问题:r1,r2必须都是root,因此在执行上面之前要先find
    -=> union(find(node1),find(node2))
    -
    -

    最坏情况复杂度达到\(O(N^2)\)!!!!

    -

    union-by-size:总是使较小的树成为较大的树的子树

    -
      -
    • [Lemma] Let T be a tree created by union-by-size with N nodes, then \(height(T)\leq\lfloor\log_2N\rfloor+1\).
    • -
    -

    Proved by induction. Each element can have its set name changed at most \(\log_2N\) times.

    -
      -
    • -

      Time complexity of \(N\) Union and \(M\) Find operations is now \(O(N+M\log_2N)\).

      -
    • -
    • -

      原因:被链接的树的大小至少翻倍

      -
    • -
    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    -14
    /* Assumes Rootl and Root2 are roots*/
    -void SetUnion(DisjSet S, SetType Root1, SetType Root2)
    -{
    -    if (S[Root1] <= S[Root2])
    -    {
    -        S[Root1] += S[Root2];
    -        S[Root2] = Root1;
    -    }
    -    else
    -    {
    -        S[Root2] += S[Root1];
    -        S[Root1] = Root2;
    -    }
    -}
    -
    -

    union-by-height:只有当两颗相同深度的树合并时才要求增加树的深度?

    -
      -
    • Always change the shallow tree
    • -
    • 保证所有的树的深度最多是\(O(logN)\)
    • -
    -

    使用S[root]保存树的深度的相反数,都是负数,绝对值越大越深

    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    /* Assumes Rootl and Root2 are roots*/
    -void SetUnion(DisjSet S, SetType Root1, SetType Root2)
    -{
    -    if ( S[Root2] < S[Root1])  /*Root2 is deeper set*/
    -        S[Root1] = Root2;      /*Make Root2 new root*/
    -    else
    -    {
    -        if (S[Root1] == S[Root2])  /*Same height*/
    -            S[Root1]--;
    -        S[Root2] = Root1;
    -    }
    -}
    -
    -

    path-compression akaman-algorithm

    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    SetType Find( ElementType X, DisjSet S )
    -{   
    -    ElementType root, trail, lead;
    -    for ( root = X; S[ root ] > 0; root = S[ root ] );  /* find the root */
    -    for ( trail = X; trail != root; trail = lead )
    -    {
    -        lead = S[ trail ];   
    -        S[ trail ] = root;   
    -    }  /* collapsing */
    -    return root;
    -}
    -
    -

    和普通的find相比:find/recursive find,尾递归情形

    -
    C
    1
    -2
    -3
    -4
    -5
    -6
    -7
    SetType Find( ElementType X, DisjSet S )
    -{
    -    if ( S[ X ] <= 0 )    
    -        return X;
    -    else 
    -        return S[ X ] = Find( S[ X ], S );
    -}
    -
    -

    4.树:二叉树,搜索树

    -

    zigzagging on a tree

    -

    zigzag.jpg

    -
    C
    1
    -2
    -3
    -4
    sample input:
    -8
    -12 11 20 17 1 15 8 5  左中右 中序  
    -12 20 17 11 15 8 5 1  左右中 后序  后序的最后一个节点为根节点
    -
    -
    C
    1
    -2
    sample output:
    -1 11 5 8 17 12 20 15
    -
    -
    C
      1
    -  2
    -  3
    -  4
    -  5
    -  6
    -  7
    -  8
    -  9
    - 10
    - 11
    - 12
    - 13
    - 14
    - 15
    - 16
    - 17
    - 18
    - 19
    - 20
    - 21
    - 22
    - 23
    - 24
    - 25
    - 26
    - 27
    - 28
    - 29
    - 30
    - 31
    - 32
    - 33
    - 34
    - 35
    - 36
    - 37
    - 38
    - 39
    - 40
    - 41
    - 42
    - 43
    - 44
    - 45
    - 46
    - 47
    - 48
    - 49
    - 50
    - 51
    - 52
    - 53
    - 54
    - 55
    - 56
    - 57
    - 58
    - 59
    - 60
    - 61
    - 62
    - 63
    - 64
    - 65
    - 66
    - 67
    - 68
    - 69
    - 70
    - 71
    - 72
    - 73
    - 74
    - 75
    - 76
    - 77
    - 78
    - 79
    - 80
    - 81
    - 82
    - 83
    - 84
    - 85
    - 86
    - 87
    - 88
    - 89
    - 90
    - 91
    - 92
    - 93
    - 94
    - 95
    - 96
    - 97
    - 98
    - 99
    -100
    -101
    -102
    -103
    -104
    -105
    -106
    -107
    -108
    -109
    -110
    -111
    -112
    -113
    -114
    -115
    -116
    -117
    -118
    -119
    -120
    -121
    -122
    -123
    -124
    -125
    -126
    -127
    -128
    -129
    -130
    -131
    -132
    -133
    -134
    -135
    -136
    -137
    -138
    -139
    -140
    -141
    -142
    -143
    -144
    -145
    -146
    -147
    #include <stdio.h>
    -#include <string.h>
    -#include <stdlib.h>
    -#define MAX_NODE_NUM 60
    -
    -typedef struct tree_node
    -{
    -    int data;
    -    struct tree_node *left;
    -    struct tree_node *right;
    -} tree_node;
    -typedef tree_node *tree_ptr;
    -
    -typedef struct
    -{
    -    int front;
    -    int rear;
    -    tree_ptr list[MAX_NODE_NUM];
    -} tree_queue;
    -typedef tree_queue *queue_ptr;
    -
    -void enqueue(tree_ptr tree, queue_ptr queue)
    -{
    -    if (tree == NULL)
    -        return; // 空树不入队
    -    queue->list[queue->rear++] = tree;
    -}
    -
    -tree_ptr dequeue(queue_ptr queue)
    -{
    -    if (queue->front == queue->rear)
    -        return NULL; // 队列为空时返回NULL
    -    tree_ptr tree_node = queue->list[queue->front++];
    -    return tree_node;
    -}
    -
    -tree_ptr build_tree(int *in_order, int *post_order, int n)
    -{
    -    if (n <= 0 || in_order == NULL || post_order == NULL || n > MAX_NODE_NUM)
    -        return NULL;
    -    tree_ptr root = (tree_ptr)malloc(sizeof(tree_node));
    -    root->data = post_order[n - 1];
    -    int index = 0;
    -    for (int i = 0; i < n; i++)
    -    {
    -        if (in_order[i] == post_order[n - 1])
    -            index = i;
    -    }
    -    // 把中序序列分成两部分,左边的是左子树,右边的是右子树
    -    // 此处 in_order + index + 1 忘记+1,导致只有左枝的左子树建成了右子树
    -    root->left = build_tree(in_order, post_order, index);
    -    root->right = build_tree(in_order + index + 1, post_order + index, n - index - 1);
    -    return root;    //build_tree的最后一个参数是子树的节点数,左子树是0~index-1共index个节点,右子树是n-index-1个节点,从index开始到n-1共(n-1)-index+1-1(除去根节点)=n-index-1个节点
    -
    -    中序 左子树12 11 20 17 )【1 右子树15 8 5
    -    后序 12 20 17 11)( 15 8 5)【1
    -        i+5post_order+4,n-index-1
    -}
    -
    -int is_empty(queue_ptr queue)
    -{
    -    if (queue->front == queue->rear)
    -        return 1;
    -    else
    -        return 0;
    -}
    -/*
    -void print_tree(tree_ptr tree){
    -    //打印顺序为根左右
    -    if(tree == NULL)return;
    -    printf("%d ", tree->data);
    -    if(tree->left != NULL)print_tree(tree->left);
    -    if(tree->right != NULL)print_tree(tree->right);  
    -}
    -*/
    -typedef struct
    -{
    -    int data[MAX_NODE_NUM];
    -    int pointer;
    -} sequence;
    -typedef sequence *sequence_ptr;
    -
    -int zigzag_levelorder(tree_ptr tree, queue_ptr queue)
    -{
    -    // zigzag的层序遍历
    -    int level = 0;
    -    enqueue(tree, queue);
    -    while (is_empty(queue) == 0)
    -    {
    -        int len = queue->rear - queue->front;
    -        if (level % 2)
    -        {
    -            for (int i = queue->front; i < queue->front + len; i++)
    -            {
    -                printf(" %d", queue->list[i]->data);
    -            }
    -        }
    -        else
    -        {
    -            for (int i = queue->front + len - 1; i >= queue->front; i--)
    -            {
    -                if (level == 0)
    -                    printf("%d", queue->list[i]->data);
    -                else
    -                    printf(" %d", queue->list[i]->data);
    -            }
    -        }
    -        for (int i = queue->front; i < queue->front + len; i++)
    -        {
    -            if (queue->list[i]->left != NULL)
    -                enqueue(queue->list[i]->left, queue);
    -            if (queue->list[i]->right != NULL)
    -                enqueue(queue->list[i]->right, queue);
    -        }
    -        queue->front = queue->front + len;
    -        level++;
    -    }
    -}
    -
    -int main()
    -{
    -    // zigzag 层序遍历,在每一行输出时打印出逆序的
    -    int n;
    -    scanf("%d", &n);
    -    // The second line gives the inorder sequence
    -    // and the third line gives the postorder sequence
    -    /*  1. 根据后序序列的最后一个元素建立根结点;
    -        2. 在中序序列中找到该元素,确定根结点的左右子树的中序序列;
    -        3. 在后序序列中确定左右子树的后序序列;
    -        4. 由左子树的后序序列和中序序列建立左子树;
    -        5. 由右子树的后序序列和中序序列建立右子树。*/
    -    int in_order[MAX_NODE_NUM] = {0};
    -    int post_order[MAX_NODE_NUM] = {0};
    -    for (int i = 0; i < n; i++)
    -        scanf("%d", &in_order[i]);
    -    for (int i = 0; i < n; i++)
    -        scanf("%d", &post_order[i]);
    -
    -    tree_ptr tree = build_tree(in_order, post_order, n);
    -    // 把树打印出来看看
    -    // print_tree(tree);
    -
    -    queue_ptr queue = (queue_ptr)malloc(sizeof(tree_queue));
    -    queue->front = 0;
    -    queue->rear = 0;
    -    zigzag_levelorder(tree, queue);
    -}
    -
    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    -14
    int Isomorphic( Tree T1, Tree T2 ){
    -    //左右子树互换,每层的东西应该是相同的
    -    //层序遍历?只要递归实现一下即可
    -    if(!T1&&!T2)return 1;
    -    else if(!T1&&T2||!T2&&T1)return 0;
    -    if(T1->Element!=T2->Element)return 0;
    -    int ans1 = Isomorphic(T1->Left,T2->Left);
    -    int ans2 = Isomorphic(T1->Right,T2->Left);
    -    int ans3 = Isomorphic(T1->Left,T2->Right);
    -    int ans4 = Isomorphic(T1->Right,T2->Right);
    -    return ans1&&ans4||ans2&&ans3;
    -
    -
    -}
    -
    -

    insertion sequence序列不同,构建出的二叉树形状可能有多种

    -

    2023-11-23 (9)

    -

    建立二叉搜索树的顺序

    -

    先判断当前节点是否为NULL,若是,则建立新节点(data = x,left=right=NULL)

    -

    若不是,则递归向下,若大于当前,则Insert(x,tree->left),小于前,则Insert(x,tree->right)

    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    -14
    -15
    -16
    -17
    -18
    -19
    -20
    -21
    -22
    SearchTree Insert( ElementType X, SearchTree T ) 
    -{ 
    -    if ( T == NULL ) /* Create and return a one-node tree */ 
    -    { 
    -        T = malloc( sizeof( struct TreeNode ) ); 
    -        if ( T == NULL ) 
    -            FatalError( "Out of space!!!" ); 
    -        else 
    -        { 
    -            T->Element = X; 
    -            T->Left = T->Right = NULL; 
    -        } 
    -    }  /* End creating a one-node tree */
    -    else  /* If there is a tree */
    -        if ( X < T->Element ) 
    -            T->Left = Insert( X, T->Left ); 
    -        else 
    -            if ( X > T->Element ) 
    -                T->Right = Insert( X, T->Right ); 
    -        /* Else X is in the tree already; we'll do nothing */ 
    -    return  T;   /* Do not forget this line!! */ 
    -}
    -
    -

    作业错题

    -

    2023-11-23 (3)

    -

    2023-11-23 (4)

    -

    环形队列 数组实现

    -

    Suppose that an array of size m is used to store a circular queue. If the front position is front and the current size is size, then the rear element must be at:

    -
    Text Only
    A.front+size
    -
    -
    Text Only
    B.(front+size)%m
    -
    -
    Text Only
    C.(front+size-1)%m  this one
    -
    -
    Text Only
    D.front+size-1
    -
    -

    2023-11-23 (5)

    -

    image-20231123171418423

    -

    disjoint sets

    -

    2023-11-23 (7)

    -
    HW3: 栈最多容纳M个数,数字1~N依次入栈,而出栈顺序任意,验证给定的序列是否为出栈序列
    -

    对于某个序列,如3,2,1,7,5,6,4,栈的大小为5

    -

    预设flag=1,假设是合法出栈序列

    -

    初始化栈顶指针为-1,先将1入栈,因为1一定是第一个入栈,使用i记录下一个将要入栈的元素

    -

    栈顶不能超过M,且还未遍历完(使用\(num[j]\)保存如果是合法出栈序列即将出栈的元素)

    -

    \(栈顶元素==num[j]\)则弹出,\(j\)向后遍历

    -

    若到最后栈不为空则error

    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    -14
    -15
    -16
    -17
    -18
    -19
    -20
    -21
    -22
    -23
    -24
    -25
    -26
    -27
    -28
    -29
    -30
    -31
    -32
    -33
    -34
    -35
    -36
    -37
    -38
    -39
    -40
    -41
    -42
    -43
    -44
    -45
    -46
    -47
    -48
    -49
    -50
    -51
    -52
    -53
    #include <stdio.h>
    -#include <stdlib.h>
    -#include <time.h>
    -#define MAXSIZE 1000
    -
    -int main()
    -{
    -    int M, N, K;
    -    scanf("%d %d %d", &M, &N, &K);
    -    // M为栈的最大容量,N为入栈的数字个数,K为需要判断的出栈序列的个数
    -    int i, j, k;
    -    int num[MAXSIZE];
    -    int flag, current;
    -    // 枚举出栈顺序,然后模拟出栈过程,如果出现不合法的情况,就直接跳出循环,输出NO
    -    for (i = 0; i < K; i++)
    -    {
    -        for (j = 0; j < N; j++)
    -        {
    -            scanf("%d", &num[j]);
    -        }
    -        flag = test(num, M, N); // 传入出栈序列,栈的最大容量,入栈数字的个数
    -        if (flag == 0)
    -            printf("NO\n");
    -        else
    -            printf("YES\n");
    -    }
    -}
    -
    -int test(int *num, int M, int N)
    -{
    -    int stack[MAXSIZE] = {0};
    -    int flag = 1;
    -    int top = -1;
    -    int i = 0, j = 0;   // i为入栈序列,j为出栈序列的下标
    -    stack[++top] = ++i; // 先将1入栈
    -    while (top < M && j < N)
    -    // 栈不满且出栈序列还未遍历完
    -    {
    -        if (top != -1 && stack[top] == num[j])
    -        // 栈不为空且栈顶元素等于出栈序列的当前元素,则出栈,且j向后遍历
    -        {
    -            top--;
    -            j++;
    -        }
    -        else
    -        {
    -            stack[++top] = ++i;
    -        }
    -    }
    -    if (top != -1)
    -        flag = 0; // 栈不为空,说明出栈序列不合法
    -    return flag;
    -}
    -
    -

    polish

    -

    infix操作

    -

    2023-11-26

    -

    C

    -

    计算机只能在将中缀表达式转换为前缀或后缀表达式后才能进行运算

    -

    计算机在计算后缀表达式时只需从左到右线性扫描,遇到操作数压入栈,遇到运算符则依次取出栈顶的两个操作数计算后将结果重新压回栈中。

    -

    因此将中缀表达式转换为前缀或后缀表达式比较关键

    -

    一般使用两个栈进行此操作,在转换时不进行运算,只是将运算符和操作数重新排列

    -

    最后输出时一般是倒序输出

    -

    注意,只有S1栈顶运算符优先级小于当前运算符时,才将当前运算符压入S1,否则直接压入中间结果栈S2

    -

    S2不叫操作数栈,因为最后结果从S2中逆序输出得到

    -

    img

    -

    img

    -

    倒序输出为ABC+*DEF+/-

    -

    操作数顺序不会变化,一定是叶子节点

    -

    二分查找+1-1问题处理

    -

    img

    -
      -
    • 左、中、右索引的分配。
    • -
    • 循环或递归终止条件。
    • -
    • 后处理的必要性
    • -
    -

    模板1相当于 左闭右闭区间 left=0,right=length-1,

    -

    模板2相当于 左闭右开区间 left=0,right=length,

    -

    模板3相当于 左开右开区间 left=-1,right=length/ left=0,right=length-1,

    -

    2和3找的是\(>=\)target的第一个数

    -

    模板 #1 (left <= right):

    -
      -
    • 二分查找的最基础和最基本的形式。
    • -
    • 查找条件可以在不与元素的两侧进行比较的情况下确定(或使用它周围的特定元素)。
    • -
    • 不需要后处理,因为每一步中,你都在检查是否找到了元素。如果到达末尾,则知道未找到该元素。
    • -
    -

    模板 #2 (left < right):

    -
      -
    • 一种实现二分查找的高级方法。
    • -
    • 查找条件需要访问元素的直接右邻居。
    • -
    • 使用元素的右邻居来确定是否满足条件,并决定是向左还是向右。
    • -
    • 保证查找空间在每一步中至少有 2 个元素。
    • -
    • 需要进行后处理。 当你剩下 1 个元素时,循环 / 递归结束。 需要评估剩余元素是否符合条件。
    • -
    -

    模板 #3 (left + 1 < right):

    -
      -
    • 实现二分查找的另一种方法。
    • -
    • 搜索条件需要访问元素的直接左右邻居。
    • -
    • 使用元素的邻居来确定它是向右还是向左。
    • -
    • 保证查找空间在每个步骤中至少有 3 个元素。
    • -
    • 需要进行后处理。 当剩下 2 个元素时,循环 / 递归结束。 需要评估其余元素是否符合条件。
    • -
    -

    K-th largest Num

    -

    在N个元素的数组中找第K大的数:

    -

    N个元素的前K个先做minHeapify,后面的元素依次插入堆的对应位置:

    -

    方法:insert,如果比H[1](堆顶元素,下标从1开始)小,则不插入堆中,因为堆顶就是第K个大的数

    -

    若比H[1]大,则percolate down,沿途子节点向上替换父节点,也就是H[1]被替换

    -

    将余下的K+1~N个元素全部判断并插入后,最终堆顶元素就是N个数中第K大的数

    -

    期中考试刷题

    -

    15-16

    -

    No Greater Than X in BST

    -

    (20分)

    -

    You are supposed to output, in decreasing order, all the elements no greater than X in a binary search tree T.

    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    -14
    -15
    -16
    -17
    -18
    -19
    -20
    -21
    -22
    -23
    -24
    -25
    -26
    -27
    -28
    -29
    -30
    -31
    -32
    #include <stdio.h>
    -#include <stdlib.h>
    -
    -typedef struct TreeNode *Tree;
    -struct TreeNode {
    -    int Element;
    -    Tree  Left;
    -    Tree  Right;
    -};
    -
    -Tree BuildTree(); /* details omitted */
    -void Output( int X ); /* details omitted */
    -
    -void Print_NGT( Tree T,  int X );
    -
    -int main()
    -{
    -    Tree T;
    -    int X;
    -
    -    T = BuildTree();
    -    scanf("%d", &X);
    -    Print_NGT( T, X );
    -    printf("End\n");
    -
    -    return 0;
    -}
    -
    -/* Your function will be put here */
    -void Print_NGT( Tree T,  int X ){
    -
    -}
    -
    - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - - - -
    - - - -
    -
    -
    -
    - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git "a/site/JY_HU/2 \346\225\260\346\215\256\347\273\223\346\236\204/webnotes/Foundation-of-Data-Structure.pdf" "b/site/JY_HU/2 \346\225\260\346\215\256\347\273\223\346\236\204/webnotes/Foundation-of-Data-Structure.pdf" deleted file mode 100644 index d732f40c..00000000 Binary files "a/site/JY_HU/2 \346\225\260\346\215\256\347\273\223\346\236\204/webnotes/Foundation-of-Data-Structure.pdf" and /dev/null differ diff --git "a/site/JY_HU/2 \346\225\260\346\215\256\347\273\223\346\236\204/webnotes/Foundation-of-Data-Structure/index.html" "b/site/JY_HU/2 \346\225\260\346\215\256\347\273\223\346\236\204/webnotes/Foundation-of-Data-Structure/index.html" deleted file mode 100644 index 07e74f38..00000000 --- "a/site/JY_HU/2 \346\225\260\346\215\256\347\273\223\346\236\204/webnotes/Foundation-of-Data-Structure/index.html" +++ /dev/null @@ -1,9033 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - 总集篇 - JY-HF learning site - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - - - - 跳转至 - - -
    -
    - -
    - - - - -
    - - -
    - -
    - - - - - - - - - -
    -
    - - - -
    -
    -
    - - - - - - - - - -
    -
    -
    - - - - -
    -
    - - - - - - - -

    Foundation of Data Structure

    -
    -

    by OE.Heart

    -
    -
    -

    1 Algorithm Analysis

    -

    [Definition] An algorithm is a finite set of instructions that, if followed, accomplishes a particular task. In addition, all algorithms must satisfy the following criteria.

    -
      -
    1. -

      Input : There are zero or more quantities that are externally supplied.

      -
    2. -
    3. -

      Output : At least one quantity is produced.

      -
    4. -
    5. -

      Definiteness : Each instruction is clear and unambiguous.

      -
    6. -
    7. -

      Finiteness : the algorithm terminates after finite number of steps

      -
    8. -
    9. -

      Effectiveness : basic enough to be carried out ; feasible

      -
    10. -
    11. -

      A program does not have to be finite. (eg. an operation system)

      -
    12. -
    13. -

      An algorithm can be described by human languages, flow charts, some programming languages, or pseudocode.

      -
    14. -
    -

    [Example] Selection Sort : Sort a set of \(n\geq1\) integers in increasing order

    -
    Text Only
    1
    -2
    -3
    -4
    for (i = 0; i < n; i++){
    -    Examine list[i] to list[n-1] and suppose that the smallest integer is at list[min];
    -    Interchange list[i] and list[min];
    -}
    -
    -
    -

    1.1 What to Analyze

    -
      -
    • -

      Machine and compiler-dependent run times.

      -
    • -
    • -

      Time and space complexities : machine and compiler independent.

      -
    • -
    • -

      Assumptions:

      -
    • -
    -
    -
      -
    1. -

      instructions are executed sequentially 顺序执行

      -
    2. -
    3. -

      each instruction is simple, and takes exactly one time unit

      -
    4. -
    5. integer size is fixed and we have infinite memory
    6. -
    -
    -
      -
    • \(T_{avg}(N)\, and\, T_{worst}(N)\) : the average and worst case time complexities as functions of input size \(N\)
    • -
    -

    [Example] Matrix addition

    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    void add(int a[][MAX_SIZE],
    -         int b[][MAX_SIZE],
    -         int c[][MAX_SIZE],
    -         int rows, int cols) 
    -{
    -    int i, j;
    -    for (i=0; i<rows; i++)/*rows+1*/
    -        for (j=0;j<cols;j++)/*rows(cols+1)*/
    -            c[i][j] = a[i][j]+b[i][j];/*rows*cols*/
    -}
    -
    -
    \[ -T(rows, cols) = 2rows\times cols + 2rows+1 -\]
    -
      -
    • 非对称
    • -
    -

    [Example] Iterative function for summing a list of numbers

    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    float sum (float list[], int n)
    -{  /*add a list of numbers*/
    -    float tempsum = 0; /*count = 1*/
    -    int i;
    -    for (i=0; i<n; i++)
    -        /*count++*/
    -        tempsum  += list[i]; /*count++*/
    -    /*count++ for last excutaion of for*/
    -   return tempsum; /*count++*/
    -}
    -
    -
    \[ -T_{sum}(n)=2n+3 -\]
    -

    [Example] Recursive function for summing a list of numbers

    -
    C
    1
    -2
    -3
    -4
    -5
    -6
    -7
    float rsum (float list[], int n)
    -{/*add a list of numbers*/
    -    if (n) /*count++*/
    -        return rsum(list, n-1) + list[n-1];
    -        /*count++*/
    -    return 0; /*count++*/
    -}
    -
    -
    \[ -T_{rsum}(n)=2n+2 -\]
    -

    But it takes more time to compute each step.

    -
    -

    1.2 Asymptotic Notation(\(O,\Omega,\Theta,o\))

    -
      -
    • predict the growth ; compare the time complexities of two programs ; asymptotic(渐进的) behavior
    • -
    -

    [Definition] \(T(N)=O(f(N))\) if there are positive constants \(c\) and \(n_0\) such that \(T(N)\leq c\cdot f(N)\) for all \(N\geq n_0\).(upper bound)

    -

    [Definition] \(T(N)=\Omega(g(N))\) if there are positive constants \(c\) and \(n_0\) such that \(T(N)\geq c\cdot f(N)\) for all \(N\geq n_0\).(lower bound)

    -

    [Definition] \(T(N)=\Theta(h(N))\) if and only if \(T(N)=O(h(N))\) and \(T(N)=\Omega(h(N))\).

    -

    [Definition] \(T(N)=o(p(N))\) if \(T(n)=O(p(N))\) and \(T(N)\neq\Theta(p(N))\).

    -
      -
    • -

      \(2N+3=O(N)=O(N^{k\geq1})=O(2^N)=\ldots\) take the smallest \(f(N)\)

      -
    • -
    • -

      \(2^N+N^2=\Omega(2^N)=\Omega(N^2)=\Omega(N)=\Omega(1)=\ldots\) take the largest \(g(N)\)

      -
    • -
    • -

      Rules of Asymptotic Notation

      -
    • -
    -
    -
      -
    1. If \(T_1(N)=O(f(N))\) and \(T_2=O(g(N))\), then
    2. -
    -

    (1) \(T_1(N)+T_2(N)=max(O(f(N)),O(g(N)))\)

    -

    (2) \(T_1(N)*T_2(N)=O(f(N)*g(N))\)

    -
      -
    1. -

      \(T(N)\)是一个\(k\)次多项式,则\(T(N)=\Theta(N^k)\)

      -
    2. -
    3. -

      \(log_kN=O(N)\) for any constant \(k\) (logarithms grow very slowly)

      -
    4. -
    -
    -

    1-1

    -

    1-2

    -

    [Example] Matrix addition

    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    void add(int a[][MAX_SIZE],
    -         int b[][MAX_SIZE],
    -         int c[][MAX_SIZE],
    -         int rows, int cols) 
    -{
    -    int i, j;
    -    for (i=0; i<rows; i++)
    -        for (j=0;j<cols;j++)
    -            c[i][j] = a[i][j]+b[i][j];
    -}
    -
    -
    \[ -T(rows,cols)=\Theta(rows\cdot cols) -\]
    -

    General Rules

    -
    -
      -
    • -

      For loops : The running time of a for loop is at most the running time of the statements inside the for loop (including tests) times the number of iterations.

      -
    • -
    • -

      Nested for loops : The total running time of a statement inside a group of nested loops is the running time of the statements multiplied by the product of the sizes of all the for loops.

      -
    • -
    • -

      Consecutive statements : These just add (which means that the maximum is the one that counts).

      -
    • -
    • -

      If/else : For the fragment - if ( Condition ) S1; - else S2;

      -
    • -
    -

    The running time is never more than the running time of the test plus the larger of the running time of S1 and S2.

    -

    1-3

    -
      -
    • Recursions :
    • -
    -

    [Example] Fibonacci number - $$ - Fib(0)=Fib(1)=1, Fib(n)=Fib(n-1)+Fib(n-2) - $$

    -
    C
    1
    -2
    -3
    -4
    -5
    -6
    -7
    lont int Fib (int N) /*T(N)*/
    -{
    -    if (N<=1) /*O(1)*/
    -        return 1; /*O(1)*/
    -    else
    -        return Fib(N-1)+Fib(N-2);
    -}      /*O(1)*//*T(N-1)*//*T(N-2)*/
    -
    -

    $$ - T(N)=T(N-1)+T(N-2)+2\geq Fib(N)\ - \left(\frac{3}{2} \right)^n\leq Fib(N)\leq\left(\frac{5}{3}\right)^n - $$

    -

    时间复杂度:\(O(2^N)\) \(T(N)\) grows exponentially

    -

    空间复杂度:\(O(N)\)

    -
    -
    -

    1.3 Compare the Algorithms

    -

    [Example] 最大子序列和

    -

    Algorithm 1

    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    -14
    int  MaxSubsequenceSum ( const int A[ ],  int  N ) 
    -{ 
    -    int ThisSum, MaxSum, i, j, k; 
    -    MaxSum = 0;   /* initialize the maximum sum */
    -    for( i = 0; i < N; i++ )  /* start from A[ i ] */
    -        for( j = i; j < N; j++ ) {   /* end at A[ j ] */
    -            ThisSum = 0; 
    -            for( k = i; k <= j; k++ ) 
    -                ThisSum += A[ k ];  /* sum from A[ i ] to A[ j ] */
    -            if ( ThisSum > MaxSum ) 
    -                MaxSum = ThisSum;  /* update max sum */
    -        }  /* end for-j and for-i */
    -    return MaxSum; 
    -}
    -
    -
    \[ -T(N)=O(N^3) -\]
    -

    Algotithm 2

    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    -14
    int  MaxSubsequenceSum ( const int A[ ],  int  N ) 
    -{ 
    -    int ThisSum, MaxSum, i, j; 
    -    MaxSum = 0;   /* initialize the maximum sum */
    -    for( i = 0; i < N; i++ ) {   /* start from A[ i ] */
    -        ThisSum = 0; 
    -        for( j = i; j < N; j++ ) {   /* end at A[ j ] */
    -            ThisSum += A[ j ];  /* sum from A[ i ] to A[ j ] */
    -            if ( ThisSum > MaxSum ) 
    -                MaxSum = ThisSum;  /* update max sum */
    -        }  /* end for-j */
    -    }  /* end for-i */
    -    return MaxSum; 
    -} 
    -
    -
    \[ -T(N)=O(N^2) -\]
    -

    Algorithm 3 Divide and Conquer 分治法

    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    -14
    -15
    -16
    -17
    -18
    -19
    -20
    -21
    -22
    -23
    -24
    -25
    -26
    -27
    -28
    -29
    -30
    -31
    -32
    -33
    -34
    -35
    -36
    -37
    -38
    -39
    -40
    -41
    -42
    static int MaxSubSum(const int A[ ], int Left, int Right)
    -{
    -    int MaxLeftSum, MaxRightSum;
    -    int MaxLeftBorderSum, MaxRightBorderSum;
    -    int LeftBorderSum, RightBorderSum;
    -    int Center, i;
    -
    -    if (Left == Right)
    -        if (A[Left] > 0)
    -            return A[Left];
    -        else
    -            return 0;
    -
    -    Center = (Left + Right) / 2;
    -    MaxLeftSum = MaxSubSum(A, Left, Center);
    -    MaxRightSum = MaxSubSum(A, Center + 1, Right);
    -
    -    MaxLeftBorderSum = 0;
    -    LeftBorderSum = 0;
    -    for (i = Center; i >= Left; i--)
    -    {
    -        LeftBorderSum += A[i];
    -        if (LeftBorderSum > MaxLeftBorderSum)
    -            MaxLeftBorderSum = LeftBorderSum;
    -    }
    -
    -    MaxRightBorderSum = 0;
    -    RightBorderSum = 0;
    -    for (i = Center+1; i <= Right; i++)
    -    {
    -        RightBorderSum += A[i];
    -        if (RightBorderSum > MaxRightBorderSum)
    -            MaxRightBorderSum = RightBorderSum;
    -    }
    -
    -    return Max3(MaxLeftSum, MaxRightSum, MaxLeftBorderSum + MaxRightBorderSum);
    -}
    -
    -int MaxSubsequenceSum(const int A[ ], int N)
    -{
    -    return MaxSubSum(A, 0, N - 1);
    -}
    -
    -
    \[ -\because T(N)=2T(\frac N2)+cN\quad T(1)=O(1)\\ -T(\frac N2)=2T(\frac N {2^2})+c\frac N2\\ -\cdots\\ -T(1)=2T(\frac N{2^k})+c\frac N{2^{k-1}}\\ -\therefore T(N)=2^kT(\frac N{2^k})+kcN=N\cdot O(1)+cN\log N -\]
    -

    Algorithm 4 On-line Algorithm 在线算法

    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    int MaxSubsequenceSum( const int  A[ ],  int  N ) 
    -{ 
    -    int ThisSum, MaxSum, j; 
    -    ThisSum = MaxSum = 0; 
    -    for ( j = 0; j < N; j++ ) { 
    -        ThisSum += A[ j ]; 
    -        if ( ThisSum > MaxSum ) 
    -            MaxSum = ThisSum; 
    -        else if ( ThisSum < 0 ) 
    -            ThisSum = 0;
    -    }  /* end for-j */
    -    return MaxSum; 
    -} 
    -
    -
    \[ -T(N)=O(N) -\]
    -
      -
    • A[ ] is scanned once only. 扫描一次,无需存储(处理streaming data)
    • -
    • 在任意时刻,算法都能对它已经读入的数据给出子序列问题的正确答案(其他算法不具有这个特性)
    • -
    -
    -

    1.4 Logrithms in the Running Time

    -
      -
    • 如果一个算法用常数时间将问题的大小削减为其一部分(通常是1/2),那么该算法就是\(O(logN)\)
    • -
    - -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    -14
    -15
    -16
    int BinarySearch ( const ElementType A[ ], ElementType X, int N ) 
    -{ 
    -    int  Low, Mid, High; 
    -    Low = 0;  High = N - 1; 
    -    while ( Low <= High ) { 
    -        Mid = ( Low + High ) / 2; 
    -        if ( A[ Mid ] < X ) 
    -            Low = Mid + 1; 
    -        else 
    -            if ( A[ Mid ] > X ) 
    -                High = Mid - 1; 
    -            else 
    -                return  Mid; /* Found */ 
    -    }  /* end while */
    -    return  NotFound; /* NotFound is defined as -1 */ 
    -} 
    -
    -
    \[ -T_{worst}(N)=O(\log N) -\]
    -

    [Example] Euclid’s Algorithm

    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    int Gcd(int M, int N)
    -{
    -    int Rem;
    -
    -    while (N > 0)
    -    {
    -        Rem = M % N;
    -        M = N;
    -        N = Rem;
    -    }
    -    return M;
    -}
    -
    -

    [Example] Efficient exponentiation

    -
    C
    1
    -2
    -3
    -4
    -5
    -6
    -7
    long int Pow(long int X, int N)
    -{
    -    if (N == 0) return 1;
    -    if (N == 1) return X;
    -    if (IsEven(N)) return Pow(X*X, N/2);/*return Pow(X, N/2)*Pow(X, N/2) affects the efficiency*/
    -    else return Pow(X*X, N/2)*X; /*return Pow(X, N-1)*X is the same*/
    -}
    -
    -
    -

    1.5 Checking Your Analysis

    -

    Method 1

    -

    When \(T(N)=O(N)\), check if \(T(2N)/T(N)\approx2\)

    -

    When \(T(N)=O(N^2)\), check if \(T(2N)/T(N)\approx4\)

    -

    When \(T(N)=O(N^3)\), check if \(T(2N)/T(N)\approx8\)

    -

    Method 2

    -

    When \(T(N)=O(f(N))\), check if $\lim\limits_{N\rightarrow\infty}\frac{T(N)}{f(N)}\approx C $

    -
    -

    2 LIst, Stacks and Queues

    -

    2.1 Abstract Data Type(ADT) 抽象数据类型

    -

    [Definition] Data Type = {Objects} and {Operations}

    -

    [Definition] An Abstract Data Type(ADT) is a data type that is organized in such a way that the specification on the objects and specification of the operations on the objects are separated from the representation of the objects and the implementation on the operations.

    -
    -

    2.2 The List ADT

    -
      -
    • Objects : N items
    • -
    • Operations
    • -
    • Finding the length
    • -
    • Printing
    • -
    • Making an empty
    • -
    • Finding
    • -
    • Inserting
    • -
    • Deleting
    • -
    • Finding next
    • -
    • Finding previous
    • -
    -

    Simple Array implementation of Lists

    -
      -
    • -

      Sequential mapping 连续存储,访问快

      -
    • -
    • -

      Find_Kth take \(O(1)\) time.

      -
    • -
    • -

      MaxSize has to be estimated.

      -
    • -
    • -

      Insertion and Deletion not only take \(O(N)\) times, but also involve a lot of data movements which takes time.

      -
    • -
    -

    2-3

    -

    Query 查询

    -

    Linked Lists

    -
      -
    • -

      Location of nodes may change on differrent runs.

      -
    • -
    • -

      Insertion 先连后断

      -
    • -
    • -

      Deletion 先连后释放

      -
    • -
    • -

      频繁malloc和free系统开销较大

      -
    • -
    • -

      Finding take \(O(N)\) times.

      -
    • -
    -
    C
    1
    -2
    -3
    -4
    -5
    /*Return true if L is empty*/
    -int IsEmpty(List L)
    -{
    -  return L->Next == NULL;
    -}
    -
    -
    C
    1
    -2
    -3
    -4
    -5
    -6
    /*Return true if P is the last position in list L*/
    -/*Parameter L is unused in this implementation*/
    -int IsLast(Position P, List L)
    -{
    -  return P->Next == NULL;
    -}
    -
    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    /*Return Position of X in L; NULL if not found*/
    -Position Find(Element X, List L)
    -{
    -  Position P;
    -
    -  P = L->Next;
    -  while (P != NULL && P->Element != X) P = P->Next;
    -
    -  return P;
    -}
    -
    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    -14
    -15
    /*Delete first occurence of X from a list*/
    -/*Assume use of a header node*/
    -void Delete(ElementType X, List L)
    -{
    -  Position P, TmpCell;
    -
    -  P = FindPrevious(X, L);
    -
    -  if (!IsLast(P, L))
    -  {
    -      TmpCell = P->Next;
    -      P->Next = TmpCell->Next;
    -      free(TmpCell);
    -  }
    -}
    -
    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    /*If X is not found, then Next field of returned*/
    -/*Assumes a header*/
    -Position FindPrevious(ElementType X, List L)
    -{
    -  Position P;
    -
    -  P = L;
    -  while (P->Next != NULL && P->Next->Element != X) P = P->Next;
    -
    -  return P;
    -}
    -
    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    -14
    /*Insert (after legal position P)*/
    -/*Header implementation assumed*/
    -/*Parameter L is unused in this implementation*/
    -void Insert(ElementType X, List L, Position P)
    -{
    -  Position TmpCell;
    -
    -  TmpCell = malloc(sizeof(struct Node));
    -  if (TmpCell == NULL) FatalError("Out of space!")
    -
    -  TmpCell->Element = X;
    -  TmpeCell->Next = P->Next;
    -  P->Next = TmpCell;
    -}
    -
    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    void DeleteList(List L)
    -{
    -  Position P, Tmp;
    -
    -  P = L->Next;
    -  L->Next = NULL;
    -  while (P != NULL)
    -  {
    -      Tmp = P->Next;
    -      free(P);
    -      P = Tmp;
    -  }
    -}
    -
    -

    Doubly Linked Circular Lists

    -
      -
    • Finding take \(O(\frac N 2)\) times.
    • -
    -

    2-1

    -

    The correct answer is D.

    -

    Two Applications

    -
      -
    1. -

      The Polynomial ADT

      -
    2. -
    3. -

      Objects :

      -
    4. -
    5. -

      Operations :

      -
    6. -
    7. -

      Finding degree

      -
    8. -
    9. Addition
    10. -
    11. Subtraction
    12. -
    13. -

      Multiplication

      -
    14. -
    15. -

      Differentiation

      -
    16. -
    17. -

      [Representation 1]

      -
    18. -
    -
    C
    1
    -2
    -3
    -4
    typedef struct {
    -  int CoeffArray [ MaxDegree + 1 ] ;
    -  int HighPower;
    -}  *Polynomial ; 
    -
    -
    C
    1
    -2
    -3
    -4
    -5
    -6
    -7
    -8
    /*将多项式初始化为零*/
    -void ZeroPolynomial(Polynomial Poly)
    -{
    -  int i;
    -  for(i = O; i <= MaxDegree; i++)
    -      Poly->CoeffArray[ i ] = O;
    -  Poly->HighPower = O;
    -}
    -
    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    /*两个多项式相加*/
    -void AddPolynomial(const Polynomial Poly1, const Polynomial Poly2, Polynomial PolySum)
    -{
    -    int i;
    -
    -    ZeroPolynomial(PolySum);
    -  PolySum->HighPower = Max(Poly1->HighPower, Poly2->HighPower);
    -
    -    for (i = PolySum->HighPower; i >= O; i--)
    -      PolySum->CoeffArray[ i ] = Poly1->CoeffArray[ i ] + Poly2->CoeffArray[ i ];
    -}
    -
    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    -14
    void MultPolynomial(const Polynomial Poly1, const Polynomial Poly2, Polynomial PolyProd)
    -{
    -    int i, j;
    -
    -    ZeroPolynomial (PolyProd);
    -  PolyProd->HighPower = Poly1->HighPower + Poly2->HighPower;
    -
    -    if(PolyProd->HighPower > MaxDegree)
    -      Error("Exceeded array size");
    -  else
    -      for(i = O; i <= Poly1->HighPower; i++)
    -          for(j = O; j <= Poly2->HighPower; j++)
    -              PolyProd->CoeffArray[ i + j ] += Poly1->CoeffArray[ i ] * Poly2->CoeffArray[ j ];
    -}
    -
    -
      -
    • [Representation 2]
    • -
    -
    C
    1
    -2
    -3
    -4
    -5
    -6
    -7
    typedef struct poly_node *poly_ptr;
    -struct poly_node{
    -    int Coefficient;  /* assume coefficients are integers */
    -    int Exponent;
    -    poly_ptr Next;
    -};
    -typedef poly_ptr a;    /* nodes sorted by exponent */
    -
    -
      -
    • -

      只存储非零项

      -
    • -
    • -

      Multilists

      -
    • -
    -

    Cursor Implementation of Linked Lists(no pointer)

    -

    2-2

    -
    -

    2.3 The Stack ADT

    -
      -
    • Last-In-First-Out (LIFO)
    • -
    • Objects : A finite ordered list with zero or more elements.
    • -
    • Operations :
    • -
    • IsEmpty
    • -
    • CreatStack
    • -
    • DisposeStack
    • -
    • MakeEmpty
    • -
    • Push
    • -
    • Top
    • -
    • Pop
    • -
    • A Pop(or Top) on an empty stack in an error in the stack ADT.
    • -
    • Push on a full stack is an implementation error but not an ADT error.
    • -
    -

    Linked List Implementation (with a header node)

    -

    3-1

    -
      -
    • The calls to malloc and free are expensive. Simply keep another stack as a recycle bin.
    • -
    -
    C
    1
    -2
    -3
    -4
    int IsEmpty(Stack S)
    -{
    -  return S->Next == NULL;
    -}
    -
    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    -14
    -15
    -16
    -17
    -18
    Stack CreateStack(void)
    -{
    -  Stack S;
    -  S = malloc(sizeof(struct Node));
    -  if (S == NULL)
    -      Fatal Error("Out of space!");
    -  S->Next == NULL;
    -  MakeEmpty(S);
    -  return S;
    -}
    -
    -void MakeEmpty(Stack S)
    -{
    -  if (S == NULL)
    -      Error("Must use CreateStack first");
    -  else
    -      while(!IsEmpty(S)) Pop(S);
    -}
    -
    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    void Push(ElementType X, Stack S)
    -{
    -  PtrToNode TmpCell;
    -  TmpCell = malloc(sizeof(struct Node));
    -  if (TmpCell == NULL)
    -      Fatal Error("Out of space!") ;
    -  else
    -  {
    -      TmpCell->Element = X;
    -      TmpCe11->Next = S->Next;
    -      S->Next = TmpCell;
    -  }
    -}
    -
    -
    C
    1
    -2
    -3
    -4
    -5
    -6
    -7
    ElementType Top(Stack S)
    -{
    -  if(!IsEmpty(S))
    -      return S->Next->Element;
    -  Error("Empty stack") ;
    -  return O; /* Return value used to avoid warning*/
    -}
    -
    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    void Pop(Stack s)
    -{
    -  PtrToNode FirstCell;
    -  if(IsEmpty(S))
    -      Error("Empty stack") ;
    -  else
    -  {
    -      FirstCe11 = S->Next;
    -      S->Next = S->Next->Next;
    -      free(FirstCe11);
    -  }
    -}
    -
    -

    Array Implementation of Stacks

    -
    C
    1
    -2
    -3
    -4
    -5
    -6
    struct StackRecord {
    -    int Capacity;          /* size of stack */
    -    int TopOfStack;        /* the top pointer */
    -    /* ++ for push, -- for pop, -1 for empty stack */
    -    ElementType *Array;    /* array for stack elements */
    -}; 
    -
    -
      -
    • -

      The stack model must be well encapsulated(封装). That is, no part of your code, except for the stack routines, can attempt to access the Array or TopOfStack variable.

      -
    • -
    • -

      Error check must be done before Push or Pop (Top).

      -
    • -
    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    -14
    -15
    -16
    Stack CreateStack(int MaxElements)
    -{
    -  Stack S;
    -  if(MaxElements < MinStackSize)
    -  Error("Stack size is too small") ;
    -  S = malloc(sizeof(struct StackRecord));
    -  if (S == NULL)
    -      Fatal Error("Out of space!!!") ;
    -
    -  S->Array = malloc(sizeof(ElementType) * MaxElements) ;
    -  if(S->Array = NULL)
    -      Fatal Error("Out of space!!!");
    -  S->Capacity = MaxElements;
    -  MakeEmpty(S) ;
    -  return S;
    -}
    -
    -
    C
    1
    -2
    -3
    -4
    -5
    -6
    -7
    -8
    void DisposeStack(Stack S)
    -{
    -  if(S != NULL)
    -  {
    -      free(S->Array);
    -      free(S);
    -  }
    -}
    -
    -
    C
    1
    -2
    -3
    -4
    int IsEmpty(Stack S)
    -{
    -  return S->TopOfStack == EmptyTOS;
    -}
    -
    -
    C
    1
    -2
    -3
    -4
    void MakeEmpty(Stack S)
    -{
    -  S->TopOfStack = EmptyTOS;
    -}
    -
    -
    C
    1
    -2
    -3
    -4
    -5
    -6
    -7
    void Push(ElementType X, Stack S)
    -{
    -  if (IsFull(S))
    -      Error("Full stack");
    -  else
    -      S->Array[ ++S->TopOfStack ] = X;
    -}
    -
    -
    C
    1
    -2
    -3
    -4
    -5
    -6
    -7
    ElementType Top(Stack S)
    -{
    -  if(! IsEmpty(S))
    -      return S->Array[ S->TopOfStack ];
    -  Error("Empty stack") ;
    -  return O; /* Return value used to avoid warning*/
    -}
    -
    -
    C
    1
    -2
    -3
    -4
    -5
    -6
    -7
    void Pop(Stack S)
    -{
    -  if(IsEmpty(S))
    -      Error("Empty stack") ;
    -  else
    -      S->TopOfStack--;
    -}
    -
    -
    C
    1
    -2
    -3
    -4
    -5
    -6
    -7
    ElementType TopAndPop(Stack S)
    -{
    -  if(!Is Empty(S))
    -      return S->Array[ S->TopOfStack-- ];
    -  Error("Empty stack");
    -  return O; /* Return value used to avoid warnin */
    -}
    -
    -

    Application

    -
      -
    1. Balancing Symbols
    2. -
    -

    检查括号是否平衡

    -
    Text Only
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    -14
    -15
    Algorithm  {
    -    Make an empty stack S;
    -    while (read in a character c) {
    -        if (c is an opening symbol)
    -            Push(c, S);
    -        else if (c is a closing symbol) {
    -            if (S is empty)  { ERROR; exit; }
    -            else  {  /* stack is okay */
    -                if  (Top(S) doesn’t match c)  { ERROR, exit; }
    -                else  Pop(S);
    -            }  /* end else-stack is okay */
    -        }  /* end else-if-closing symbol */
    -    } /* end while-loop */ 
    -    if (S is not empty)  ERROR;
    -}
    -
    -
      -
    1. -

      Postfix Evaluation 后缀表达式

      -
    2. -
    3. -

      Infix to Postfix Conversion

      -
    4. -
    5. -

      读到一个操作数时立即把它放到输出中

      -
    6. -
    7. 读到一个操作符时从栈中弹出栈元素直到发现优先级更低的元素为止,再将操作符压入栈中
    8. -
    9. The order of operands is the same in infix and postfix.
    10. -
    11. Operators with higher precedence appear before those with lower precedence.
    12. -
    13. Never pop a ’(‘ from the stack except when processing a ‘)’.
    14. -
    15. When ‘(’ is not in the stack, its precedence is the highest; but when it is in the stack, its precedence is the lowest.
    16. -
    17. -

      Exponentiation associates right to left.

      -
    18. -
    19. -

      Function Calls (System Stack)

      -
    20. -
    -

    3-2

    -
    -

    Note : Recursion can always be completely removed. Non recursive programs are generally faster than equivalent recursive programs. However, recursive programs are in general much simpler and easier to understand.

    -
    -
    -

    2.4 The Queue ADT

    -
      -
    • First-In-First-Out (FIFO)
    • -
    • Objects : A finite ordered list with zero or more elements.
    • -
    • Operations :
    • -
    • IsEmpty
    • -
    • CreatQueue
    • -
    • DisposeQueue
    • -
    • MakeEmpty
    • -
    • Enqueue
    • -
    • Front
    • -
    • Dequeue
    • -
    -

    Array Implementation of Queues

    -
    C
    1
    -2
    -3
    -4
    -5
    -6
    -7
    struct QueueRecord {
    -    int Capacity ;       /* max size of queue */
    -    int Front;           /* the front pointer */
    -    int Rear;            /* the rear pointer */
    -    int Size;            /* Optional - the current size of queue */
    -    ElementType *Array;  /* array for queue elements */
    - }; 
    -
    -

    Circular Queue :

    -

    3-33-4

    -
      -
    • The maximum capacity of this queue is 5.
    • -
    -
    -

    Note : Adding a Size field can avoid wasting one empty space to distinguish “full” from “empty”.

    -
    -
    -

    3 Trees

    -

    3.1 Preliminaries

    -

    [Definition] A tree is a collection of nodes. The collection can be empty; otherwise, a tree consists of (1) a distinguished node r, called the root; (2) and zero or more nonempty (sub)trees, each of whose roots are connected by a directed edge from r.

    -
      -
    • -

      Subtrees must not connect together. Therefore every node in the tree is the root of some subtree.

      -
    • -
    • -

      There are N-1 edges in a tree with N nodes

      -
    • -
    -

    Terminologies

    -
    -
      -
    • degree of a node : 结点的子树个数
    • -
    • degree of a tree : 结点的度的最大值
    • -
    • parent : 有子树的结点
    • -
    • children : the roots of the subtrees of a parent
    • -
    • siblings : children of the same parent
    • -
    • leaf(terminal node) : a node with degree 0(no children)
    • -
    • path from \(n_1\) to \(n_k\) : a unique sequence of nodes \(n_1,n_2,\cdots,n_k\) such that \(n_i\) is the parent of \(n_{i+1}\) for \(1\leq i<k\)
    • -
    • length of path : 路径上边的条数
    • -
    • depth of \(n_i\) : 从根结点到\(n_i\)结点的路径的长度(\(Depth(root)=0\))
    • -
    • height of \(n_i\) : 从\(n_i\)结点到叶结点的最长路径的长度(\(Height(leaf)=0\))
    • -
    • height/depth of a tree : 根结点的高度/最深的叶结点的深度
    • -
    • ancestors of a node : 从此结点到根结点的路径上的所有结点
    • -
    • descendants of a node : 此结点的子树中的所有结点
    • -
    -
    -

    List Representation

    -
      -
    • The size of each node depends on the number of branches.
    • -
    -

    4-2

    -

    The correct answer is T.

    -

    FirstChild-NextSibling Representation

    -

    4-1

    -
      -
    • The representation is not unique since the children in a tree can be of any order.
    • -
    -
    -

    3.2 Binary Trees

    -

    [Definition] A binary tree is a tree in which no node can have more than two children.

    -

    Tree Traversals (visit each node exactly once)

    -
      -
    1. Preorder Traversal
    2. -
    -
    Text Only
    1
    -2
    -3
    -4
    -5
    -6
    -7
    -8
    -9
    void preorder( tree_ptr tree )
    -{ 
    -    if( tree )   
    -    {
    -        visit ( tree );
    -        for (each child C of tree )
    -            preorder ( C );
    -    }
    -}
    -
    -
      -
    1. Postorder Traversal
    2. -
    -
    Text Only
    1
    -2
    -3
    -4
    -5
    -6
    -7
    -8
    -9
    void postorder( tree_ptr tree )
    -{  
    - if( tree )   
    - {
    -        for (each child C of tree )
    -         postorder ( C );
    -        visit ( tree );
    -    }
    -}
    -
    -
      -
    1. Levelorder Traversal
    2. -
    -
    Text Only
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    void levelorder( tree_ptr tree )
    -{   
    - enqueue ( tree );
    -    while (queue is not empty) 
    -    {
    -        visit ( T = dequeue ( ) );
    -        for (each child C of T )
    -            enqueue ( C );
    -    }
    -}
    -
    -
      -
    1. Inorder Traversal
    2. -
    -
    Text Only
    1
    -2
    -3
    -4
    -5
    -6
    -7
    -8
    -9
    void inorder( tree_ptr  tree )
    -{  
    - if( tree )   
    - {
    -     inorder ( tree->Left );
    -         visit ( tree->Element );
    -         inorder ( tree->Right );
    -   }
    -}
    -
    -

    Iterative Program :

    -
    Text Only
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    -14
    void iter_inorder( tree_ptr tree )
    -{ 
    - Stack  S = CreateStack( MAX_SIZE );
    - for ( ; ; )  
    - {
    -     for ( ; tree; tree = tree->Left )
    -         Push ( tree, S );
    -         tree = Top ( S );  
    -         Pop( S );
    -         if ( !tree ) break;
    -         visit ( tree->Element );
    -         tree = tree->Right; 
    -    }
    -}
    -
    -

    4-3

    -

    Threaded Binary Trees

    -
      -
    • -

      A full binary tree with \(n\) nodes has \(2n\) links, and \(n+1\) of them are NULL.

      -
    • -
    • -

      Replace the NULL links by “threads” which will make traversals easier.

      -
    • -
    -

    Rules :

    -
    -
      -
    • If Tree->Left is null, replace it with a pointer to the inorder predecessor(中序前驱) of Tree.
    • -
    • If Tree->Right is null, replace it with a pointer to the inorder successor(中序后继) of Tree.
    • -
    • There must not be any loose threads. Therefore a threaded binary tree must have a head node of which the left child points to the first node.
    • -
    -
    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    typedef struct ThreadedTreeNode *PtrToThreadedNode;
    -typedef struct PtrToThreadedNode ThreadedTree;
    -typedef struct ThreadedTreeNode 
    -{
    -    int LeftThread;        /* if it is TRUE, then Left */
    -    ThreadedTree Left;     /* is a thread, not a child ptr.*/
    -    ElementType Element;
    -    int RightThread;       /* if it is TRUE, then Right */
    -    ThreadedTree Right;    /* is a thread, not a child ptr.*/
    -}
    -
    -
      -
    • 线索化的实质就是将二叉链表中的空指针改为指向前驱或后继的线索。由于前驱和后继信息只有在遍历该二叉树时才能得到,所以,线索化的过程就是在遍历的过程中修改空指针的过程。
    • -
    -

    4-4

    -
      -
    • In a tree, the order of children does not matter. But in a binary tree, left child and right child are different.
    • -
    -

    Properties of Binary Trees

    -
    -
      -
    • The maximum number of nodes on level \(i\) is \(2^{i-1},i\geq1\).
    • -
    • The maximum number of nodes in a binary tree of depth \(k\) is \(2^k-1,k\geq1\).
    • -
    • For any nonempty binary tree, \(n_0 = n_2 + 1\) where \(n_0\) is the number of leaf nodes and \(n_2\) is the number of nodes of degree 2.
    • -
    -
    -
    -

    3.3 Binary Search Trees

    -

    [Definition] A binary search tree is a binary tree. It may be empty. If it is not empty, it satisfies the following properties:

    -
      -
    • 每个结点有一个互不不同的值
    • -
    • 若左子树非空,则左子树上所有结点的值均小于根结点的值
    • -
    • 若右子树非空,则右子树上所有结点的值均大于根结点的值
    • -
    • 左、右子树也是是一棵二叉查找树
    • -
    -

    ADT

    -
      -
    • Objects : A finite ordered list with zero or more elements.
    • -
    • Operations :
    • -
    • SearchTree MakeEmpty( SearchTree T )
    • -
    • Position Find( ElementType X, SearchTree T )
    • -
    • Position FindMin( SearchTree T )
    • -
    • Position FindMax( SearchTree T )
    • -
    • SearchTree Insert( ElementType X, SearchTree T )
    • -
    • SearchTree Delete( ElementType X, SearchTree T )
    • -
    • ElementType Retrieve( Position P )
    • -
    -

    Implementations

    -
      -
    1. Find
    2. -
    -
    Text Only
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    Position Find( ElementType X, SearchTree T ) 
    -{ 
    - if ( T == NULL ) 
    -     return NULL;  /* not found in an empty tree */
    -    if ( X < T->Element )  /* if smaller than root */
    -        return Find( X, T->Left );  /* search left subtree */
    -    else 
    -     if ( X > T->Element )  /* if larger than root */
    -         return  Find( X, T->Right );  /* search right subtree */
    -        else   /* if X == root */
    -         return  T;  /* found */
    -} 
    -
    -
      -
    • \(T(N)=S(N)=O(d)\) where \(d\) is the depth of X
    • -
    -

    Iterative program :

    -
    Text Only
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    Position Iter_Find( ElementType X, SearchTree T ) 
    -{ 
    - while ( T )
    - {
    -     if ( X == T->Element )  
    -         return T;  /* found */
    -        if ( X < T->Element )
    -            T = T->Left; /*move down along left path */
    -        else
    -             T = T-> Right; /* move down along right path */
    -    }  /* end while-loop */
    -    return NULL;   /* not found */
    -} 
    -
    -
      -
    1. FindMin
    2. -
    -
    Text Only
    1
    -2
    -3
    -4
    -5
    -6
    -7
    -8
    Position FindMin( SearchTree T ) 
    -{ 
    - if ( T == NULL )   
    -     return NULL; /* not found in an empty tree */
    -    else 
    -        if ( T->Left == NULL ) return T;  /* found left most */
    -        else return FindMin( T->Left );   /* keep moving to left */
    -} 
    -
    -
      -
    1. FindMax
    2. -
    -
    Text Only
    1
    -2
    -3
    -4
    -5
    -6
    -7
    Position FindMax( SearchTree T ) 
    -{ 
    - if ( T != NULL ) 
    -     while ( T->Right != NULL )   
    -         T = T->Right;   /* keep moving to find right most */
    -    return T;  /* return NULL or the right most */
    -} 
    -
    -
      -
    1. Insert
    2. -
    -
    Text Only
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    -14
    -15
    -16
    -17
    -18
    -19
    -20
    -21
    -22
    SearchTree Insert( ElementType X, SearchTree T ) 
    -{ 
    -    if ( T == NULL ) /* Create and return a one-node tree */ 
    -    { 
    -     T = malloc( sizeof( struct TreeNode ) ); 
    -     if ( T == NULL ) 
    -         FatalError( "Out of space!!!" ); 
    -     else 
    -     { 
    -         T->Element = X; 
    -         T->Left = T->Right = NULL; 
    -     } 
    -    }  /* End creating a one-node tree */
    -    else  /* If there is a tree */
    -         if ( X < T->Element ) 
    -         T->Left = Insert( X, T->Left ); 
    -     else 
    -         if ( X > T->Element ) 
    -             T->Right = Insert( X, T->Right ); 
    -     /* Else X is in the tree already; we'll do nothing */ 
    -    return  T;   /* Do not forget this line!! */ 
    -}
    -
    -
      -
    • 内存越界后不会马上报错,在下一次free或malloc时会失败
    • -
    • Handle duplicated keys
    • -
    • -

      \(T(N)=O(d)\)

      -
    • -
    • -

      Delete

      -
    • -
    • -

      Delete a leaf node : Reset its parent link to NULL

      -
    • -
    • Delete a degree 1 node : Replace the node by its single child
    • -
    • Delete a degree 2 node : 用左子树最大值结点或右子树最小值结点替换
    • -
    -
    Text Only
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    -14
    -15
    -16
    -17
    -18
    -19
    -20
    -21
    -22
    -23
    -24
    -25
    SearchTree Delete( ElementType X, SearchTree T ) 
    -{    
    - Position TmpCell; 
    -    if ( T == NULL ) Error( "Element not found" ); 
    -    else if ( X < T->Element )  /* Go left */ 
    -     T->Left = Delete( X, T->Left ); 
    -    else if ( X > T->Element )  /* Go right */ 
    -     T->Right = Delete( X, T->Right ); 
    - else  /* Found element to be deleted */ 
    -     if ( T->Left && T->Right ) {  /* Two children */ 
    -     /* Replace with smallest in right subtree */ 
    -         TmpCell = FindMin( T->Right ); 
    -         T->Element = TmpCell->Element; 
    -         T->Right = Delete( T->Element, T->Right );  } /* End if */
    -     else 
    -     {  /* One or zero child */ 
    -         TmpCell = T; 
    -         if ( T->Left == NULL ) /* Also handles 0 child */ 
    -             T = T->Right; 
    -         else if ( T->Right == NULL )  
    -             T = T->Left; 
    -         free( TmpCell );  
    -      }  /* End else 1 or 0 child */
    -      return  T; 
    -}
    -
    -
      -
    • \(T(N)=O(d)\)
    • -
    -
    -

    Note : If there are not many deletions, then lazy deletion may be employed: add a flag field to each node, to mark if a node is active or is deleted. Therefore we can delete a node without actually freeing the space of that node. If a deleted key is reinserted, we won’t have to call malloc again.

    -
    -
      -
    1. -

      Average-Case Analysis

      -
    2. -
    3. -

      The average depth over all nodes in a tree is \(O(logN)\) on the assumption that all trees are equally likely.

      -
    4. -
    5. \(n\)个元素存入二叉搜索树,树的高度将由插入序列决定
    6. -
    -

    5-1

    -

    The correct answer is A.

    -
    -

    4 Priority Queues (Heaps)

    -

    4.1 ADT Model

    -
      -
    • Objects :A finite ordered list with zero or more elements.
    • -
    • Operations :
    • -
    • PriorityQueue Initialize( int MaxElements );
    • -
    • void Insert( ElementType X, PriorityQueue H );
    • -
    • ElementType DeleteMin( PriorityQueue H );
    • -
    • ElementType FindMin( PriorityQueue H );
    • -
    -
    -

    4.2 Implementations

    -

    Array

    -
      -
    • -

      Insertion — add one item at the end ~\(\Theta(1)\)

      -
    • -
    • -

      Deletion — find the largest / smallest key ~\(\Theta(n)\)

      -
    • -
    -

    ​ remove the item and shift array ~\(O(n)\)

    -

    Linked List

    -
      -
    • -

      Insertion — add to the front of the chain ~\(\Theta(1)\)

      -
    • -
    • -

      Deletion — find the largest / smallest key ~\(\Theta(n)\)

      -
    • -
    -

    ​ remove the item ~\(\Theta(1)\)

    -
      -
    • Never more deletions than insertions
    • -
    -

    Ordered Array

    -
      -
    • Insertion — find the proper position ~\(O(\log n)\)
    • -
    -

    ​ shift array and add the item ~\(O(n)\)

    -
      -
    • Deletion — remove the first / last item ~\(\Theta(1)\)
    • -
    -

    Ordered Linked List

    -
      -
    • Insertion — find the proper position ~\(O(n)\)
    • -
    -

    ​ add the item ~\(\Theta(1)\)

    -
      -
    • Deletion — remove the first / last item ~\(\Theta(1)\)
    • -
    -

    Binary Search Tree

    -
      -
    • Both insertion and deletion will take \(O(\log N)\) only.
    • -
    • Only delete the the minimum element, always delete from the left subtrees.
    • -
    • Keep a balanced tree
    • -
    • But there are many operations related to AVL tree that we don't really need for a priority queue.
    • -
    -
    -

    4.3 Binary Heap

    -

    Structure Property

    -

    [Definition] A binary tree with \(n\) nodes and height \(h\) is complete if its nodes correspond to the nodes numbered from \(1\) to \(n\) in the perfect binary tree of height \(h\).

    -
      -
    • -

      A complete binary tree of height \(h\) has between \(2^h\) and \(2^{h+1}-1\) nodes.

      -
    • -
    • -

      \(h=\lfloor\log N\rfloor\)

      -
    • -
    • -

      Array Representation : BT[n + 1] ( BT[0] is not used)

      -
    • -
    -

    6-1

    -

    [Lemma]

    -
      -
    1. \(index\,of\,parent(i)=\left\{ - \begin{array}{rcl} - \lfloor i/2\rfloor && {i\neq1}\\ - None && {i=1}\\ - \end{array} \right.\)
    2. -
    3. \(index\,of\,left\_child(i)=\left\{ - \begin{array}{rcl} - 2i && {2i\leq n}\\ - None && {2i>n}\\ - \end{array} \right.\)
    4. -
    5. \(index\,of\,right\_child(i)=\left\{ - \begin{array}{rcl} - 2i+1 && {2i+1\leq n}\\ - None && {2i+1>n}\\ - \end{array} \right.\)
    6. -
    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    -14
    -15
    -16
    -17
    PriorityQueue Initialize( int MaxElements ) 
    -{ 
    -    PriorityQueue H; 
    -    if ( MaxElements < MinPQSize ) 
    -        return Error( "Priority queue size is too small" ); 
    -    H = malloc(sizeof( struct HeapStruct )); 
    -    if ( H == NULL ) 
    -        return FatalError( "Out of space!!!" ); 
    -    /* Allocate the array plus one extra for sentinel */ 
    -    H->Elements = malloc(( MaxElements + 1 ) * sizeof( ElementType )); 
    -    if ( H->Elements == NULL ) 
    -        return FatalError( "Out of space!!!" ); 
    -    H->Capacity = MaxElements; 
    -    H->Size = 0; 
    -    H->Elements[0] = MinData;  /* set the sentinel */
    -    return H; 
    -}
    -
    -

    Heap Order Property

    -

    [Definition] A min tree is a tree in which the key value in each node is no larger than the key values in its children (if any). A min heap is a complete binary tree that is also a min tree.

    -
      -
    • We can declare a max heap by changing the heap order property.
    • -
    -

    Basic Heap Operations

    -
      -
    1. Insertion
    2. -
    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    /*H->Element[ 0 ] is a sentinel that is no larger than the minimum element in the heap.*/ 
    -void Insert( ElementType X, PriorityQueue H ) 
    -{ 
    - int i; 
    -    if ( IsFull( H )) 
    -    { 
    -     Error( "Priority queue is full" ); 
    -     return; 
    -    } 
    -    for ( i = ++H->Size; H->Elements[ i/2 ] > X; i /= 2 ) 
    -     H->Elements[ i ] = H->Elements[ i/2 ]; /*Percolate up, faster than swap*/
    -    H->Elements[ i ] = X; 
    -}
    -
    -

    $$ - T(N)=O(\log N) - $$

    -
      -
    1. DeleteMin
    2. -
    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    -14
    -15
    -16
    -17
    -18
    -19
    -20
    -21
    -22
    -23
    -24
    ElementType DeleteMin( PriorityQueue H ) 
    -{ 
    -    int i, Child; 
    -    ElementType MinElement, LastElement; 
    -    if ( IsEmpty( H ) ) 
    -    { 
    -        Error( "Priority queue is empty" ); 
    -        return H->Elements[ 0 ];   
    -    } 
    -    MinElement = H->Elements[ 1 ];  /*Save the min element*/
    -    LastElement = H->Elements[ H->Size-- ];  /*Take last and reset size*/
    -    for ( i = 1; i * 2 <= H->Size; i = Child )  /*Find smaller child*/ 
    -    {
    -        Child = i * 2; 
    -        if (Child != H->Size && H->Elements[Child+1] < H->Elements[Child]) 
    -             Child++;     
    -        if ( LastElement > H->Elements[ Child ] )   /*Percolate one level*/ 
    -             H->Elements[ i ] = H->Elements[ Child ]; 
    -        else     
    -         break;   /*Find the proper position*/
    -    } 
    -    H->Elements[ i ] = LastElement; 
    -    return MinElement; 
    -}
    -
    -
    \[ -T(N)=O(\log N) -\]
    -

    Other Heap Operations

    -
      -
    • -

      查找除最小值之外的值需要对整个堆进行线性扫描

      -
    • -
    • -

      DecreaseKey — Percolate up

      -
    • -
    • -

      IncreaseKey — Percolate down

      -
    • -
    • -

      Delete

      -
    • -
    • -

      BuildHeap

      -
    • -
    -

    将N 个关键字以任意顺序放入树中,保持结构特性,再执行下滤

    -
    C
    1
    -2
    for (i = N/2; i > 0; i--)
    - PercolateDown(i);
    -
    -

    $$ - T(N)=O(N) - $$

    -

    [Theorem] For the perfect binary tree of height \(h\) containing \(2^{h+1}-1\) nodes, the sum of the heights of the nodes is \(2^{h+1}-1-(h+1)\).

    -

    image-20210125151728720

    -
    -

    4.4 Applications of Priority Queues

    -

    Heap Sort

    -

    查找一个序列中第k小的元素

    -

    The function is to find the K-th smallest element in a list A of N elements. The function BuildMaxHeap(H, K) is to arrange elements H[1] ... H[K] into a max-heap.

    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    -14
    -15
    -16
    -17
    -18
    -19
    -20
    -21
    -22
    -23
    -24
    ElementType FindKthSmallest ( int A[], int N, int K )
    -{   /* it is assumed that K<=N */
    -    ElementType *H;
    -    int i, next, child;
    -
    -    H = (ElementType*)malloc((K+1)*sizeof(ElementType));
    -    for ( i = 1; i <= K; i++ ) H[i] = A[i-1];
    -    BuildMaxHeap(H, K);
    -
    -    for ( next = K; next < N; next++ ) {
    -        H[0] = A[next];
    -        if ( H[0] < H[1] ) {
    -            for ( i = 1; i*2 <= K; i = child ) {
    -                child = i*2;
    -                if ( child != K && H[child+1] > H[child] ) child++;
    -                if ( H[0] < H[child] )
    -                    H[i] = H[child];
    -                else break;
    -            }
    -            H[i] = H[0];
    -        }
    -    }
    -    return H[1];
    -}
    -
    -
    -

    4.5 \(d\)-Heaps — All nodes have \(d\) children

    -

    Note :

    -
    -
      -
    • DeleteMin will take \(d-1\) comparisons to find the smallest child. Hence the total time complexity would be \(O(d \log_d N)\).
    • -
    • 2 or /2 is merely *a bit shift**, but *d or /d is not.
    • -
    • When the priority queue is too large to fit entirely in main memory, a d-heap will become interesting.
    • -
    -
    -

    6-2

    -

    image-20210125070700824

    -

    正确答案是4,注意“in the process”

    -
    -

    5 The Disjoint Set

    -

    5.1 Equivalence Relations

    - -

    [Definition] A relation, ~, over a set, S, is said to be an equivalence relation over S if it is symmetric, reflexive, and transitive over S.

    -

    [Definition] Two members x and y of a set S are said to be in the same equivalence class if x ~ y.

    -
    -

    5.2 The Dynamic Equivalence Problem

    -
      -
    • Given an equivalence relation ~, decide for any a and b if a ~ b
    • -
    -
    Text Only
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    -14
    -15
    -16
    Algorithm: (Union/Find)
    -{
    -  /* step 1: read the relations in */
    -    Initialize N disjoint sets;
    -    while ( read in a ~ b )
    -    {
    -      if ( !(Find(a) == Find(b)) )  /*Dynamic(on-line)*/
    -          Union the two sets;
    -    } /* end-while */
    -    /* step 2: decide if a ~ b */
    -    while ( read in a and b )
    -        if ( Find(a) == Find(b) )
    -          output( true );
    -        else   
    -          output( false );
    -}
    -
    -
      -
    • -

      Elements of the sets : \(1,2,3,\cdots,N\)

      -
    • -
    • -

      Sets : \(S_1,S_2,\cdots\,and\,S_i\bigcap S_j=\emptyset\,(if\quad i\neq j)\)

      -
    • -
    • -

      Operations :

      -
    • -
    • -

      Union( \(i, j\) ) = Replace \(S_i\) and \(S_j\) by \(S=S_i\bigcup S_j\)

      -
    • -
    • Find( \(i\) ) = Find the set \(S_k\) which contains the element \(i\)
    • -
    -
    -

    5.3 Basic Data Structure

    -

    Union( \(i, j\) )

    -
      -
    • -

      Make \(S_i\) a subtree of \(S_j\), or vice versa, that is to set the parent pointer of one of the roots to the other root.

      -
    • -
    • -

      Implementation 1 :

      -
    • -
    -

    7-1

    -
      -
    • -

      Implementation 2 :

      -
    • -
    • -

      The elements are numbered from 1 to N, hence they can be used as indices of an array.

      -
    • -
    • -

      S[ element ] = the element’s parent

      -
    • -
    • -

      Note : S[ root ] = 0 and set name = root index

      -
    • -
    • 数组初始化全部为0
    • -
    -
    C
    1
    -2
    -3
    -4
    void SetUnion(DisjSet S, SetType Rt1, SetType Rt2)
    -{
    -  S[Rt2] = Rt1;
    -}
    -
    -

    Find( \(i\) )

    -
      -
    • Implementation 1 :
    • -
    -

    7-2

    -
      -
    • Implementation 2 :
    • -
    -
    C
    1
    -2
    -3
    -4
    -5
    SetType Find(ElementType X, DisjSet S)
    -{
    -  for ( ; S[X]>0; X=S[X]);
    -  return X;
    -}
    -
    -

    Analysis

    -
      -
    • Union and find are always paired. Thus we consider the performance of a sequence of union-find operations.
    • -
    -

    7-3

    -
    Text Only
    1
    -2
    -3
    -4
    -5
    -6
    -7
    -8
    -9
    Algorithm using union-find operations:
    -{  
    -    Initialize Si = { i }  for  i = 1, ..., 12 ;
    -    for ( k = 1; k <= 9; k++ )  /* for each pair i R j */
    -    {
    -        if ( Find( i ) != Find( j ) )
    -            SetUnion( Find( i ), Find( j ) );
    -    }
    -}
    -
    -
      -
    • Worst case : \(T(N)=\Theta(N^2)\)
    • -
    -
    -

    5.4 Smart Union Algorithms

    -

    Union-by-Size

    -
      -
    • -

      Always change the smaller tree

      -
    • -
    • -

      S[Root] = -size, initialized to be -1

      -
    • -
    • -

      [Lemma] Let T be a tree created by union-by-size with N nodes, then \(height(T)\leq\lfloor\log_2N\rfloor+1\).

      -
    • -
    -

    Proved by induction. Each element can have its set name changed at most \(\log_2N\) times.

    -
      -
    • Time complexity of \(N\) Union and \(M\) Find operations is now \(O(N+M\log_2N)\).
    • -
    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    -14
    /* Assumes Rootl and Root2 are roots*/
    -void SetUnion(DisjSet S, SetType Root1, SetType Root2)
    -{
    -    if (S[Root1] <= S[Root2])
    -    {
    -        S[Root1] += S[Root2];
    -        S[Root2] = Root1;
    -    }
    -    else
    -    {
    -        S[Root2] += S[Root1];
    -        S[Root1] = Root2;
    -    }
    -}
    -
    -

    Union-by-Height

    -
      -
    • Always change the shallow tree
    • -
    • 保证所有的树的深度最多是\(O(logN)\)
    • -
    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    /* Assumes Rootl and Root2 are roots*/
    -void SetUnion(DisjSet S, SetType Root1, SetType Root2)
    -{
    -    if ( S[Root2] < S[Root1])  /*Root2 is deeper set*/
    -        S[Root1] = Root2;      /*Make Root2 new root*/
    -    else
    -    {
    -        if (S[Root1] == S[Root2])  /*Same height*/
    -            S[Root1]--;
    -        S[Root2] = Root1;
    -    }
    -}
    -
    -
    -

    5.5 Path Compression

    -
      -
    • 从X到Root的路径上的每一个结点都使它的父结点变成Root
    • -
    -
    C
    1
    -2
    -3
    -4
    -5
    -6
    -7
    SetType Find( ElementType X, DisjSet S )
    -{
    -    if ( S[ X ] <= 0 )    
    -        return X;
    -    else 
    -        return S[ X ] = Find( S[ X ], S );
    -}
    -
    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    SetType Find( ElementType X, DisjSet S )
    -{   
    -    ElementType root, trail, lead;
    -    for ( root = X; S[ root ] > 0; root = S[ root ] );  /* find the root */
    -    for ( trail = X; trail != root; trail = lead )
    -    {
    -        lead = S[ trail ];   
    -        S[ trail ] = root;   
    -    }  /* collapsing */
    -    return root;
    -}
    -
    -
      -
    • Note : Not compatible with union-by-height since it changes the heights. Just take “height” as an estimated rank.
    • -
    -
    -

    5.6 Worst Case for Union-by-Rank and Path Compression

    -

    [Lemma] Let \(T(M,N)\) be the maximum time required to process an intermixed sequence of \(M\geq N\) finds and \(N-1\) unions, then \(k_1M\alpha(M,N)\leq T(M,N)\leq k_2M\alpha(M,N)\) for some positive constants \(k_1\) and \(k_2\).

    -
      -
    • Ackermann’s Function - $$ - A(i,j)=\left{ - \begin{array}{rcl} - 2^j && {i=1,j\geq1}\ - A(i-1,2) && {i\geq2,j=1}\ - A(i-1,A(i,j-1)) && {i\geq2,j\geq2}\ - \end{array} \right. - $$
    • -
    -

    $$ - A(2,4)=2^{2^{2^{2^2}}}=2^{65536} - $$

    -
      -
    • \(\alpha(M,N)=min\{i\geq1|A(i,\lfloor M/N\rfloor)>\log N\}\leq O(\log^*N)\leq4\)
    • -
    -

    \(\log^*N\) (inverse Ackermann function) = number of times the logarithm is applied to \(N\) until the result \(\leq1\).

    -
    -

    5.7 Conclusion

    -

    一共有五种算法,注意看清题设

    -
      -
    • -

      No smart union

      -
    • -
    • -

      Union-by-size

      -
    • -
    • -

      Union-by-height

      -
    • -
    • -

      Union-by-size + Path Compression

      -
    • -
    • -

      Union-by-height + Path Compression

      -
    • -
    -
    -

    6 Graph Algorithms

    -

    6.1 Definitions

    -
      -
    • \(G( V, E )\) where \(G\) = graph, \(V = V( G )\) = finite nonempty set of vertices, and \(E = E( G )\) = finite set of edges.
    • -
    -

    Undirected graph

    -
      -
    • \(( v_i , v_j ) = ( v_j , v_i )\) = the same edge.
    • -
    -

    Directed graph(diagraph)

    -

    8-1

    -

    Restrictions

    -
      -
    • Self loop is illegal.
    • -
    • Multigraph is not considered.
    • -
    -

    Complete graph

    -
      -
    • A graph that has the maximum number of edges.
    • -
    -

    image-20210124163038265

    -

    Adjacent

    -

    image-20210124163324744

    -

    image-20210124163301833

    -

    Subgraph

    -
    \[ -G'\subset G=V(G')\subseteq V(G) \&\& E(G')\subseteq E(G) -\]
    -

    Path

    -
      -
    • Path(\(\subset G\)) from \(v_p\) to \(v_q\) = \(\{v_p,v_{i1},v_{i2},\cdots,v_{in},v_q\}\) such that \((v_p,v_{i1}),(v_{i1},v_{i2}),\cdots,(v_{in},v_q)\) belong to \(E(G)\)
    • -
    -

    Length of a path

    -
      -
    • number of edges on the path
    • -
    -

    Simple path

    -
      -
    • \(v_{i1},v_{i2},\cdots,v_{in}\) are distinct.
    • -
    -

    Cycle

    -
      -
    • simple path with \(v_p=v_q\)
    • -
    -

    Connected

    -
      -
    • \(v_i\) and \(v_j\) in an undirected \(G\) are connected if there is a path from \(v_i\) to \(v_j\) (and hence there is also a path from \(v_j\) to \(v_i\))
    • -
    • An undirected graph \(G\) is connected if every pair of distinct \(v_i\) and \(v_j\) are connected
    • -
    -

    (Connected) Component of an undirected G

    -
      -
    • the maximal connected subgraph
    • -
    -

    Tree

    -
      -
    • a graph that is connected and acyclic(非循环的)
    • -
    -

    DAG

    -
      -
    • a directed acyclic graph
    • -
    -

    Strongly connected directed graph G

    -
      -
    • For every pair of \(v_i\) and \(v_j\) in \(V( G )\), there exist directed paths from \(v_i\) to \(v_j\) and from \(v_j\) to \(v_i\).
    • -
    • If the graph is connected without direction to the edges, then it is said to be weakly connected
    • -
    -

    Strongly connected component

    -
      -
    • the maximal subgraph that is strongly connected
    • -
    -

    Degree

    -
      -
    • -

      number of edges incident to v

      -
    • -
    • -

      For a directed G, we have in-degree and out-degree.

      -
    • -
    • -

      Given G with \(n\) vertices and \(e\) edges, then - $$ - e=(\sum_{i=0}^{n-1}d_i)/2\quad where\quad d_i=degree(v_i) - $$

      -
    • -
    -
    -

    6.2 Representation of Graphs

    -

    Adjacency Matrix

    -

    image-20210124163641976

    -
    -

    Note : If G is undirected, then adj_mat[][] is symmetric. Thus we can save space by storing only half of the matrix.

    -
    -

    image-20210123194735917

    -
      -
    • -

      This representation wastes space if the graph has a lot of vertices but very few edges.

      -
    • -
    • -

      To find out whether or not \(G\) is connected, we’ll have to examine all edges. In this case \(T\) and \(S\) are both \(O( n^2 )\).

      -
    • -
    -

    Adjacency Lists

    -
      -
    • Replace each row by a linked list
    • -
    -

    image-20210124164723362

    -
    -

    Note : The order of nodes in each list does not matter.

    -
    -
      -
    • For undirected \(G\), \(S\) = \(n\) heads + \(2e\) nodes = \((n+2e)\) ptrs + \(2e\) ints
    • -
    • Degree(i) = number of nodes in graph[i](if \(G\) is undirected)
    • -
    • \(T\) of examine \(E(G)\) = \(O(n+e)\)
    • -
    -

    image-20210124165346405

    -

    Adjacency Multilists

    -

    image-20210124164607434

    -
      -
    • Sometimes we need to mark the edge after examine it, and then find the next edge.
    • -
    -

    Weighted Edges

    -
      -
    • adj_mat [ i ] [ j ] = weight
    • -
    • adjacency lists / multilists : add a weight field to the node
    • -
    -
    -

    6.3 Topological Sort

    -

    AOV Network

    -
      -
    • digraph \(G\) in which \(V( G )\) represents activities and \(E( G )\) represents precedence relations
    • -
    • Feasible AOV network must be a directed acyclic graph.
    • -
    • \(i\) is a predecessor of \(j\) = there is a path from \(i\) to \(j\)
    • -
    • \(i\) is an immediate predecessor of \(j\) = \(< i, j > \in E( G )\). Then \(j\) is called a successor(immediate successor) of \(i\)
    • -
    -

    Partial order

    -
      -
    • a precedence relation which is both transitive and irreflexive
    • -
    -
    -

    Note : If the precedence relation is reflexive, then there must be an \(i\) such that \(i\) is a predecessor of \(i\). That is, \(i\) must be done before \(i\) is started. Therefore if a project is feasible, it must be irreflexive.

    -
    -

    [Definition] A topological order is a linear ordering of the vertices of a graph such that, for any two vertices, \(i\), \(j\), if \(i\) is a predecessor of \(j\) in the network then \(i\) precedes \(j\) in the linear ordering.

    -
    -

    Note : The topological orders may not be unique for a network.

    -
    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    -14
    -15
    -16
    -17
    -18
    /*Test an AOV for feasibility, and generate a topological order if possible*/
    -void Topsort( Graph G )
    -{   
    -    int Counter;
    -    Vertex V, W;
    -    for ( Counter = 0; Counter < NumVertex; Counter++ ) 
    -    {
    -        V = FindNewVertexOfDegreeZero( );
    -        if ( V == NotAVertex ) 
    -        {
    -            Error ( Graph has a cycle );   
    -            break;  
    -        }
    -        TopNum[ V ] = Counter; /* or output V */
    -        for ( each W adjacent to V )
    -            Indegree[ W ]––;
    -    }
    -}
    -
    -
    \[ -T=O(|V|^2) -\]
    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    -14
    -15
    -16
    -17
    -18
    -19
    -20
    -21
    /*Improvment:Keep all the unassigned vertices of degree 0 in a special box (queue or stack)*/
    -void Topsort( Graph G )
    -{   
    -    Queue Q;
    -    int Counter = 0;
    -    Vertex V, W;
    -    Q = CreateQueue( NumVertex );  
    -    MakeEmpty( Q );
    -    for ( each vertex V )
    -        if ( Indegree[ V ] == 0 ) Enqueue( V, Q );
    -    while ( !IsEmpty( Q ) ) 
    -    {
    -        V = Dequeue( Q );
    -        TopNum[ V ] = ++Counter; /* assign next */
    -        for ( each W adjacent to V )
    -            if (––Indegree[ W ] == 0 ) Enqueue( W, Q );
    -    }  /* end-while */
    -    if ( Counter != NumVertex )
    -    Error( Graph has a cycle );
    -    DisposeQueue( Q ); /* free memory */
    -}
    -
    -
    \[ -T=O(|V|+|E|) -\]
    -
    -

    6.4 Shortest Path Algorithms

    -

    Given a digraph \(G = ( V, E )\), and a cost function \(c( e )\) for \(e \in E( G )\).

    -

    The length of a path \(P\) from source to destination is \(\sum_{e_i\subset P} c(e_i)\)(also called weighted path length).

    -

    Single-Source Shortest-Path Problem

    -

    Given as input a weighted graph, \(G = ( V, E )\), and a distinguished vertex \(s\), find the shortest weighted path from \(s\) to every other vertex in \(G\).

    -
    -

    Note: If there is no negative-cost cycle, the shortest path from \(s\) to \(s\) is defined to be zero.

    -
    -
    Unweighted Shortest Path
    -
      -
    • Breadth-first search 广度优先遍历
    • -
    -

    Implementation :

    -
      -
    • Table[ i ].Dist ::= distance from \(s\) to \(v_i\) /* initialized to be \(\infin\) except for \(s\) */
    • -
    • Table[ i ].Known ::= 1 if \(v_i\) is checked; or 0 if not
    • -
    • Table[ i ].Path ::= for tracking the path /* initialized to be 0 */
    • -
    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    -14
    -15
    -16
    -17
    -18
    -19
    void Unweighted( Table T )
    -{   
    -    int CurrDist;
    -    Vertex V, W;
    -    for ( CurrDist = 0; CurrDist < NumVertex; CurrDist++ ) 
    -    {
    -        for ( each vertex V )
    -            if ( !T[ V ].Known && T[ V ].Dist == CurrDist ) 
    -            {
    -                T[ V ].Known = true;
    -                for ( each W adjacent to V )
    -                    if ( T[ W ].Dist == Infinity ) 
    -                    {
    -                        T[ W ].Dist = CurrDist + 1;
    -                        T[ W ].Path = V;
    -                    } /* end-if Dist == Infinity */
    -            } /* end-if !Known && Dist == CurrDist */
    -    }  /* end-for CurrDist */
    -}
    -
    -

    The worst case :

    -

    9-1 -$$ -T(N)=O(|V|^2) -$$ -Improvement :

    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    -14
    -15
    -16
    -17
    -18
    -19
    -20
    -21
    -22
    void Unweighted( Table T )
    -{   
    -    /* T is initialized with the source vertex S given */
    -    Queue Q;
    -    Vertex V, W;
    -    Q = CreateQueue( NumVertex );
    -    MakeEmpty( Q );
    -    Enqueue( S, Q ); /* Enqueue the source vertex */
    -    while ( !IsEmpty( Q ) ) 
    -    {
    -        V = Dequeue( Q );
    -        T[ V ].Known = true; /* not really necessary */
    -        for ( each W adjacent to V )
    -            if ( T[ W ].Dist == Infinity ) 
    -            {
    -                T[ W ].Dist = T[ V ].Dist + 1;
    -                T[ W ].Path = V;
    -                Enqueue( W, Q );
    -            } /* end-if Dist == Infinity */
    -    } /* end-while */
    -    DisposeQueue( Q ); /* free memory */
    -}
    -
    -
    \[ -T=O(|V|+|E|) -\]
    -
    Weighted Shorted Path
    -
    Dijkstra’s Algorithm
    -
      -
    • Let S = { \(s\) and \(v_i\)’s whose shortest paths have been found }
    • -
    • For any \(u\notin S\), define distance [ u ] = minimal length of path { \(s\rightarrow(v_i\in S)\rightarrow u\) }. If the paths are generated in non-decreasing order, then :
    • -
    • the shortest path must go through only \(v_i\in S\)
    • -
    • Greedy Method : \(u\) is chosen so that distance[ u ] = min{ \(w \notin S\) | distance[ w ] } (If \(u\) is not unique, then we may select any of them)
    • -
    • if distance[\(u_1\)] < distance[\(u_2\)] and add \(u_1\) into \(S\), then distance [ \(u_2\) ] may change. If so, a shorter path from \(s\) to \(u_2\) must go through \(u_1\) and distance [ \(u_2\) ] = distance [ \(u_1\) ] + length(< \(u_1\), \(u_2\)>).
    • -
    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    typedef int Vertex;
    -struct TableEntry
    -{
    -    List Header; /*Adjacency list*/
    -    int Known;
    -    DistType Dist;
    -    Vertex Path;
    -};
    -/*Vertices are numbered from 0*/
    -#define NotAVertex (-1)
    -typedef struct TableEntry Table[ NumVertex ];
    -
    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    void InitTable(Vertex Start, Graph G, Table T)
    -{ 
    -    int i;
    -    ReadGraph(G, T); /* Read graph somehow */
    -    for(i = 0; i < NumVertex; i++)
    -    {
    -        T[ i ].Known = False;
    -        T[ i ].Dist = Infinity;
    -        T[ i ].Path = NotAVertex;
    -    }
    -    T[ Start ].dist = O;
    -}
    -
    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    /*Print shortest path to V after Dijkstra has run*/
    -/*Assume that the path exists*/
    -void PrintPath(Vertex V, Table T)
    -{
    -    if (T[ V ].Path != NotAVertex)
    -    {
    -        PrintPath(T[ V ].Path, T);
    -        printf(" to") ;
    -    }
    -    printf("%v", V) ; /* %v is pseudocode * /
    -
    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    -14
    -15
    -16
    -17
    void Dijkstra( Table T )
    -{ 
    -    Vertex V, W;
    -    for ( ; ; ) 
    -    {
    -        V = smallest unknown distance vertex;
    -        if ( V == NotAVertex ) break; 
    -        T[ V ].Known = true;
    -        for ( each W adjacent to V )
    -            if ( !T[ W ].Known ) 
    -                if ( T[ V ].Dist + Cvw < T[ W ].Dist ) 
    -                {
    -                    Decrease( T[ W ].Dist to T[ V ].Dist + Cvw );
    -                    T[ W ].Path = V;
    -                } /* end-if update W */
    -    } /* end-for( ; ; ) */
    -}
    -
    -
    Implementation 1
    -
      -
    • Simply scan the table to find the smallest unknown distance vertex.——\(O(|V|)\)
    • -
    • Good if the graph is dense
    • -
    -
    \[ -T=O(|V|^2+|E|) -\]
    -
    Implementation 2
    -
      -
    • -

      堆优化

      -
    • -
    • -

      Keep distances in a priority queue and call DeleteMin to find the smallest unknown distance vertex.——\(O(\log|V|)\)

      -
    • -
    • -

      更新的处理方法

      -
    • -
    • -

      Method 1 : DecreaseKey——\(O(\log|V|)\)

      -

      \(T=O(|V|\log|V|+|E|\log|V|)=O(|E|\log|V|)\)

      -
    • -
    • -

      Method 2 : insert W with updated Dist into the priority queue

      -

      Must keep doing DeleteMin until an unknown vertex emerges

      -

      \(T=O(|E|\log|V|)\) but requires \(|E|\) DeleteMin with |E| space

      -
    • -
    • -

      Good if the graph is sparse

      -
    • -
    -
    Improvements
    -
      -
    • Pairing heap
    • -
    • Fibonacci heap
    • -
    -
    Graphs with Negative Edge Costs
    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    -14
    -15
    -16
    -17
    -18
    -19
    -20
    -21
    void WeightedNegative( Table T )
    -{
    -    Queue Q;
    -    Vertex V, W;
    -    Q = CreateQueue (NumVertex );  
    -    MakeEmpty( Q );
    -    Enqueue( S, Q ); /*Enqueue the source vertex*/
    -    while ( !IsEmpty( Q ) ) 
    -    {
    -        V = Dequeue( Q );
    -        for ( each W adjacent to V )
    -        if ( T[ V ].Dist + Cvw < T[ W ].Dist ) 
    -        {
    -            T[ W ].Dist = T[ V ].Dist + Cvw;
    -            T[ W ].Path = V;
    -            if ( W is not already in Q )
    -                Enqueue( W, Q );
    -        } /*end-if update*/
    -    } /*end-while */
    -    DisposeQueue( Q ); /*free memory*/
    -}
    -
    -
    -

    Note : Negative-cost cycle will cause indefinite loop

    -
    -
    \[ -T=O(|V|\times|E|) -\]
    -
    Acyclic Graphs
    -
      -
    • If the graph is acyclic, vertices may be selected in topological order since when a vertex is selected, its distance can no longer be lowered without any incoming edges from unknown nodes.
    • -
    • \(T=O(|E|+|V|)\) and no priority queue is needed.
    • -
    -
    AOE(Activity on Edge) Networks
    -

    image-20210124185420522

    -

    image-20210124185541801

    -

    image-20210124185508683

    -

    All-Pairs Shortest Path Problem

    -
      -
    • For all pairs of \(v_i\) and \(v_j\) ( \(i\neq j\) ), find the shortest path between.
    • -
    -
    Method 1
    -
      -
    • Use single-source algorithm for \(|V|\) times.
    • -
    • \(T=O(|V|^3)\), works fast on sparse graph.
    • -
    -
    Method 2
    -
      -
    • 动态规划
    • -
    • \(O(|V|^3)\) algorithm given in Chapter 10, works faster on dense graphs.
    • -
    -
    -

    6.5 Network Flow Problems

    -

    image-20201206175230349

    -
      -
    • Determine the maximum amount of flow that can pass from \(s\) to \(t\).
    • -
    -
    -

    Note : Total coming in (\(v\)) = Total going out (\(v\)) where \(v \notin \{ s, t \}\)

    -
    -

    A Simple Algorithm

    -
      -
    • 流图\(G_f\)表示算法的任意阶段已经达到的流,开始时\(G_f\)的所有边都没有流,算法终止时\(G_f\)包含最大流
    • -
    • 残余图(residual graph)\(G_r\)表示对于每条边还能添加上多少流,\(G_r\)的边叫做残余边(residual edge)
    • -
    -
    -

    Step 1 : Find any path from \(s\) to \(t\) in \(G_r\) , which is called augmenting path(增长通路).

    -

    Step 2 : Take the minimum edge on this path as the amount of flow and add to \(G_f\).

    -

    Step 3 : Update \(G_r\) and remove the 0 flow edges.

    -

    Step 4 : If there is a path from \(s\) to \(t\) in \(G_r\) then go to Step 1, or end the algorithm.

    -
    -
      -
    • Step 1中初始选择的路径可能使算法不能找到最优解,贪心算法行不通
    • -
    -

    A solution

    -
      -
    • allow the algorithm to undo its decisions
    • -
    • For each edge \(( v, w )\) with flow \(f_{v, w}\) in \(G_f\), add an edge \(( w, v )\) with flow \(f_{v, w}\) in \(G_r\) .
    • -
    -
    -

    Note : The algorithm works for \(G\) with cycles as well.

    -
    -
    [Proposition] If the edge capabilities are rational numbers, this algorithm always terminate with a maximum flow.
    -

    Analysis

    -
      -
    • -

      An augmenting path can be found by an unweighted shortest path algorithm.

      -
    • -
    • -

      \(T=O(f|E|)\) where \(f\) is the maximum flow.

      -
    • -
    • -

      Always choose the augmenting path that allows the largest increase in flow

      -
    • -
    • -

      对Dijkstra算法进行单线(single-line)修改来寻找增长通路

      -
    • -
    • \(cap_{max}\)为最大边容量
    • -
    • \(O(|E|\log cap_{max})\)条增长通路将足以找到最大流,对于增长通路的每次计算需要\(O(|E|\log|V|)\)时间
    • -
    -

    $$ - T=T_{augmentation}\times T_{find_a_path}\ - =O(|E|\log cap_{max})\times O(|E|\log|V|)\ - =O(|E|^2\log|V|\log cap_{max}) - $$

    -
      -
    • -

      Always choose the augmenting path that has the least number of edges

      -
    • -
    • -

      使用无权最短路算法来寻找增长路径

      -
    • -
    -

    $$ - T=T_{augmentation}\times T_{find_a_path}\ - =O(|E||V|)\times O(|E|)\ - =O(|E|^2|V|) - $$

    -
    -

    Note :

    -
      -
    • If every \(v \notin \{ s, t \}\) has either a single incoming edge of capacity 1 or a single outgoing edge of capacity 1, then time bound is reduced to \(O( |E| |V|^{1/2} )\).
    • -
    • The min-cost flow problem is to find, among all maximum flows, the one flow of minimum cost provided that each edge has a cost per unit of flow.
    • -
    -
    -
    -

    6.6 Minimum Spanning Tree

    -
    [Definition] A spanning tree of a graph \(G\) is a tree which consists of \(V(G)\) and a subset of \(E(G)\)
    -
    -

    Note :

    -
      -
    • The minimum spanning tree is a tree since it is acyclic, the number of edges is \(|V|-1\)
    • -
    • It is minimum for the total cost of edges is minimized.
    • -
    • It is spanning because it covers every vertex.
    • -
    • A minimum spanning tree exists if \(G\) is connected.
    • -
    • Adding a non-tree edge to a spanning tree, we obtain a cycle.
    • -
    -
    -
    Greedy Method
    -

    Make the best decision for each stage, under the following constrains :

    -
    -
      -
    • we must use only edges within the graph
    • -
    • we must use exactly \(|V|-1\) edges
    • -
    • we may not use edges that would produce a cycle
    • -
    -
    -
      -
    1. -

      Prim’s Algorithm

      -
    2. -
    3. -

      在算法的任一时刻,都可以看到一个已经添加到树上的顶点集,而其余顶点尚未加到这棵树中

      -
    4. -
    5. -

      算法在每一阶段都可以通过选择边\((u, v)\),使得\((u,v)\)的值是所有\(u\) 在树上但\(v\)不在树上的边的值中的最小者,而找出一个新的顶点并把它添加到这棵树中

      -
    6. -
    7. -

      Kruskal’s Algorithm

      -
    8. -
    9. -

      连续地按照最小的权选择边,,并且当所选的边不产生环时就把它作为取定的边

      -
      Text Only
       1
      - 2
      - 3
      - 4
      - 5
      - 6
      - 7
      - 8
      - 9
      -10
      -11
      -12
      -13
      -14
      -15
      void Kruskal( Graph G )
      -{   
      -   T = { };
      -    while ( T contains less than |V|-1 edges && E is not empty ) 
      -    {
      -        choose a least cost edge (v, w) from E;  /*DeleteMin*/
      -        delete (v, w) from E;
      -        if ( (v, w) does not create a cycle in T )     
      -           add (v, w) to T;  /*Union/Find*/
      -        else     
      -           discard (v, w);
      -    }
      -    if ( T contains fewer than |V|-1 edges )
      -       Error( “No spanning tree” );
      -}
      -
      -
      C
       1
      - 2
      - 3
      - 4
      - 5
      - 6
      - 7
      - 8
      - 9
      -10
      -11
      -12
      -13
      -14
      -15
      -16
      -17
      -18
      -19
      -20
      -21
      -22
      -23
      -24
      -25
      -26
      -27
      void Kruskal(Graph G)
      -{
      -   int EdgesAccepted;
      -   DisjSet S;
      -   PriorityQueue H;
      -   Vertex U, V;
      -   SetType Uset, Vset;
      -   Edge E;
      -
      -   Initialize(S);
      -   ReadGraphIntoHeapArray(G, H);
      -   BuildHeap(H);
      -
      -   EdgesAccepted = 0;
      -   while(EdgesAccepted < NumVertex-1)
      -   {
      -       E = DeleteMin(H); /*E = (U,V)*/
      -       Uset = Find(U, S);
      -       Vset = Find(V, S);
      -       if(Uset != Vset)
      -       {
      -           /*Accept the edge*/
      -           EdgesAccepted++;
      -           SetUnion(S, USet, VSet);
      -       }
      -   }
      -}
      -
      -

      $$ - T=O(|E|\log|E|) - $$

      -

      image-20210124214008496

      -
      -
    10. -
    - -
    C
    1
    -2
    -3
    -4
    -5
    -6
    -7
    /*a generalization of preorder traversal*/
    -void DFS(Vertex V)
    -{   
    -    visited[ V ] = true;  /*mark this vertex to avoid cycles*/
    -    for ( each W adjacent to V )
    -        if ( !visited[ W ] ) DFS( W );
    -} /*T = O(|E|+|V|) as long as adjacency lists are used*/
    -
    -

    Undirected Graphs

    -
    C
    1
    -2
    -3
    -4
    -5
    -6
    -7
    -8
    -9
    void ListComponents(Graph G)
    -{   
    -    for ( each V in G ) 
    -        if ( !visited[ V ] ) 
    -        {
    -            DFS( V );
    -            printf("\n");
    -        }
    -}
    -
    -

    Biconnectivity

    -
      -
    • \(v\) is an articulation point if \(G'=DeleteVertex(G, v)\) has at least 2 connected components.
    • -
    • \(G\) is a biconnected graph if \(G\) is connected and has no articulation points.
    • -
    • A biconnected component is a maximal biconnected subgraph.
    • -
    -

    image-20201207194401819

    -

    image-20201207194413257

    -
    -

    Note : No edges can be shared by two or more biconnected components. Hence \(E(G)\) is partitioned by the biconnected components of \(G\).

    -
    -

    Finding the biconnected components of a connected undirected \(G\) :

    -
    -
      -
    • Use depth first search to obtain a spanning tree of \(G\)
    • -
    -

    image-20201208110403641

    -

    image-20201208110506092

    -
      -
    • Depth first number(\(Num\)) 先序编号
    • -
    • Back edges(背向边) = \((u,v)\notin\) tree and \(u\) is an ancestor of \(v\).
    • -
    -
    -

    Note : If \(u\) is an ancestor of \(v\), then \(Num(u)<Num(v)\).

    -
    -
      -
    • -

      Find the articulation points in \(G\)

      -
    • -
    • -

      The root is an articulation point if it has at least 2 children.

      -
    • -
    • Any other vertex \(u\) is an articulation point if \(u\) has at least 1 child, and it is impossible to move down at least 1 step and then jump up to \(u\)‘s ancestor
    • -
    -
    -
      -
    • 对于深度优先搜索生成树上的每一个顶点\(u\),计算编号最低的顶点,称之为\(Low(u)\) - $$ - Low(u)=\min{Num(u),\min{Low(w)|w\,is\,a\,child\,of\,u},\min{Num(w)|(u,w)\,is\,a\,back\,edge}} - $$
    • -
    -
    Text Only
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    /*Assign Num and compute Parents*/
    -void AssignNum(Vertex V)
    -{
    -    Vertex W;
    -    Num[V] = Counter++;
    -    Visited[V] = True;
    -    for each W adjacent to V
    -        if(!Visited[W])
    -        {
    -            Parent[W] = V;
    -            AssignNum(W);
    -        }
    -}
    -
    -
    Text Only
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    -14
    -15
    -16
    -17
    -18
    -19
    /*Assign Low; also check for articulation points*/
    -void AssignLow(Vertex V)
    -{
    -    Vertex W;
    -    Low[V] = Num[V]; /*Rule 1*/
    -    for each W adjacent to V
    -    {
    -        if(Num[W] > Num[V]) /*Forward edge*/
    -        {
    -            Assignlow(W);
    -            if(Low[W] >= Num[V])
    -                printf("%v is an articulation point\n", v);
    -            Low[V] = Min(Low[V], Low[W]); /*Rule 3*/
    -        }
    -        else
    -            if (Parent[V] != W) /*Back edge*/
    -                Low[V] = Min(Low[V], Num[W]); /*Rule 2*/
    -    }
    -}
    -
    -
    Text Only
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    -14
    -15
    -16
    -17
    -18
    -19
    -20
    void FindArt(Vertex V)
    -{
    -    Vertex W;
    -    Visited[V] = True;
    -    Low[V] = Num[V] = Counter++; /*Rule 1*/
    -    for each W adjacent to V
    -    {
    -        if(!Visited[W]) /*Forward edge*/
    -        {
    -            Parent[W] = V;
    -            FindArt(W);
    -            if(Low[W] >= Num[V])
    -                printf("%v is an articulation point\n", v);
    -            Low[V] = Min(Low[V], Low[W]); /*Rule 3*/
    -        }
    -        else
    -            if(Parent[ V ] != W) /*Back edge*/
    -                Low[V] = Min(Low[V], Num[W]); /*Rule 2*/
    -    }
    -}
    -
    -

    Euler Circuits

    -
    [Proposition] An Euler circuit is possible only if the graph is connected and each vertex has an even degree.
    -
    [Proposition] An Euler tour is possible if there are exactly two vertices having odd degree. One must start at one of the odd-degree vertices.
    -
    -

    Note:

    -
      -
    • The path should be maintained as a linked list.
    • -
    • For each adjacency list, maintain a pointer to the last edge scanned.
    • -
    • \(T=O(|E|+|V|)\)
    • -
    -
    -
    -

    7 Sorting

    -

    7.1 Preliminaries

    -
    C
    void X_Sort (ElementType A[], int N)
    -
    -
      -
    • N must be a legal integer.
    • -
    • Assume integer array for the sake of simplicity.
    • -
    • ‘>’ and ‘<’ operators exist and are the only operations allowed on the input data.
    • -
    • Consider internal sorting only. The entire sort can be done in main memory.
    • -
    -
    -

    7.2 Insertion Sort

    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    -14
    void Insertion(ElementType A[], int N)
    -{ 
    -    int j, P; 
    -    ElementType Tmp; 
    -
    -    for ( P = 1; P < N; P++ ) 
    -    { 
    -        Tmp = A[ P ];  /*the next coming card*/
    -        for ( j = P; j > 0 && A[ j - 1 ] > Tmp; j-- ) 
    -            A[ j ] = A[ j - 1 ]; 
    -            /*shift sorted cards to provide a position for the new coming card*/
    -        A[ j ] = Tmp;  /*place the new card at the proper position*/
    -    }/*end for-P-loop*/
    -}
    -
    -
      -
    • -

      The worst case : Input A[ ] is in reverse order - $$ - T(N)=O(N^2) - $$

      -
    • -
    • -

      The best case : Input A[ ] is in sorted order - $$ - T(N)=O(N) - $$

      -
    • -
    -
    -

    7.3 A Lower Bound for Simple Sorting Algorithms

    -

    [Definition] An inversion in an array of numbers is any ordered pair\((i,j)\) having the property that \(i<j\) but \(A[i]>A[j]\)

    -
      -
    • -

      Swapping two adjacent elements that are out of place removes exactly one inversion.

      -
    • -
    • -

      \(T(N,I)=O(I+N)\) where \(I\) is the number of inversions in the original array.

      -
    • -
    -

    [Theorem] The average number of inversions in an array of \(N\) distinct numbers is \(N(N-1)/4\)

    -

    [Theorem] Any algorithm that sorts by exchanging adjacent elements requires \(\Omega(N^2)\) time on average

    -
    -

    7.4 Shellsort

    -

    image-20201214133747061

    -
      -
    • Define an increment sequence \(h_1 < h_2 < \cdots < h_t ( h_1 = 1 )\)
    • -
    • -

      Define an \(h_k\)-sort at each phase for \(k = t, t - 1,\cdots, 1\)

      -
    • -
    • -

      最后一轮就是Insertion Sort

      -
    • -
    -
    -

    Note : An \(h_k\)-sorted file that is then \(h_{k-1}\)-sorted remains \(h_k\)-sorted.

    -
    -

    Shell’s Increment Sequence

    -
    \[ -h_t=\lfloor N/2\rfloor,h_k=\lfloor h_{k+1}/2\rfloor -\]
    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    -14
    -15
    -16
    void Shellsort( ElementType A[ ], int N ) 
    -{ 
    -    int i, j, Increment; 
    -    ElementType Tmp; 
    -    for ( Increment = N / 2; Increment > 0; Increment /= 2 )  /*h sequence */
    -        for ( i = Increment; i < N; i++ ) 
    -        { /* insertion sort */
    -            Tmp = A[ i ]; 
    -            for ( j = i; j >= Increment; j -= Increment ) 
    -                if( Tmp < A[ j-Increment ] )
    -                    A[ j ] = A[ j-Increment ]; 
    -                else 
    -                    break; 
    -            A[ j ] = Tmp;
    -        } /* end for-I and for-Increment loops */
    -}
    -
    -
      -
    • [Theorem] The worst-case running time of Shellsort, using Shell’s increments, is \(\Theta( N^2 )\).
    • -
    -

    Hibbard's Increment Sequence

    -
    \[ -h_k=2^k-1 -\]
    -
      -
    • [Theorem] The worst-case running time of Shellsort, using Hibbard's increments, is \(\Theta( N^{3/2} )\).
    • -
    -

    Conjecture

    -
      -
    • \(T_{avg – Hibbard} ( N ) = O ( N^{5/4} )\)
    • -
    • Sedgewick’s best sequence is \(\{1, 5, 19, 41, 109, \cdots \}\) in which the terms are either of the form \(9\times4^i – 9\times2^i + 1\) or - \(4^i – 3\times2^i + 1\). \(T_{avg} ( N ) = O ( N^{7/6} )\) and \(T_{worst}( N ) = O( N^{4/3} )\).
    • -
    -

    Conclusion

    -
      -
    • Shellsort is a very simple algorithm, yet with an extremely complex analysis.
    • -
    • It is good for sorting up to moderately large input (tens of thousands).
    • -
    -
    -

    7.5 Heapsort

    -

    Algorithm1

    -
    C
    1
    -2
    -3
    -4
    -5
    -6
    -7
    -8
    void Heapsort( int N ) 
    -{
    -    BuildHeap( H );
    -    for ( i = 0; i < N; i++ ) 
    -        TmpH[ i ] = DeleteMin( H );
    -    for ( i = 0; i < N; i++ ) 
    -        H[ i ] = TmpH[ i ];
    -}
    -
    -
    \[ -T(N)=O(N\log N) -\]
    -
      -
    • The space requirement is doubled.
    • -
    -

    Algorithm2

    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    void Heapsort( ElementType A[ ], int N ) 
    -{
    -    int i; 
    -    for ( i = N / 2; i >= 0; i-- ) /*BuildHeap*/ 
    -        PercDown( A, i, N );
    -    for ( i = N - 1; i > 0; i-- ) 
    -    { 
    -        Swap( &A[ 0 ], &A[ i ] ); /*DeleteMax*/ 
    -        PercDown( A, 0, i ); 
    -    } 
    -}
    -
    -
      -
    • [Theorem] The average number of comparisons used to heapsort a random permutation of N distinct items is \(2N\log N-O(N\log\log N)\).
    • -
    -
    -

    Note : Although Heapsort gives the best average time, in practice it is slower than a version of Shellsort that uses Sedgewick’s increment sequence.

    -
    -
    -

    7.6 Mergesort

    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    -14
    -15
    -16
    -17
    -18
    -19
    -20
    -21
    -22
    -23
    void MSort( ElementType A[ ], ElementType TmpArray[ ], int Left, int Right ) 
    -{   
    -    int Center; 
    -    if ( Left < Right ) 
    -    {  /*if there are elements to be sort*/
    -        Center = (Left+Right)/2; 
    -        MSort(A, TmpArray, Left, Center);   /*T(N/2)*/
    -        MSort(A, TmpArray, Center+1, Right);    /*T(N/2)*/
    -        Merge(A, TmpArray, Left, Center+1, Right);  /*O(N)*/
    -    } 
    -} 
    -
    -void Mergesort( ElementType A[ ], int N ) 
    -{   
    -    ElementType *TmpArray;  /*need O(N) extra space*/
    -    TmpArray = malloc(N*sizeof(ElementType)); 
    -    if (TmpArray != NULL) 
    -    { 
    -        MSort(A, TmpArray, 0, N-1); 
    -        free(TmpArray); 
    -    } 
    -    else FatalError("No space for tmp array!!!"); 
    -}
    -
    -
      -
    • If a TmpArray is declared locally for each call of Merge, then \(S(N) = O(N\log N)\).
    • -
    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    -14
    -15
    -16
    -17
    -18
    -19
    -20
    /*Lpos = start of left half, Rpos = start of right half*/ 
    -void Merge( ElementType A[ ], ElementType TmpArray[ ], int Lpos, int Rpos, int RightEnd ) 
    -{   
    -    int i, LeftEnd, NumElements, TmpPos; 
    -    LeftEnd = Rpos-1; 
    -    TmpPos = Lpos; 
    -    NumElements = RightEnd-Lpos+1; 
    -    while( Lpos <= LeftEnd && Rpos <= RightEnd ) /*main loop*/ 
    -        if ( A[ Lpos ] <= A[ Rpos ] ) 
    -            TmpArray[ TmpPos++ ] = A[ Lpos++ ]; 
    -        else 
    -            TmpArray[ TmpPos++ ] = A[ Rpos++ ]; 
    -    while( Lpos <= LeftEnd ) /*Copy rest of first half*/ 
    -        TmpArray[ TmpPos++ ] = A[ Lpos++ ]; 
    -    while( Rpos <= RightEnd ) /*Copy rest of second half*/ 
    -        TmpArray[ TmpPos++ ] = A[ Rpos++ ]; 
    -    for( i = 0; i < NumElements; i++, RightEnd-- ) 
    -        /*Copy TmpArray back*/ 
    -        A[ RightEnd ] = TmpArray[ RightEnd ]; 
    -}
    -
    -

    Analysis

    -
    \[ -T(1)=O(1)\\ -T(N)=2T(\frac{N}{2})+O(N)\\ -\frac{T(N)}{N}=\frac{T(\frac{N}{2})}{\frac{N}{2}}+1\\ -\cdots\\ -\frac{T(\frac{N}{2^{k-1}})}{\frac{N}{2^{k-1}}}=\frac{T(1)}{1}+1\\ -T(N)=O(N+N\log N) -\]
    -
    -

    Note : Mergesort requires linear extra memory, and copying an array is slow. It is hardly ever used for internal sorting, but is quite useful for external sorting.

    -
    -
    -

    7.7 Quicksort

    -
      -
    • the fastest known sorting algorithm in practice
    • -
    -

    Algorithm

    -
    Text Only
    1
    -2
    -3
    -4
    -5
    -6
    -7
    -8
    void Quicksort( ElementType A[ ], int N )
    -{
    -    if (N < 2) return;
    -    pivot = pick any element in A[ ]; 
    -    Partition S = { A[ ] \ pivot } into two disjoint sets:
    -        A1 = { a in S | a <= pivot } and A2 = { a in S | a >= pivot };
    -    A = Quicksort(A1, N1) and { pivot } and Quicksort(A2, N2);
    -}
    -
    -
      -
    • The pivot is placed at the right place once and for all.
    • -
    • 要研究的问题是如何选取枢纽元和如何划分
    • -
    -

    Picking the Pivot

    -
    A Wrong Way
    -
      -
    • Pivot = A[ 0 ]
    • -
    • The worst case : A[ ] is presorted, quicksort will take \(O(N^2)\) time to do nothing
    • -
    -
    A Safe Maneuver
    -
      -
    • Pivot = random select from A[ ]
    • -
    • random number generation is expensive
    • -
    -
    Median-of-Three Partitioning
    -
      -
    • Pivot = median(left, center, right)
    • -
    • Eliminates the bad case for sorted input and actually reduces the running time by about 5%.
    • -
    -

    Partitioning Strategy

    -
      -
    • \(i\)\(j\)的左边时,我们将\(i\)右移,移过那些小于枢纽元的元素,并将\(j\)左移,移过那些大于枢纽元的元素
    • -
    • \(i\)\(j\)停止时,\(i\)指向一个大元素而\(j\)指向一个小元素,如果\(i\)\(j\)的左边,那么将这两个元素互换
    • -
    • 重复该过程直到\(i\)\(j\)彼此交错为止
    • -
    • 划分的最后一步是将枢纽元与\(i\)所指向的元素交换
    • -
    • 如果\(i\)\(j\)遇到等于枢纽元的键值,就让\(i\)\(j\)都停止,因为若都不停止\(T(N)=O(N^2)\)
    • -
    • There will be many dummy swaps, but at least the sequence will be partitioned into two equal-sized subsequences.
    • -
    -

    Small Arrays

    -
      -
    • Quicksort is slower than insertion sort for small \(N(\leq 20)\).
    • -
    • Cutoff when \(N\) gets small and use other efficient algorithms (such as insertion sort).
    • -
    -

    Implementation

    -
    C
    1
    -2
    -3
    -4
    -5
    -6
    -7
    void Quicksort( ElementType A[ ], int N ) 
    -{ 
    -    Qsort( A, 0, N-1 ); 
    -    /*A:the array*/
    -    /*0:Left index*/
    -    /*N–1:Right index*/
    -}
    -
    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    -14
    -15
    -16
    /* Return median of Left, Center, and Right */ 
    -/* Order these and hide the pivot */ 
    -ElementType Median3( ElementType A[ ], int Left, int Right ) 
    -{
    -    int Center = ( Left+Right )/2; 
    -    if ( A[ Left ] > A[ Center ] ) 
    -        Swap( &A[ Left ], &A[ Center ] ); 
    -    if ( A[ Left ] > A[ Right ] ) 
    -        Swap( &A[ Left ], &A[ Right ] ); 
    -    if ( A[ Center ] > A[ Right ] ) 
    -        Swap( &A[ Center ], &A[ Right ] ); 
    -    /*Invariant: A[ Left ] <= A[ Center ] <= A[ Right ]*/ 
    -    Swap( &A[ Center ], &A[ Right-1 ] ); /*Hide pivot*/ 
    -    /*only need to sort A[ Left+1 ] … A[ Right–2 ]*/
    -    return A[ Right-1 ];  /*Return pivot*/ 
    -}
    -
    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    -14
    -15
    -16
    -17
    -18
    -19
    -20
    -21
    -22
    -23
    -24
    void Qsort( ElementType A[ ], int Left, int Right ) 
    -{
    -    int i, j; 
    -    ElementType Pivot; 
    -    if ( Left + Cutoff <= Right ) 
    -    {   /*if the sequence is not too short*/
    -        Pivot = Median3( A, Left, Right );  /*select pivot*/
    -        i = Left;     
    -        j = Right  1;  /*why not set Left+1 and Right-2?*/
    -        for( ; ; ) 
    -        { 
    -            while ( A[ ++i ] < Pivot ) { }  /*scan from left*/
    -            while ( A[ --j ] > Pivot ) { }  /*scan from right*/
    -            if ( i < j ) 
    -                Swap( &A[ i ], &A[ j ] );  /*adjust partition*/
    -            else break;  /*partition done*/
    -        } 
    -        Swap( &A[ i ], &A[ Right-1 ] ); /*restore pivot */ 
    -        Qsort( A, Left, i-1 );    /*recursively sort left part*/
    -        Qsort( A, i+1, Right );   /*recursively sort right part*/
    -    }  /*end if - the sequence is long*/
    -    else /*do an insertion sort on the short subarray*/ 
    -        InsertionSort( A+Left, Right-Left+1 );
    -}
    -
    -
    -

    Note : If set i = Left+1 and j = Right-2, there will be an infinite loop if A[i] = A[j] = pivot.

    -
    -

    Analysis

    -
    \[ -T(N)=T(i)+T(N-i-1)+cN -\]
    -
      -
    • -

      \(i\) is the number of the elements in \(S_1\).

      -
    • -
    • -

      The Worst Case - $$ - T(N)=T(N-1)+cN - $$

      -
    • -
    -

    $$ - T(N-1)=T(N-2)+c(N-1) - $$

    -

    $$ - \cdots - $$

    -

    $$ - T(2)=T(1)+2c - $$

    -

    $$ - T(N)=T(1)+c\sum^N_{i=2}i=O(N^2) - $$

    -
      -
    • The Best Case - $$ - T(N)=2T(N/2)+cN - $$
    • -
    -

    $$ - \frac{T(N)}{N}=\frac{T(N/2)}{N/2}+c - $$

    -

    $$ - \frac{T(N/2)}{N/2}=\frac{T(N/4)}{N/4}+c - $$

    -

    $$ - \cdots - $$

    -

    $$ - \frac{T(2)}{2}=\frac{T(1)}{1}+c - $$

    -

    $$ - \frac{T(N)}{N}=\frac{T(1)}{1}+c\log N\frac{T(N)}{N}=\frac{T(1)}{1}+c\log N - $$

    -

    $$ - T(N)=cN\log N+N=O(N\log N) - $$

    -
      -
    • -

      The Average Case

      -
    • -
    • -

      Assume the average value of \(T( i )\) for any \(i\) is \(\frac{1}{N}\left[\sum^{N-1}_{j=0}T(j)\right]\) - $$ - T(N)=\frac{2}{N}\left[\sum^{N-1}_{j=0}T(j)\right]+cN - $$

      -
    • -
    -

    $$ - NT(N)=2\left[\sum^{N-1}_{j=0}T(j)\right]+cN^2 - $$

    -

    $$ - (N-1)T(N-1)=2\left[\sum^{N-2}_{j=0}T(j)\right]+c(N-1)^2 - $$

    -

    $$ - NT(N)-(N-1)T(N-1)=2T(N-1)+2cN-c - $$

    -

    $$ - NT(N)=(N+1)T(N-1)+2cN - $$

    -

    $$ - \frac{T(N)}{N+1}=\frac{T(N-1)}{N}+\frac{2c}{N+1} - $$

    -

    $$ - \frac{T(N-1)}{N}=\frac{T(N-2)}{N-1}+\frac{2c}{N} - $$

    -

    $$ - \cdots - $$

    -

    $$ - \frac{T(2)}{3}=\frac{T(1)}{2}+\frac{2c}{3} - $$

    -

    $$ - \frac{T(N)}{N+1}=\frac{T(1)}{2}+2c\sum^{N+1}_{i=3}\frac{1}{i} - $$

    -

    $$ - T(N)=O(N\log N) - $$

    -

    Quickselect

    -
      -
    • 查找第\(K\)最大(最小)元
    • -
    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    -14
    -15
    -16
    -17
    -18
    -19
    -20
    -21
    -22
    -23
    -24
    -25
    -26
    -27
    -28
    -29
    -30
    -31
    /*Places the kth sma11est element in the kth position*/
    -/*Because arrays start at 0, this will be index k-1*/
    -void Qselect(ElementType A[ ], int k, int Left, int Right)
    -{
    -    int i, j;
    -    ElementType Pivot;
    -
    -    if (Left + Cutoff <= Right)
    -    {
    -        Pivot = Median3(A, Left, Right);
    -        i = Left; 
    -        j = Right-1;
    -        for( ; ; )
    -        {
    -            while(A[ ++i ] < Pivot){ }
    -            while(A[ --j ] > Pivot){ }
    -            if(i < j)
    -                Swap(&A[ i ], &A[ j ]);
    -            else
    -                break;
    -        }
    -        Swap(&A[ i ], &A[ Right-1 ]); /*Restore pivot*/
    -
    -        if(k <= i)
    -            Qselect(A, k, Left, i-1);
    -        else if (k > i+1)
    -            Qselect(A, k, i+1, Right);
    -    }
    -    else /*Doan insertion sort on the subarray*/
    -        InsertionSort(A+Left, Right-Left+1);
    -}
    -
    -

    image-20210125115951471

    -

    正确答案是D

    -
    -

    7.8 Sorting Large Structures

    -
      -
    • Swapping large structures can be very much expensive.
    • -
    • Add a pointer field to the structure and swap pointers instead – indirect sorting. Physically rearrange the structures at last if it is really necessary.
    • -
    • Table Sort
    • -
    -
    -

    7.9 A General Lower Bound for Sorting

    -

    [Theorem] Any algorithm that sorts by comparisons only must have a worst case computing time of \(\Omega(N\log N)\).

    -
      -
    • When sorting \(N\) distinct elements, there are \(N!\) different possible results.
    • -
    • Thus any decision tree must have at least \(N!\) leaves.
    • -
    • If the height of the tree is \(k\), then \(N! \leq 2^{k-1}\rarr k\geq\log(N!)+1\)
    • -
    • Since \(N!\geq (N/2)^{N/2}\) and \(\log_2N!\geq(N/2)\log_2(N/2) = \Theta(N\log_2N )\)
    • -
    • Therefore \(T(N)=k\geq c\cdot N\log_2 N\)
    • -
    -
    -

    7.10 Bucket Sort

    -

    image-20201221203533117

    -
    Text Only
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    Algorithm
    -{
    -    initialize count[ ];
    -    while(read in a student’s record)
    -        insert to list count[stdnt.grade];
    -    for(int i = 0; i < M; i++) 
    -    {
    -        if(count[i]) output list count[i];
    -    }
    -}
    -
    -
    \[ -T(N,M)=O(M+N) -\]
    -
    -

    7.11 Radix Sort

    -

    image-20201221203826847

    -

    image-20201221203950519

    -
      -
    • \(T=O(P(N+B))\) where \(P\) is the number of passes, \(N\) is the number of elements to sort, and \(B\) is the number of buckets.
    • -
    -

    MSD(Most Significant Digit) Sort and LSD(Least Significant Digit) Sort

    -

    image-20210102211456822

    -

    image-20210102211604977

    -

    image-20210102211647809

    -
    -
      -
    • 稳定的排序算法:冒泡排序、插入排序、归并排序、基数排序
    • -
    • 不稳定的排序算法:选择排序、快速排序、希尔排序、堆排序
    • -
    -
    -

    8 Hashing

    -

    8.1 General Idea

    -

    image-20210102212103035

    -

    Symbol Table ADT

    -
      -
    • Objects : A set of name-attribute pairs, where the names are unique
    • -
    • Operations :
    • -
    • SymTab Create(TableSize)
    • -
    • Boolean IsIn(symtab, name)
    • -
    • Attribute Find(symtab, name)
    • -
    • SymTab Insert(symtab, name, attr)
    • -
    • SymTab Delete(symtab, name)
    • -
    -

    Hash Tables

    -

    image-20210102212608844

    -
      -
    • A collision occurs when we hash two nonidentical identifiers into the same bucket.
    • -
    • An overflow occurs when we hash a new identifier into a full bucket.
    • -
    -
    -

    8.2 Hash Function

    -
      -
    • \(f(x)\) must be easy to compute and minimize the number of collisions.
    • -
    • \(f(x)\) should be unbiased. For any \(x\) and any \(i\), we have that \(Probability(f(x)=i)=\frac{1}{b}\). Such kind of a hash function is called a uniform hash function.
    • -
    -
    -

    8.3 Separate Chaining

    -
      -
    • keep a list of all keys that hash to the same value
    • -
    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    -14
    -15
    -16
    struct ListNode; 
    -typedef struct ListNode *Position; 
    -struct HashTbl; 
    -typedef struct HashTbl *HashTable; 
    -struct ListNode { 
    -    ElementType Element; 
    -    Position Next; 
    -}; 
    -typedef Position List; 
    -/* List *TheList will be an array of lists, allocated later */ 
    -/* The lists use headers (for simplicity), */ 
    -/* though this wastes space */ 
    -struct HashTbl { 
    -    int TableSize; 
    -    List *TheLists; 
    -}; 
    -
    -

    Create an empty table

    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    -14
    -15
    -16
    -17
    -18
    -19
    -20
    -21
    -22
    -23
    HashTable InitializeTable( int TableSize ) 
    -{   
    -    HashTable H; 
    -    int i; 
    -    if ( TableSize < MinTableSize ) 
    -    { 
    -        Error( "Table size too small" );  
    -        return NULL;  
    -    } 
    -    H = malloc( sizeof( struct HashTbl ) );  /*Allocate table*/
    -    if ( H == NULL ) FatalError( "Out of space!!!" ); 
    -    H->TableSize = NextPrime( TableSize );  /*Better be prime*/
    -    H->TheLists = malloc( sizeof( List )* H->TableSize );  /*Array of lists*/
    -    if ( H->TheLists == NULL ) FatalError( "Out of space!!!" );
    -    H->TheList = malloc(H->TableSize*sizeof(struct ListNode));
    -    for( i = 0; i < H->TableSize; i++ ) 
    -    {   /*Allocate list headers*/
    -        //H->TheLists[ i ] = malloc( sizeof( struct ListNode ) ); /* Slow! */
    -        if ( H->TheLists[ i ] == NULL ) FatalError( "Out of space!!!" ); 
    -        else H->TheLists[ i ]->Next = NULL;
    -    } 
    -    return H; 
    -} 
    -
    -

    Find a key from a hash table

    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    Position Find ( ElementType Key, HashTable H ) 
    -{ 
    -    Position P; 
    -    List L; 
    -    L = H->TheLists[ Hash( Key, H->TableSize ) ]; 
    -    P = L->Next; 
    -    while( P != NULL && P->Element != Key )  /*Probably need strcmp*/ 
    -        P = P->Next; 
    -    return P; 
    -} 
    -
    -

    Insert a key into a hash table

    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    -14
    -15
    -16
    -17
    -18
    void Insert ( ElementType Key, HashTable H ) 
    -{ 
    -    Position Pos, NewCell; 
    -    List L; 
    -    Pos = Find( Key, H ); 
    -    if ( Pos == NULL ) 
    -    {   /*Key is not found, then insert*/
    -        NewCell = malloc( sizeof( struct ListNode ) ); 
    -        if ( NewCell == NULL ) FatalError( "Out of space!!!" ); 
    -        else 
    -        { 
    -            L = H->TheLists[ Hash( Key, H->TableSize ) ]; /*Compute again is bad*/
    -            NewCell->Next = L->Next; 
    -            NewCell->Element = Key; /*Probably need strcpy!*/ 
    -            L->Next = NewCell; 
    -        } 
    -    } 
    -} 
    -
    -
    -

    Note : Make the TableSize about as large as the number of keys expected (i.e. to make the loading density factor \(\lambda\approx\)1).

    -
    -
    -

    8.4 Open Addressing

    -
      -
    • find another empty cell to solve collision(avoiding pointers)
    • -
    -
    Text Only
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    Algorithm: insert key into an array of hash table
    -{
    -    index = hash(key);
    -    initialize i = 0 ------ the counter of probing;
    -    while (collision at index) 
    -    {
    -        index = (hash(key)+f(i))%TableSize; /*f(i) is collision resolving function*/
    -        if (table is full) break;
    -        else i++;
    -    }
    -    if (table is full) ERROR (“No space left”);
    -    else insert key at index;
    -}
    -
    -
    -

    Note : Generally \(\lambda<0.5\).

    -
    -

    Linear Probing

    -
      -
    • \(F(i)\) is a linear function of \(i\), such as \(F(i)=i\).
    • -
    • 逐个探测每个单元(必要时可以绕回)以查找出一个空单元
    • -
    • 使用线性探测的预期探测次数对于插入和不成功的查找来说大约是\(\frac{1}{2}(1+\frac{1}{(1-\lambda)^2})\),对于成功的查找来说是\(\frac{1}{2}(1+\frac{1}{1-\lambda})\)
    • -
    • Cause primary clustering : any key that hashes into the cluster will add to the cluster after several attempts to resolve the collision.
    • -
    -

    Quadratic Probing

    -
      -
    • \(F(i)\) is a quadratic function of \(i\), such as \(F(i)=i^2\).
    • -
    -
    [Theorem] If quadratic probing is used, and the table size is prime, then a new element can always be inserted if the table is at least half empty.
    -

    image-20210104154133711

    -
    -

    Note : If the table size is a prime of the form \(4k + 3\), then the quadratic probing \(f(i) = \pm i^2\) can probe the entire table.

    -
    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    -14
    -15
    -16
    -17
    -18
    -19
    -20
    -21
    -22
    -23
    -24
    HashTable InitializeTable(int TableSize)
    -{
    -    HashTable H;
    -    int i;
    -    if(TableSize < MinTableSize)
    -    {
    -        Error("Table size too small");
    -        return NULL;
    -    }
    -    /*Allocate table*/
    -    H = malloc(sizeof(struct HashTbl));
    -    if(H == NULL)
    -        Fatal Error("Out of space!!!");
    -    H->TableSize = NextPrime(TableSize);
    -
    -    /*Allocate array of Cells*/
    -    H->TheCells = malloc(sizeof(Cell)*H->TableSize);
    -    if(H->TheCells == NULL)
    -        FatalError("Out of space!!!");
    -
    -    for(i = 0; i < H->TableSize; i++)
    -        H->TheCells[ i ].Info = Empty;
    -    return H;
    -}
    -
    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    -14
    -15
    Position Find(ElementType Key, HashTable H) 
    -{   
    -    Position CurrentPos; 
    -    int CollisionNum; 
    -    CollisionNum = 0; 
    -    CurrentPos = Hash(Key, H->TableSize); 
    -    while(H->TheCells[ CurrentPos ].Info != Empty &&
    -          H->TheCells[ CurrentPos ].Element != Key) 
    -    { 
    -        CurrentPos += 2*++CollisionNum-1; 
    -        if (CurrentPos >= H->TableSize)  
    -            CurrentPos -= H->TableSize;   /*Faster than mod*/
    -    } 
    -    return CurrentPos; 
    -} 
    -
    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    void Insert(ElementType Key, HashTable H) 
    -{ 
    -    Position Pos; 
    -    Pos = Find(Key, H); 
    -    if (H->TheCells[ Pos ].Info != Legitimate) 
    -    { /*OK to insert here*/ 
    -        H->TheCells[ Pos ].Info = Legitimate; 
    -        H->TheCells[ Pos ].Element = Key; /*Probably need strcpy*/ 
    -    } 
    -} 
    -
    -
    -

    Note :

    -
      -
    • Insertion will be seriously slowed down if there are too many deletions intermixed with insertions.
    • -
    • Although primary clustering is solved, secondary clustering occurs, that is, keys that hash to the same position will probe the same alternative cells.
    • -
    -
    -

    Double Hashing

    -
      -
    • \(f(i)=i*hash_2(x)\)
    • -
    • \(hash_2(x)\not\equiv 0\)
    • -
    • make sure that all cells can be probed
    • -
    • \(hash_2(x)=R-(x\%R)\) with \(R\) a prime smaller than TableSize, will work well.
    • -
    -
    -

    Note :

    -
      -
    • If double hashing is correctly implemented, simulations imply that the expected number of probes is almost the same as for a random collision resolution strategy.
    • -
    • Quadratic probing does not require the use of a second hash function and is thus likely to be simpler and faster in practice.
    • -
    -
    -
    -

    8.5 Rehashing

    -
      -
    • Build another table that is about twice as big.
    • -
    • Scan down the entire original hash table for non-deleted elements.
    • -
    • Use a new function to hash those elements into the new table.
    • -
    • When to rehash
    • -
    • As soon as the table is half full
    • -
    • When an insertion fails
    • -
    • When the table reaches a certain load factor
    • -
    -
    -

    Note : Usually there should have been N/2 insertions before rehash, so O(N) rehash only adds a constant cost to each insertion. However, in an interactive system, the unfortunate user whose insertion caused a rehash could see a slowdown.

    -
    -
    C
     1
    - 2
    - 3
    - 4
    - 5
    - 6
    - 7
    - 8
    - 9
    -10
    -11
    -12
    -13
    -14
    -15
    -16
    -17
    HashTable Rehash(HashTable H)
    -{
    -    int i, OldSize;
    -    Cell *OldCells;
    -    OldCells = H->TheCells;
    -    OldSize = H->TableSize;
    -
    -    /*Get a new, empty table*/
    -    H = InitializeTable(2*OldSize);
    -    /*Scan through old table, reinserting into new*/
    -    for(i = 0; i < OldSize; i++)
    -        if(OldCells[i].Info == Legitimate)
    -            Insert(OldCells[i].Element, H);
    -    free(OldCells);
    -
    -    return H;
    -}
    -
    -
    - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - - - -
    - - - -
    -
    -
    -
    - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git "a/site/JY_HU/2 \346\225\260\346\215\256\347\273\223\346\236\204/webnotes/index.html" "b/site/JY_HU/2 \346\225\260\346\215\256\347\273\223\346\236\204/webnotes/index.html" deleted file mode 100644 index 0f395d31..00000000 --- "a/site/JY_HU/2 \346\225\260\346\215\256\347\273\223\346\236\204/webnotes/index.html" +++ /dev/null @@ -1,2656 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - 写在前面 - JY-HF learning site - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - - - - 跳转至 - - -
    -
    - -
    - - - - -
    - - -
    - -
    - - - - - - - - - -
    -
    - - - -
    -
    -
    - - - - - - - - - -
    -
    -
    - - - - -
    -
    - - - - - - - -

    Notes for Data Structure

    -

    Stars -Forks -repo-size -Contributors

    -

    This is my personal notes for The Foundation of Data Structure course in Zhejiang University.

    -

    Since it’s the first time I’ve learned data structure systematically, I wish I could detail the information which will make it easier for me to review in the future.

    -

    Also hope that my notes can help someone else a little bit.

    - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - - - -
    - - - -
    -
    -
    -
    - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/site/JY_HU/3 ZJU-AI-ML/feed forward and backward propagation/index.html b/site/JY_HU/3 ZJU-AI-ML/feed forward and backward propagation/index.html deleted file mode 100644 index 3684b133..00000000 --- a/site/JY_HU/3 ZJU-AI-ML/feed forward and backward propagation/index.html +++ /dev/null @@ -1,2645 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - 反向传播 - JY-HF learning site - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - -
    -
    - -
    - - - - -
    - - -
    - -
    - - - - - - - - - -
    -
    - - - -
    -
    -
    - - - - - - - - - -
    -
    -
    - - - - -
    -
    - - - - - - - -

    反向传播

    - -

    feed forward and backward propagation

    -

    反向传播中,计算的是最终的

    - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - - - -
    - - - -
    -
    -
    -
    - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/site/JY_HU/3 ZJU-AI-ML/notes for ZJU-AI-ML/index.html b/site/JY_HU/3 ZJU-AI-ML/notes for ZJU-AI-ML/index.html deleted file mode 100644 index a4148ff2..00000000 --- a/site/JY_HU/3 ZJU-AI-ML/notes for ZJU-AI-ML/index.html +++ /dev/null @@ -1,2644 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - 赶快补课抄笔记 - JY-HF learning site - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    - -
    -
    - -
    - - - - -
    - - -
    - -
    - - - - - - - - - -
    -
    - - - -
    -
    -
    - - - - - - - - - -
    -
    -
    - - - - -
    -
    - - - - - - - -

    赶快补课抄笔记

    - -

    notes for ZJU-AI-ML

    - - - - - - - - - - - - - - - - - - - - - - -
    -
    - - - -
    - - - -
    - - - -
    -
    -
    -
    - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/site/JY_HU/3 ZJU-AI-ML/Approach almost/index.html b/site/JY_HU/AI/Approach almost/index.html similarity index 54% rename from site/JY_HU/3 ZJU-AI-ML/Approach almost/index.html rename to site/JY_HU/AI/Approach almost/index.html index f8962e7e..342fce99 100644 --- a/site/JY_HU/3 ZJU-AI-ML/Approach almost/index.html +++ b/site/JY_HU/AI/Approach almost/index.html @@ -152,6 +152,50 @@ + + +
    @@ -239,6 +283,14 @@ + + + + + + + + @@ -248,7 +300,7 @@
  • - + Jy Hu CS @@ -261,6 +313,9 @@ + + + @@ -527,7 +582,7 @@ - 1 数字逻辑设计 + 大二下 @@ -537,7 +592,246 @@ + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + @@ -2492,7 +4500,26 @@
  • 构建 t 分布: 在低维空间中重复上述步骤,构建 t 分布,表示数据点在低维空间中的分布。
  • 最小化 KL 散度: 通过最小化 KL 散度(Kullback-Leibler divergence),调整低维空间中的数据点位置,使其尽可能符合条件概率分布。
  • -

    t-SNE 通常用于可视化高维数据,尤其在发现聚类结构方面表现出色。然而,需要注意的是,t-SNE 对于不同的初始化可能会导致不同的结果,因此在解释结果时需要谨慎。

    +

    t-SNE 通常用于可视化高维数据,尤其在发现聚类结构方面表现出色。然而,需要注意的是,t-SNE 对于不同的初始化可能会导致不同的结果,因此在解释结果时需要谨慎。

    +

    Image compression using PCA (Principal Component Analysis) involves applying PCA to the pixel values of an image and retaining only the most significant principal components. The basic idea is to reduce the dimensionality of the image while preserving as much information as possible. Here's a step-by-step guide on how to perform image compression using PCA:

    +
      +
    1. Flatten the Image:
    2. +
    3. Convert the 2D image matrix to a 1D vector by flattening the pixel values. For a color image, you'll have separate vectors for each color channel (e.g., Red, Green, Blue).
    4. +
    5. Standardize the Data:
    6. +
    7. Standardize the pixel values (subtract mean, divide by standard deviation) to ensure that each color channel has zero mean and unit variance.
    8. +
    9. Compute Covariance Matrix:
    10. +
    11. Calculate the covariance matrix of the standardized pixel values. The covariance matrix represents the relationships between different color channels.
    12. +
    13. Perform PCA:
    14. +
    15. Use PCA to compute the eigenvectors and eigenvalues of the covariance matrix. The eigenvectors represent the principal components, and the eigenvalues indicate their significance.
    16. +
    17. Select Principal Components:
    18. +
    19. Select the top-k eigenvectors corresponding to the k largest eigenvalues. These principal components capture the most important information in the image.
    20. +
    21. Project Data onto Lower-Dimensional Space:
    22. +
    23. Project the standardized pixel values onto the subspace spanned by the selected principal components. This effectively reduces the dimensionality of the image.
    24. +
    25. Reconstruction:
    26. +
    27. Reconstruct the compressed image by reversing the PCA transformation. This involves multiplying the lower-dimensional representation by the transpose of the selected principal components and adding back the mean.
    28. +
    29. Visualize the Results:
    30. +
    31. Compare the original image with the compressed image to assess the quality of the compression.
    32. +
    @@ -2515,7 +4542,7 @@ - 2024-07-02 + 2024-07-03 @@ -2647,7 +4674,7 @@ - + diff --git a/site/JY_HU/3 ZJU-AI-ML/ML-zju/index.html b/site/JY_HU/AI/ML-zju/index.html similarity index 53% rename from site/JY_HU/3 ZJU-AI-ML/ML-zju/index.html rename to site/JY_HU/AI/ML-zju/index.html index 0a7571c0..df539de9 100644 --- a/site/JY_HU/3 ZJU-AI-ML/ML-zju/index.html +++ b/site/JY_HU/AI/ML-zju/index.html @@ -152,6 +152,50 @@ + +
    +
    @@ -239,6 +283,14 @@ + + + + + + + + @@ -248,7 +300,7 @@
  • - + Jy Hu CS @@ -261,6 +313,9 @@ + + + @@ -527,7 +582,7 @@ - 1 数字逻辑设计 + 大二下 @@ -537,7 +592,246 @@ + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + @@ -2545,7 +4553,51 @@

    symbolism

    connectionism

    transformers

    recurrent neural networks

    -

    convolution neural netorks

    +

    convolution neural netorks

    +

    Neyman-Pearson方法

    +

    Neyman-Pearson方法是统计学中的一种假设检验方法,由Jerzy Neyman和Egon Pearson命名。它在频率主义统计学中被广泛应用,用于根据观察到的数据在两个竞争性假设之间做出决策。该方法着重于控制第一类错误的概率,即当真实的零假设被错误拒绝时发生的错误。

    +

    以下是Neyman-Pearson方法的关键要点:

    +
      +
    1. 零假设(\(H_0\))和备择假设(\(H_1\)\(H_a\)):
    2. +
    3. \(H_0\):零假设代表默认假设,通常是无效果或无差异的陈述。
    4. +
    5. \(H_1\):备择假设表示与零假设相对的陈述,通常涉及效果或差异的存在。
    6. +
    7. 显著性水平(Significance Level):
    8. +
    9. 定义:显著性水平是在零假设为真的情况下拒绝零假设的概率
    10. +
    11. 应用:研究者在实验设计时选择显著性水平,通常用符号 �α 表示。
    12. +
    13. 试验统计量(Test Statistic):
    14. +
    15. 定义:一个数值,根据观察到的数据计算而得,用于决定是否拒绝零假设。
    16. +
    17. 应用:根据试验统计量与临界值(由显著性水平确定)的关系来做出决策。
    18. +
    19. 拒绝域和接受域(Rejection Region and Acceptance Region):
    20. +
    21. 定义:拒绝域是试验统计量的值,当它落在这个区域内时,拒绝零假设。接受域则是拒绝域的补集。
    22. +
    23. 应用:通过选择拒绝域的边界,研究者可以控制第一类错误的概率。
    24. +
    +

    Neyman-Pearson方法通过在控制显著性水平的同时最小化第二类错误的概率,提供了一种强假设检验的框架。这种方法在实际应用中对于需要明确控制错误率的问题非常有用。

    +

    posterior = beta.pdf(p, a, b)是什么意思

    +

    这个表达式表示了后验概率的计算方式,其中beta.pdf(p, a, b)表示了一个Beta分布的概率密度函数(probability density function,PDF)。在这个表达式中,p是概率的取值,ab是Beta分布的参数。

    +

    Beta分布是一个常用的概率分布,它在概率论和统计学中经常被用于描述随机变量的取值范围在[0, 1]之间的情况。它的概率密度函数可以表示为:

    +
    \[ \text{Beta}(p|a, b) = \frac{1}{B(a, b)} \cdot p^{a-1} \cdot (1-p)^{b-1} \]
    +

    其中,$$ \text{Beta}(p|a, b)$$是Beta函数(Beta function),用于归一化Beta分布。在后验概率的计算中,通常会假设先验分布为Beta分布,并结合观测数据,通过贝叶斯定理计算得到后验分布。这里的beta.pdf(p, a, b)就是计算给定参数ab的Beta分布在概率值p处的概率密度。

    +

    因此,posterior = beta.pdf(p, a, b)表示计算后验概率,即给定先验分布和观测数据,通过Beta分布的概率密度函数计算在概率值p处的后验概率密度。

    +

    Metropolis-Hastings算法

    +

    Metropolis-Hastings算法是一种用于从目标分布中抽样的马尔可夫链蒙特卡罗(MCMC)方法。这个算法允许我们在无法直接从目标分布中抽样的情况下,通过构建一个马尔可夫链来间接地生成样本。以下是一个通俗的解释:

    +
      +
    1. 背景:
    2. +
    3. 目标分布(Target Distribution): 我们想要从中抽样的分布,通常是由于它很难直接从中抽样。
    4. +
    5. 马尔可夫链(Markov Chain): 一系列随机变量的序列,其中每个变量的状态仅依赖于前一个状态。
    6. +
    7. 思想:
    8. +
    9. 我们构建一个马尔可夫链,使其平稳分布(稳态分布)为我们想要抽样的目标分布。
    10. +
    11. 步骤:
    12. +
    13. 提议步骤(Proposal Step): 从当前状态生成一个提议状态。这可以通过从某个简单分布中抽样来实现。
    14. +
    15. 接受/拒绝步骤(Accept/Reject Step): 以一定的概率接受提议状态,否则保持当前状态。这个概率由目标分布和提议分布的比例决定。
    16. +
    17. 具体流程:
    18. +
    19. 从当前状态开始,通过提议步骤生成一个新的状态。
    20. +
    21. 计算接受概率,它考虑了目标分布在新状态和当前状态下的概率密度比。
    22. +
    23. 根据接受概率决定是否接受新状态。如果接受,则更新为新状态;否则,保持当前状态。
    24. +
    25. 重复这个过程,得到一个马尔可夫链。
    26. +
    27. 收敛性:
    28. +
    29. 随着抽样次数的增加,马尔可夫链趋向于稳态分布,从而生成的样本趋近于目标分布。
    30. +
    +

    总体而言,Metropolis-Hastings算法通过引入提议步骤和接受/拒绝步骤,利用马尔可夫链的性质,逐步探索并逼近目标分布,从而实现从目标分布中抽样的目的。这种方法在贝叶斯统计学、统计物理学等领域中广泛应用。

    @@ -2568,7 +4620,7 @@

    connectionism

    - 2024-07-02 + 2024-07-03 @@ -2578,7 +4630,7 @@

    connectionism

    - 2023-11-18 + 2024-07-03 @@ -2700,7 +4752,7 @@

    connectionism

    - + diff --git a/site/JY_HU/AI/assets/000151.png b/site/JY_HU/AI/assets/000151.png new file mode 100644 index 00000000..75766003 Binary files /dev/null and b/site/JY_HU/AI/assets/000151.png differ diff --git a/site/JY_HU/AI/assets/43a69d21d6ca9b411ebbdaaeafb292b.png b/site/JY_HU/AI/assets/43a69d21d6ca9b411ebbdaaeafb292b.png new file mode 100644 index 00000000..74ee3459 Binary files /dev/null and b/site/JY_HU/AI/assets/43a69d21d6ca9b411ebbdaaeafb292b.png differ diff --git a/site/JY_HU/AI/assets/640-1706021353902-82.png b/site/JY_HU/AI/assets/640-1706021353902-82.png new file mode 100644 index 00000000..d4214cda Binary files /dev/null and b/site/JY_HU/AI/assets/640-1706021353902-82.png differ diff --git a/site/JY_HU/AI/assets/640-1706021353903-83.png b/site/JY_HU/AI/assets/640-1706021353903-83.png new file mode 100644 index 00000000..9cad8671 Binary files /dev/null and b/site/JY_HU/AI/assets/640-1706021353903-83.png differ diff --git a/site/JY_HU/AI/assets/640.png b/site/JY_HU/AI/assets/640.png new file mode 100644 index 00000000..a7f42eab Binary files /dev/null and b/site/JY_HU/AI/assets/640.png differ diff --git a/site/JY_HU/AI/assets/822.jpg b/site/JY_HU/AI/assets/822.jpg new file mode 100644 index 00000000..41403c03 Binary files /dev/null and b/site/JY_HU/AI/assets/822.jpg differ diff --git a/site/JY_HU/AI/assets/OIP-1705891331401-67-1705908072743-71.jpeg b/site/JY_HU/AI/assets/OIP-1705891331401-67-1705908072743-71.jpeg new file mode 100644 index 00000000..20a02d77 Binary files /dev/null and b/site/JY_HU/AI/assets/OIP-1705891331401-67-1705908072743-71.jpeg differ diff --git a/site/JY_HU/AI/assets/OIP-1705891331401-67.jpeg b/site/JY_HU/AI/assets/OIP-1705891331401-67.jpeg new file mode 100644 index 00000000..20a02d77 Binary files /dev/null and b/site/JY_HU/AI/assets/OIP-1705891331401-67.jpeg differ diff --git a/site/JY_HU/AI/assets/OIP.jpeg b/site/JY_HU/AI/assets/OIP.jpeg new file mode 100644 index 00000000..20a02d77 Binary files /dev/null and b/site/JY_HU/AI/assets/OIP.jpeg differ diff --git a/site/JY_HU/AI/assets/R.png b/site/JY_HU/AI/assets/R.png new file mode 100644 index 00000000..070a044c Binary files /dev/null and b/site/JY_HU/AI/assets/R.png differ diff --git a/site/JY_HU/AI/assets/ad3b7251fa90407eb7017f1d529490d8.png b/site/JY_HU/AI/assets/ad3b7251fa90407eb7017f1d529490d8.png new file mode 100644 index 00000000..978ab9b0 Binary files /dev/null and b/site/JY_HU/AI/assets/ad3b7251fa90407eb7017f1d529490d8.png differ diff --git a/site/JY_HU/AI/assets/image-20240102195030931.png b/site/JY_HU/AI/assets/image-20240102195030931.png new file mode 100644 index 00000000..f6993426 Binary files /dev/null and b/site/JY_HU/AI/assets/image-20240102195030931.png differ diff --git a/site/JY_HU/AI/assets/image-20240120202935801-1705753780433-57.png b/site/JY_HU/AI/assets/image-20240120202935801-1705753780433-57.png new file mode 100644 index 00000000..3d87992f Binary files /dev/null and b/site/JY_HU/AI/assets/image-20240120202935801-1705753780433-57.png differ diff --git a/site/JY_HU/AI/assets/image-20240120202935801.png b/site/JY_HU/AI/assets/image-20240120202935801.png new file mode 100644 index 00000000..3d87992f Binary files /dev/null and b/site/JY_HU/AI/assets/image-20240120202935801.png differ diff --git a/site/JY_HU/AI/assets/image-20240122103344840.png b/site/JY_HU/AI/assets/image-20240122103344840.png new file mode 100644 index 00000000..e63068fd Binary files /dev/null and b/site/JY_HU/AI/assets/image-20240122103344840.png differ diff --git a/site/JY_HU/AI/assets/image-20240122152121671.png b/site/JY_HU/AI/assets/image-20240122152121671.png new file mode 100644 index 00000000..bf177af8 Binary files /dev/null and b/site/JY_HU/AI/assets/image-20240122152121671.png differ diff --git a/site/JY_HU/AI/assets/image-20240122165410500.png b/site/JY_HU/AI/assets/image-20240122165410500.png new file mode 100644 index 00000000..a3a51ef3 Binary files /dev/null and b/site/JY_HU/AI/assets/image-20240122165410500.png differ diff --git a/site/JY_HU/AI/assets/image-20240123110821931-1705979304458-74.png b/site/JY_HU/AI/assets/image-20240123110821931-1705979304458-74.png new file mode 100644 index 00000000..f12fd891 Binary files /dev/null and b/site/JY_HU/AI/assets/image-20240123110821931-1705979304458-74.png differ diff --git a/site/JY_HU/AI/assets/image-20240123110821931.png b/site/JY_HU/AI/assets/image-20240123110821931.png new file mode 100644 index 00000000..f12fd891 Binary files /dev/null and b/site/JY_HU/AI/assets/image-20240123110821931.png differ diff --git a/site/JY_HU/AI/assets/image-20240123110904146.png b/site/JY_HU/AI/assets/image-20240123110904146.png new file mode 100644 index 00000000..c522a367 Binary files /dev/null and b/site/JY_HU/AI/assets/image-20240123110904146.png differ diff --git a/site/JY_HU/AI/assets/image-20240123170508438.png b/site/JY_HU/AI/assets/image-20240123170508438.png new file mode 100644 index 00000000..0f237c40 Binary files /dev/null and b/site/JY_HU/AI/assets/image-20240123170508438.png differ diff --git a/site/JY_HU/AI/assets/image-20240123211120304.png b/site/JY_HU/AI/assets/image-20240123211120304.png new file mode 100644 index 00000000..11a9500d Binary files /dev/null and b/site/JY_HU/AI/assets/image-20240123211120304.png differ diff --git a/site/JY_HU/AI/assets/image-20240124210645454.png b/site/JY_HU/AI/assets/image-20240124210645454.png new file mode 100644 index 00000000..4ce6c8f4 Binary files /dev/null and b/site/JY_HU/AI/assets/image-20240124210645454.png differ diff --git a/site/JY_HU/AI/assets/v2-1ef2dbc04eac36e74b219e88a2f7d078_1440w.jpg b/site/JY_HU/AI/assets/v2-1ef2dbc04eac36e74b219e88a2f7d078_1440w.jpg new file mode 100644 index 00000000..d9797a30 Binary files /dev/null and b/site/JY_HU/AI/assets/v2-1ef2dbc04eac36e74b219e88a2f7d078_1440w.jpg differ diff --git a/site/JY_HU/AI/assets/v2-6444601b4c41d99e70569b0ea388c3bd_1440w.png b/site/JY_HU/AI/assets/v2-6444601b4c41d99e70569b0ea388c3bd_1440w.png new file mode 100644 index 00000000..befa905c Binary files /dev/null and b/site/JY_HU/AI/assets/v2-6444601b4c41d99e70569b0ea388c3bd_1440w.png differ diff --git a/site/JY_HU/AI/assets/v2-76324941c4251678fb80b9ec9c957a05_1440w.webp b/site/JY_HU/AI/assets/v2-76324941c4251678fb80b9ec9c957a05_1440w.webp new file mode 100644 index 00000000..7284015e Binary files /dev/null and b/site/JY_HU/AI/assets/v2-76324941c4251678fb80b9ec9c957a05_1440w.webp differ diff --git a/site/JY_HU/AI/assets/v2-8f03a496d97441bdc436befc66bfeccb_1440w.webp b/site/JY_HU/AI/assets/v2-8f03a496d97441bdc436befc66bfeccb_1440w.webp new file mode 100644 index 00000000..758f154b Binary files /dev/null and b/site/JY_HU/AI/assets/v2-8f03a496d97441bdc436befc66bfeccb_1440w.webp differ diff --git a/site/JY_HU/AI/assets/v2-ced21dbc2d476ae37d61dce4376a1631_1440w.webp b/site/JY_HU/AI/assets/v2-ced21dbc2d476ae37d61dce4376a1631_1440w.webp new file mode 100644 index 00000000..121cd8d7 Binary files /dev/null and b/site/JY_HU/AI/assets/v2-ced21dbc2d476ae37d61dce4376a1631_1440w.webp differ diff --git a/site/JY_HU/AI/assets/v2-f0cd36d214b248c905f32680d3243279_1440w.webp b/site/JY_HU/AI/assets/v2-f0cd36d214b248c905f32680d3243279_1440w.webp new file mode 100644 index 00000000..d9d58c9d Binary files /dev/null and b/site/JY_HU/AI/assets/v2-f0cd36d214b248c905f32680d3243279_1440w.webp differ diff --git a/site/JY_HU/AI/d2l-zh-pytorch/index.html b/site/JY_HU/AI/d2l-zh-pytorch/index.html new file mode 100644 index 00000000..45407102 --- /dev/null +++ b/site/JY_HU/AI/d2l-zh-pytorch/index.html @@ -0,0 +1,5365 @@ + + + + + + + + + + + + + + + + + + + + + + + + + d2l笔记 - JY-HF learning site + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + + + + 跳转至 + + +
    +
    + +
    + + + + +
    + + +
    + +
    + + + + + + + + + +
    +
    + + + +
    +
    +
    + + + + + + + + + +
    +
    +
    + + + + +
    +
    + + + + + + + +

    d2l-zh-pytorch

    +

    image-20240123211120304

    +

    1.20

    +

    torch.tensor使用

    +

    广播机制

    +

    降维

    +
    Python
    torch.tensor()
    +
    +

    轴(axis)就是张量的维度

    +

    torch.arange(a): 生成从0~a-1的一个向量

    +

    torch.dot

    +

    数据预处理:pandas用法

    +
    Python
     1
    + 2
    + 3
    + 4
    + 5
    + 6
    + 7
    + 8
    + 9
    +10
    +11
    +12
    +13
    +14
    +15
    +16
    +17
    +18
    import pandas as pd
    +import torch
    +
    +data = pd.read_csv(data_file) #假设已经写好了csv文件,使用pandas的read_csv方法创建数据集
    +print(data)  
    +
    +#输出为:
    +NumRooms Alley Price
    +0 NaN Pave 127500
    +1 2.0 NaN 106000
    +2 4.0 NaN 178100
    +3 NaN NaN 140000
    +
    +inputs, outputs = data.iloc[:, 0:2], data.iloc[:, 2]
    +inputs = inputs.fillna(inputs.mean()) #data有iloc,fillna,get_dummies等方法
    +
    +X = torch.tensor(inputs.to_numpy(dtype=float))
    +y = torch.tensor(outputs.to_numpy(dtype=float)) #在处理好数据中的缺失后,从数值转化成tensor
    +
    +

    反向传播:autograd

    +

    输出的y是x的多元函数,对\(x_i\)求偏导的格式为:

    +

    image-20240120202935801

    +

    例如\(y=2X^TX\)

    +

    y是标量,x是一个向量

    +
    Python
     1
    + 2
    + 3
    + 4
    + 5
    + 6
    + 7
    + 8
    + 9
    +10
    +11
    +12
    +13
    +14
    import torch
    +x = torch.arange(4.0)  #输出 tensor([0.,1.,2.,3.])
    +x.requires_grad_(True) # 等价于x=torch.arange(4.0,requires_grad=True)
    +x.grad # 默认值是None
    +y = 2 * torch.dot(x, x)
    +y.backward()
    +x.grad  #输出为:tensor([ 0., 4., 8., 12.])
    +x.grad == 4 * x #输出为: tensor([True, True, True, True]) 
    +
    +# 再计算另外一个函数的梯度值:
    +x.grad.zero_()  # 在默认情况下,PyTorch会累积梯度,我们需要清除之前的值
    +y = x.sum()
    +y.backward()
    +x.grad  #输出tensor([1., 1., 1., 1.])
    +
    +

    1.22

    +

    引入激活函数的理由:

    +

    1.各层级之间的线性操作可以直接等价于一层线性操作

    +

    2.由于线性组合相当于是对原始参数矩阵张成的空间进行伸缩,旋转和剪切

    +

    但是可能真实世界有些原始数据本身就是线性不可分的,必须要对原始空间进行一定的非线性操作(对原空间进行一定的扭曲?)

    +

    对于回归问题也可以同样运用高数的思维,把回归看成分类问题的无限细分,当极限存在时,分类也就成为了回归问题。

    +

    激活函数应该具有的特征 +避免梯度消失的特性,造成网络更新过慢 +输出最好关于0对称,这样就不会造成梯度向特定方向移动 +激活函数应该为神经网络引入非线性 +激活函数应该是可微的,使得满足各层之间梯度下降的计算(至少部分可微) +梯度的计算不应该太复杂,影响网络性能

    +

    img

    +
    C
     1
    + 2
    + 3
    + 4
    + 5
    + 6
    + 7
    + 8
    + 9
    +10
    +11
    +12
    +13
    +14
    +15
    +16
    +17
    +18
    +19
    +20
    +21
    +22
    +23
    +24
    +25
    +26
    +27
    +28
    +29
    +30
    +31
    +32
    +33
    +34
    class Model(Module):
    +    def __init__(self):
    +        super(Model, self).__init__()
    +        self.conv1 = nn.Conv2d(1, 6, 5)
    +        #1,6,5分别表示输入通道数,输出通道数,卷积核大小
    +        self.relu1 = nn.ReLU()
    +        self.pool1 = nn.MaxPool2d(2)
    +        self.conv2 = nn.Conv2d(6, 16, 5)
    +        self.relu2 = nn.ReLU()
    +        self.pool2 = nn.MaxPool2d(2)
    +        self.fc1 = nn.Linear(256, 120)
    +        self.relu3 = nn.ReLU()
    +        self.fc2 = nn.Linear(120, 84)
    +        self.relu4 = nn.ReLU()
    +        self.fc3 = nn.Linear(84, 10)
    +        self.relu5 = nn.ReLU()
    +
    +    def forward(self, x):
    +        y = self.conv1(x)
    +        y = self.relu1(y)
    +        y = self.pool1(y)
    +        y = self.conv2(y)
    +        y = self.relu2(y)
    +        y = self.pool2(y)
    +        y = y.view(y.shape[0], -1)
    +        # 此处view操作是为了将y的形状从[b, c, h, w]变为[b, c*h*w],以便送入全连接层
    +        # -1的涵义是自适应,即自动计算此处应填多少
    +        y = self.fc1(y)
    +        y = self.relu3(y)
    +        y = self.fc2(y)
    +        y = self.relu4(y)
    +        y = self.fc3(y)
    +        y = self.relu5(y)
    +        return y
    +
    +

    image-20240122103344840

    +

    Transformer各层网络结构详解!面试必备!(附代码实现) - 掘金

    +

    上图是论文中 Transformer 的内部结构图,左侧为 Encoder block,右侧为 Decoder block。红色圈中的部分为 Multi-Head Attention,是由多个 Self-Attention组成的,可以看到 Encoder block 包含一个 Multi-Head Attention,而 Decoder block 包含两个 Multi-Head Attention (其中有一个用到 Masked)。Multi-Head Attention 上方还包括一个 Add & Norm 层,Add 表示残差连接 (Residual Connection) 用于防止网络退化,Norm 表示 Layer Normalization,用于对每一层的激活值进行归一化。

    +

    跟李沐学ai

    +

    masked multi-head attention

    +

    batch norm 和layer norm的区别

    +

    ChatGPT

    +

    ChatGPT

    +

    Batch Normalization(批归一化,简称 Batch Norm)和 Layer Normalization(层归一化,简称 Layer Norm)是用于神经网络中的正则化技术,它们有一些关键的区别:

    +
      +
    1. 归一化的层级:
    2. +
    3. Batch Normalization: 归一化是在每个 mini-batch 中的每个特征维度上进行的。它对每个特征维度进行平均和标准差的归一化,因此可以看作是对 mini-batch 维度和特征维度的归一化。
    4. +
    5. Layer Normalization: 归一化是在每个样本的每个特征维度上进行的。它对每个特征维度进行平均和标准差的归一化,因此可以看作是对样本维度和特征维度的归一化。
    6. +
    7. 归一化的计算方式:
    8. +
    9. Batch Normalization: 对于每个特征维度,计算 mini-batch 中所有样本的均值和标准差。使用这些均值和标准差进行归一化。
    10. +
    11. Layer Normalization: 对于每个样本的每个特征维度,计算该样本的均值和标准差。使用这些均值和标准差进行归一化。
    12. +
    13. 计算时的依赖关系:
    14. +
    15. Batch Normalization: 在训练时,由于需要计算 mini-batch 的均值和标准差,因此需要使用当前 mini-batch 中的所有样本。在测试时,通常使用训练阶段计算的移动平均值进行归一化。
    16. +
    17. Layer Normalization: 在训练和测试时都是独立计算每个样本的均值和标准差,因此不需要使用 mini-batch。
    18. +
    19. 适用场景:
    20. +
    21. Batch Normalization: 在深度神经网络中,特别是卷积神经网络(CNNs)中广泛使用,对于深层网络的训练有助于梯度传播。
    22. +
    23. Layer Normalization: 更适用于循环神经网络(RNNs)等不适合使用 mini-batch 归一化的场景,因为 RNNs 的输入序列长度可能不同。
    24. +
    +

    总体而言,Batch Normalization 和 Layer Normalization都是用于加速神经网络训练、防止梯度消失和梯度爆炸的方法,但它们的实现和应用场景有所不同。

    +

    残差连接(Residual Connection)是一种神经网络中的建模技术,旨在解决深度神经网络训练过程中的梯度消失和梯度爆炸问题。这一技术最初由何恺明等人提出,并在2016年的论文 "Deep Residual Learning for Image Recognition" 中首次引入。

    +

    在残差连接中,网络的某些层(通常是卷积层)的输入直接通过跳跃连接(skip connection)添加到网络的输出中。这样的连接使得网络可以直接学习残差,而不是完整地学习特征映射。残差连接的数学表达如下:

    +

    输出=输入+残差输出=输入+残差

    +

    具体而言,如果 �(�)F(x) 表示网络的映射函数(例如卷积层和激活函数的组合),那么残差块的输出为:

    +

    输出=�(�)+�输出=F(x)+x

    +

    其中,�x 是输入。

    +

    残差连接的主要优势包括:

    +
      +
    1. 解决梯度消失问题: 通过直接传播残差,梯度可以更轻松地传播回较早的层,从而减轻了梯度消失问题。
    2. +
    3. 简化网络训练: 使得更深的网络更容易训练,因为网络可以学习将输入直接传递到输出的恒等映射,而不需要对输入进行复杂的变换。
    4. +
    5. 降低特征映射学习的难度: 网络可以选择性地学习残差,而不是完整地学习特征映射,这有助于更好地捕捉数据中的变化。
    6. +
    +

    残差连接在许多深度学习任务中都取得了显著的成功,并被广泛用于各种架构,如 ResNet、DenseNet 等。

    +

    img

    +

    注意力函数:scaled dot-product attention

    +

    \(\(Attention(Q,K,V)=softmax(QK^T / sqrt(d_k)) V\)\)

    +

    将query和key-value对

    +

    output是value的加权和

    +

    value的加权和是query和key的相似度算出的

    +

    key是名字,query是想查谁的名字,也是一个名字,value是key对应的值

    +

    关于矩阵乘法:非常便于并行

    +

    假设进行了n次query,dk为key的特征维度数,dv为单词特征维数,一般来说dk和dv相同

    +

    一般来说Query,Key,Value矩阵的形状一致

    +

    Query矩阵 n行dk列

    +

    Key矩阵 m行dk列

    +

    weight矩阵 n行m列,每一行都是一次query,对应一个单词

    +

    value矩阵,m行dv列,每一列是一个单词,dv是单词特征的维度

    +

    output矩阵,n行dv列,n次query,输出了

    +

    multi-head 多头注意力机制,拆开来再合并

    +

    在模型中attention机制的三次使用场景

    +
      +
    1. 开始输入的时候,一个输入复用为三条线,Q,K,V都是自己本身
    2. +
    3. masked-multihead-attention 来源于上一层decoder的输出,也是复用三次
    4. +
    5. multihead-attention,key-value对来源于decoder,query来源于encoder
    6. +
    +

    如下图,在第一次multi-head-attention之后,实际上整个序列的信息已经通过attention层,把不同的query和position encoding被拆解成独立的部分,和RNN不同

    +

    image-20240122152121671

    +

    ResNet 残差网络

    +

    很深的神经网络误差变大的问题

    +

    不是过拟合造成的

    +

    "Identity mapping" 是深度学习领域中一个重要的概念,通常与残差网络(Residual Networks,简称 ResNets)相关。

    +

    在深度卷积神经网络中,当模型变得非常深时,训练变得更加困难。梯度消失和梯度爆炸是训练深度网络时常见的问题之一。为了解决这个问题,ResNet 引入了残差块(Residual Block),其中的关键部分就是 "identity mapping"。

    +

    Identity Mapping 的定义:

    +

    在 ResNet 的残差块中,通过引入跳跃连接(skip connection)和 "identity mapping",使得网络可以直接学习残差(residual)。具体而言,对于一个残差块,其输出可以表示为:

    +

    Output=F(Input)+Input

    +

    其中,F(Input) 是经过残差块内部操作的结果,Input 是输入。上式中的 "input" 就是 "identity mapping",它允许模型学习对输入进行恒等映射(即不进行任何变换)。

    +

    作用和优势:

    +
      +
    1. 梯度流动: "Identity mapping" 使得梯度可以更直接地传播回网络的较早层,有助于缓解梯度消失问题,使训练更加稳定。
    2. +
    3. 模型学习残差: 通过引入 "identity mapping",模型可以选择性地学习对输入进行变换,而不是必须学习整个映射。这有助于模型更轻松地适应底层和高层的特征。
    4. +
    5. 网络深度: ResNet 中的 "identity mapping" 允许构建非常深的网络,而不会导致训练困难。这使得 ResNet 成为处理复杂任务的强大工具。
    6. +
    +

    总体而言,"identity mapping" 在深度学习中的应用是为了提高模型的训练稳定性和深度网络的可训练性。

    +

    mapping 投影 线性映射

    +

    image-20240122165410500

    +

    在深度学习中,"downsample" 和 "upsample" 是指改变输入数据的空间分辨率的操作。

    +
      +
    1. Downsample(下采样):
    2. +
    3. 下采样是指将输入数据的空间分辨率降低的过程。在图像处理中,这通常通过降低图像的宽度和高度来实现。常见的下采样操作包括池化(Pooling)和步幅大于1的卷积操作。
    4. +
    5. 池化操作中,通常使用最大池化或平均池化,将每个池化窗口内的数值合并为一个单一的值,从而降低空间分辨率。
    6. +
    7. Upsample(上采样):
    8. +
    9. 上采样是指将输入数据的空间分辨率增加的过程。在图像处理中,这通常通过插值操作来实现。常见的上采样操作包括反卷积(Deconvolution)和转置卷积(Transpose Convolution)。
    10. +
    11. 上采样的目标是通过填充额外的像素或特征来增加图像的维度,从而提高空间分辨率。
    12. +
    +

    这两个操作在深度学习中经常用于神经网络的不同层次和任务:

    +
      +
    • 特征提取层: 在卷积神经网络(CNNs)中,下采样通常在卷积层中进行,以减少特征图的空间维度,捕捉更高级的特征。池化操作是常见的下采样方法。
    • +
    • 特征生成层: 在某些任务中,如图像分割或生成,上采样用于增加特征图的空间分辨率,使其能够输出与输入相同大小的结果。反卷积或转置卷积是常见的上采样方法。
    • +
    +

    这些操作在神经网络中的使用可以根据任务和网络结构的需求而变化。

    +

    1.23

    +

    43a69d21d6ca9b411ebbdaaeafb292b

    +

    "LR" 在深度学习领域中通常指的是逻辑回归(Logistic Regression),是一种用于二分类问题的模型。对于逻辑回归模型,通常使用二元交叉熵损失函数(Binary Cross Entropy Loss)作为损失函数,而不是传统的均方误差损失。

    +

    逻辑回归的损失函数为:

    +

    \(\text{Binary Cross Entropy Loss} = - \frac{1}{N} \sum_{i=1}^{N} \left[ y_i \log(p_i) + (1 - y_i) \log(1 - p_i) \right]\)

    +

    其中:

    +
      +
    • \(N\) 是样本数量。
    • +
    • \(y_i\) 是第 \(i\) 个样本的真实标签。
    • +
    • \(p_i\) 是模型对第 \(i\) 个样本的预测概率。
    • +
    +

    优化损失函数的过程通常使用梯度下降法或其变种。梯度下降法的基本思想是通过迭代调整模型参数,使损失函数最小化。

    +
      +
    1. 梯度计算: 计算损失函数对模型参数的梯度。对于逻辑回归,这可以通过反向传播算法计算得到。
    2. +
    3. +

      参数更新: 使用梯度下降法或其他优化算法更新模型参数。更新规则通常为 \(\theta_{\text{new}} = \theta_{\text{old}} - \alpha \nabla L\),其中 \(\alpha\) 是学习率,▽L 是损失函数关于模型参数的梯度。

      +
    4. +
    5. +

      迭代: 重复上述步骤,直到满足停止条件,如达到最大迭代次数或梯度接近零。

      +
    6. +
    +

    对于逻辑回归,由于损失函数是凸函数,梯度下降法通常能够收敛到全局最小值。学习率的选择很重要,过大的学习率可能导致不稳定的训练,而过小的学习率可能导致收敛缓慢。

    +

    在 PyTorch 中,你可以使用自动微分和优化器来实现梯度下降。例如:

    +
    Python
     1
    + 2
    + 3
    + 4
    + 5
    + 6
    + 7
    + 8
    + 9
    +10
    +11
    +12
    +13
    +14
    +15
    +16
    +17
    +18
    +19
    +20
    +21
    import torch
    +import torch.nn as nn
    +import torch.optim as optim
    +
    +# 定义逻辑回归模型
    +model = nn.Linear(in_features, out_features)
    +# 定义损失函数
    +criterion = nn.BCEWithLogitsLoss()
    +# 定义优化器
    +optimizer = optim.SGD(model.parameters(), lr=learning_rate)
    +# 训练过程
    +for epoch in range(num_epochs):
    +    # 前向传播
    +    outputs = model(inputs)
    +    # 计算损失
    +    loss = criterion(outputs, labels)
    +    # 反向传播
    +    optimizer.zero_grad()
    +    loss.backward()
    +    # 参数更新
    +    optimizer.step()
    +
    +

    SVM原理简析

    +

    怎样才是最好的分割:

    +

    “分的清,没有含糊不清的点”:各点离平面的距离设为\(r_i\),求使得所有\(r_i\)的最小值最大的一个分割

    +

    理解凸优化 - 知乎 (zhihu.com)

    +

    支持向量机(SVM)——原理篇 (zhihu.com)

    +

    pytorch自定义数据集使用

    +

    pytorch--transform工具箱及用法

    +
    Python
    1
    +2
    +3
    +4
    +5
    +6
    +7
    from torchvision import transforms
    +from PIL import image
    +
    +img_path = "relative/path/to/image"
    +img = Image.open(img_path)
    +print(img)  #<PIL.JpegImage.JpegImageFile image mode=RGB size = 768x512 at 0275820fe60>
    +tensor_trans = transforms.ToTensor(img)
    +
    +
    Python
    1
    +2
    +3
    +4
    +5
    from torch.utils.tensorboard import SummaryWriter
    +writer = SummaryWriter("logs")
    +
    +writer.add_image("Tensor_img",tensor_img)
    +writer.close()
    +
    +

    ToTensor

    +

    把PIL Image 或者 numpy.ndarray转换为tensor类型

    +
    Python
    1
    +2
    +3
    +4
    +5
    +6
    train_augs = torchvision.transforms.Compose([
    +torchvision.transforms.RandomHorizontalFlip(),
    +torchvision.transforms.ToTensor()])
    +
    +test_augs = torchvision.transforms.Compose([
    +torchvision.transforms.ToTensor()])
    +
    +

    resize

    +

    torchvision提供的标准数据集和transform结合使用

    +

    标准数据集网址:Datasets — Torchvision 0.16 documentation (pytorch.org)

    +

    torchvision — Torchvision master documentation (pytorch.org)

    +
    Python
     1
    + 2
    + 3
    + 4
    + 5
    + 6
    + 7
    + 8
    + 9
    +10
    +11
    +12
    +13
    +14
    #torchvision官方数据集和transforms联合使用
    +import torchvision
    +from torch.utils.tensorboard import SummaryWriter
    +dataset_transform = torchvision.transforms.Compose([
    +    torchvision.transforms.ToTensor()
    +])
    +train_set = torchvision.datasets.CIFAR10(root = "./dataset",train = True,download=True,transform=dataset_transform)
    +test_set = torchvision.datasets.CIFAR10(root = "./dataset",train = False,download=True,transform=dataset_transform)
    +#下载后解压
    +print(train_set[0])
    +writer = SummaryWriter("cifar10")  #新建的tensorboard日志的路径文件夹名称
    +for i in range(10):
    +    img, target = test_set[i]
    +    writer.add_image("test_set",img,i)  #图片在tensorboard会话中的名称
    +
    +

    tensorboard使用:

    +

    commandline:tensorboard --logdir = "mydirname"

    +

    或在vscode中启动tensorboard会话也可

    +

    pytorch-dataloader使用

    +

    把dataset中的数据一个个加载到神经网络中

    +

    dataloader类属性:

    +

    ​ dataset,from which to load the data

    +

    ​ batch_size,每次抓几张牌

    +

    ​ shuffle ,每个epoch是否重新加载

    +

    ​ num_workers 主进程加载,=0,>0对windows可能有问题,broken pipes

    +

    ​ drop_last 舍去最后一份牌,是否保留整数

    +

    image-20240123170508438

    +

    torch-nn使用

    +
    Python
     1
    + 2
    + 3
    + 4
    + 5
    + 6
    + 7
    + 8
    + 9
    +10
    +11
    +12
    import torch.nn as nn
    +import torch.nn.functional as F
    +
    +class Model(nn.Module)
    +    def __init__(self):
    +        super(Model,self).__init__()
    +        self.conv1 = nn.Conv2d(1,20,5)
    +        self.conv2 = nn,Conv2d(20,20,5)
    +
    +    def forward(self,x)
    +        x = F.relu(self.conv1(x))
    +        return F.relu(self.conv2(x))
    +
    +

    torch-sequential 结合CIFAR-10数据集使用

    +

    Structure of CIFAR10-quick model. | Download Scientific Diagram

    +

    层的参数设置:

    +
    Python
    1
    +2
    +3
        Conv2d(input_channel,output_channel,kernel_size,padding)
    +    #比如input 的通道数为前后相同方块的大小 为3,output channel为32,kernel_size为5,padding为2
    +    maxpool2d(size)
    +
    +

    微调 迁移学习

    +
      +
    1. 迁移学习将从源数据集中学到的知识迁移到目标数据集,微调是迁移学习的常见技巧。
    2. +
    3. 除输出层外,目标模型从源模型中复制所有模型设计及其参数,并根据目标数据集对这些参数进行微 + 调。但是,目标模型的输出层需要从头开始训练。
    4. +
    5. 通常,微调参数使用较小的学习率,而从头开始训练输出层可以使用更大的学习率。
    6. +
    +

    img

    +

    ​ VGG 网络结构示意

    +

    计算机视觉基础知识

    +

    我们以图像的每个像素为中心生成不同形状的锚框。 +• 交并比(IoU)也被称为杰卡德系数,用于衡量两个边界框的相似性。它是相交面积与相并面积的比率。 +• 在训练集中,我们需要给每个锚框两种类型的标签。一个是与锚框中目标检测的类别,另一个是锚框真 +实相对于边界框的偏移量。 +• 预测期间可以使用非极大值抑制(NMS)来移除类似的预测边界框,从而简化输出。

    +

    非极大值抑制 NMS

    +

    NMS(非极大值抑制,Non-Maximum Suppression)是一种常用于目标检测任务的技术,用于从一组重叠的候选框中选择最符合条件的框。其主要原理是消除多余的、与最终选择框高度重叠的候选框,以确保最终输出的框具有最佳的质量和非重叠性。

    +

    以下是NMS的基本原理:

    +
      +
    1. 得分排序: 首先,对所有的候选框按照其得分(置信度或其他评估指标)进行降序排列。通常,得分越高的框越有可能是正确的目标。
    2. +
    3. 选择最高得分框: 选取得分最高的候选框作为输出,将其加入最终的输出结果集合。
    4. +
    5. 计算重叠面积: 计算当前选择的框与剩余的候选框的重叠面积。这里常用的是 IoU(Intersection over Union)指标,即两个框相交面积与它们的并集面积之比。
    6. +
    7. 删除重叠框: 对于与当前选择的框重叠面积超过某个设定的阈值的其他候选框,将其从候选框集合中移除。
    8. +
    9. 重复步骤2至步骤4: 重复以上步骤,选择下一个得分最高的框,然后删除与它重叠面积超过阈值的其他框。直到所有的候选框都被处理。
    10. +
    +

    这样,NMS 确保了最终输出的框具有较高的得分,并且彼此之间有较低的重叠度。这对于目标检测任务很重要,因为它可以防止在同一个目标上产生多个高度重叠的检测结果,从而提高检测的准确性。

    +

    单发多框检测 SSD

    +

    "单发多框检测"(Single Shot Multibox Detection,SSD)是一种用于目标检测的深度学习架构,旨在实现快速而准确的目标检测。SSD是一种多尺度、多框架的检测方法,能够在一次前向传播中检测图像中的多个目标。

    +

    以下是SSD的主要特点和原理:

    +
      +
    1. 多尺度特征图: SSD 在卷积神经网络中引入了多个不同尺度的特征图。每个特征图对应于网络的不同层,具有不同的感受野和分辨率。这样可以使网络在不同尺度上对目标进行检测。
    2. +
    3. 多框框架: 对于每个尺度的特征图,SSD 通过预定义的一系列锚框(anchor boxes)来检测不同形状和尺寸的目标。每个锚框与网络的每个空间位置相关联,通过卷积层的预测来输出目标的位置和类别信息。
    4. +
    5. 损失函数: SSD 使用多任务损失函数,同时考虑位置回归和类别分类。位置回归损失关注锚框的位置精度,而类别分类损失关注预测的目标类别。
    6. +
    7. 非极大值抑制(NMS): 在SSD的输出中,采用非极大值抑制来移除高度重叠的框,以提高检测的准确性。NMS通过保留具有最高置信度的框,并消除与其高度重叠的其他框。
    8. +
    9. 实时性能: SSD设计旨在实现实时目标检测。通过一次前向传播,SSD可以在图像中检测多个目标,并提供目标的位置和类别信息。
    10. +
    +

    SSD的设计使得它在准确性和速度之间取得了平衡,使其成为在实际应用中广泛使用的目标检测框架之一。它适用于各种尺寸和形状的目标,并且在复杂的场景中表现良好

    +

    img

    +

    1.24 多模态模型

    +

    gradio

    +

    特化的AI前端界面,语法非常轻量级,采用很多block搭建交互式的web UI

    +

    强化学习

    +

    huggingface

    +

    Zero-shot image classification is a computer vision task to classify images into one of several classes, without any prior training or knowledge of the classes. Zero shot image classification works by transferring knowledge learnt during training of one model, to classify novel classes that was not present in the training data.

    +

    CLIP:openai的clip模型,Contrastive Language-Image Pre-training

    +

    img

    +

    GLIP简介:Grounded Language-Image Pre-training

    +

    目前的视觉识别任务通常是在一个预先定义好的类别范围内进行的,这样限制了其在真实场景中的扩展。CLIP的出现打破了这一限制,CLIP利用image-text对进行训练,从而使得模型可以根据文字prompt识别任意类别。关于CLIP的详细介绍可以看我的文章:深度解读CLIP:打破文字与图像之间的壁垒。CLIP适用于分类任务,而GLIP尝试将这一技术应用于目标检测等更加复杂的任务中。

    +

    +

    在多模态网络(Multimodal Network)中,通常会使用类似于单模态网络的结构,但在设计上进行了一些调整以处理多个模态(例如图像、文本、声音等)的输入。其中,backbone、neck 和 head 是网络的不同部分,各自有不同的功能。

    +
      +
    1. Backbone:
    2. +
    3. 定义: Backbone 是网络的主干部分,负责提取输入数据的高级特征表示。在多模态网络中,可能存在多个并行的 backbone,每个用于处理不同的输入模态。
    4. +
    5. 功能: 提取共享的低级和中级特征,以捕捉不同输入模态的共性信息。
    6. +
    7. Neck:
    8. +
    9. 定义: Neck 是连接 backbone 和 head 的中间部分,通常位于网络的中心。它可以包含一系列的层或模块,有助于整合来自不同模态的特征。
    10. +
    11. 功能: 实现特征的融合或整合,以便更好地处理多模态信息。在 neck 中,可以应用一些融合策略,例如注意力机制、融合层等,以加强不同模态之间的关联性。
    12. +
    13. Head:
    14. +
    15. 定义: Head 是网络的最后部分,负责执行任务特定的输出。在多模态网络中,可能存在多个 head,每个用于处理不同的任务或输出模态。
    16. +
    17. 功能: 生成最终的任务输出,例如分类、回归或生成任务的结果。每个 head 可以专注于处理与其任务相关的特征表示。
    18. +
    +

    总体而言,backbone 负责提取共享的特征,neck 负责整合多模态特征,而 head 则专注于执行具体的任务。多模态网络的设计需要考虑如何在这三个部分中合理地处理不同模态的信息,以实现对多模态输入的有效建模。不同的应用场景和任务可能需要不同的架构设计。

    +

    grounding DINO:根据文字提示检测任意目标

    +

    img

    +
      +
    • Phasa A: 设计了结合self-attention、text-to-image cross-attention、image-to-text attention的特征enhancer应用在Neck中;
    • +
    • Phasa B: 设计了一个language-guided query selection方法用于初始化Head的query;
    • +
    • Phasa C: 设计了一个跨模态的decoder用于Head部分,从而增强query的特征表达。
    • +
    +

    img

    +

    SAM-track model

    +

    “Segment and Track Anything” 利用自动和交互式方法。主要使用的算法包括 SAM(Segment Anything Models)用于自动/交互式关键帧分割,以及 DeAOT(Decoupling features in Associating Objects with Transformers)(NeurIPS2022)用于高效的多目标跟踪和传播。SAM-Track 管道实现了 SAM 的动态自动检测和分割新物体,而 DeAOT 负责跟踪所有识别到的物体。

    +

    image-20240124210645454

    +

    AOT(associating objects with transformers)网络介绍

    +

    [NIPS21][CVPR21竞赛冠军] Associating Objects with Transformers for Video Object Segmentation - 知乎 (zhihu.com)

    +

    DeAOT achieves promising results on various benchmarks. However, as a semi-supervised video segmentation model, DeAOT requires reference frame annotations for initialization, which limits its application.

    +

    半监督视频目标分割

    +

    1.25

    +

    VILT

    +

    vision transformer

    +

    把目标检测从视觉端移除?

    +

    用预训练的目标检测器去抽取视觉特征的时候会有很多局限性

    +

    视觉特征:patch embedding?

    +

    模态融合部分非常大

    +

    推理时间和训练时间复杂度?

    +

    模型推理过程

    +

    模型的推理时间指的是使用训练好的机器学习或深度学习模型进行实际预测或推断的时间。在模型训练之后,模型通常需要通过输入数据进行推理,即根据学到的规律或模式对新的未见过的数据进行预测或分类。

    +

    推理时间是衡量模型性能的一个重要指标,尤其是在实际应用中,对于需要快速响应的场景,推理时间的效率至关重要。推理时间的快慢受到多个因素的影响,包括但不限于:

    +
      +
    1. 模型复杂度: 复杂的模型通常需要更多的计算资源来执行推理,因此推理时间可能更长。
    2. +
    3. 硬件设备: 推理时间与使用的硬件设备密切相关。GPU(图形处理单元)通常能够提供比 CPU 更快的推理速度,而专用的硬件加速器(如TPU、FPGA等)可能进一步提高推理性能。
    4. +
    5. 输入数据大小: 处理更大规模的输入数据可能会增加推理时间,因为模型需要在更多的数据上执行计算。
    6. +
    7. 模型优化: 通过模型剪枝、量化(Quantization)、深度学习加速库等技术,可以优化模型,减少推理时间。
    8. +
    9. 并发性: 模型是否能够有效地利用并行计算能力也会影响推理时间。一些框架和库提供了多线程或分布式计算的支持,以提高并发性。
    10. +
    +

    因此,模型的推理时间是在实际部署或使用过程中,模型处理输入数据所需的时间,直接关系到模型在实际应用中的实用性和性能。

    +

    CLIP是典型的双塔模型,特征

    +

    VE TE MI

    +

    VE: Visual embedding

    +

    TE: Text embedding

    +

    MI: modality interaction

    +

    VQA,VR,VE

    +

    VQA(Visual Question Answering)、VR(Visual Reasoning)和VE(Visual Explanation)是三个涉及多模态(图像和文本)的任务,它们在计算机视觉和自然语言处理领域中有着不同的目标和侧重点。

    +
      +
    1. VQA(Visual Question Answering):
    2. +
    3. 概念: VQA 是一种任务,旨在使计算机能够回答关于图像内容的自然语言问题。通常,输入是一张图像和一个与图像相关的问题,输出是该问题的自然语言答案。
    4. +
    5. 应用: VQA 在图像理解、智能问答系统和视觉场景理解等领域具有广泛应用。它要求系统理解图像内容,理解问题,并生成相应的文本答案。
    6. +
    7. VR(Visual Reasoning):
    8. +
    9. 概念: VR 是一种任务,旨在通过对视觉场景进行推理来回答更为复杂的问题。与简单的问题答案不同,VR 要求模型通过对图像中的关系、场景和对象进行推理,更深层次地理解视觉信息。
    10. +
    11. 应用: VR 的应用范围包括智能图像理解、决策支持系统等,要求系统不仅能够识别图像中的对象,还能够进行高级的推理和分析。
    12. +
    13. VE(Visual Explanation):
    14. +
    15. 概念: VE 是一种任务,旨在通过生成视觉解释来回答问题。除了提供简单的答案外,VE 要求系统生成图像或图形化的解释,以说明为什么给定的答案是正确的。
    16. +
    17. 应用: VE 在教育、可解释性人工智能等领域具有应用潜力。通过生成解释,系统可以更好地与用户交互,并提高对模型决策的理解。
    18. +
    +

    这些任务都涉及到图像和文本之间的跨模态理解和交互,要求计算机系统能够处理视觉信息和自然语言信息的复杂关系。这些任务在推动计算机视觉和自然语言处理交叉研究的发展,使计算机能够更全面地理解和处理多模态信息。

    +

    ALBEF之前的论文总结:

    +

    视觉特征在图像处理中比文本特征要重要

    +

    模态融合部分也非常关键

    +

    Visual Encoder > Modality Interaction > Text Encoder

    +

    目标函数总结:

    +

    CLIP使用的 ITC lost :image text contrasting

    +

    (word patch alignment WPA lost训练起来非常慢)

    +

    masked laguage modeling :MLM lost, 完形填空

    +

    image text matching lost: ITM lost

    +

    img

    +

    ​ 多模态大模型综述(插图)

    +

    ALBEF : ALign BEfore Fuse:在融合文本和图像特征前就对齐特征

    +

    vision and language representation learning with momentum distillation

    +

    不需要使用bounding box annotation(锚框定位及标注)

    +

    momentum distilliation

    +

    momentum encoder

    +

    自训练模型

    +

    何恺明:MAE(Masked Autoencoders) - 知乎 (zhihu.com)

    + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + +
    + + + +
    + + + +
    +
    +
    +
    + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/site/JY_HU/AI/interview-questions/index.html b/site/JY_HU/AI/interview-questions/index.html new file mode 100644 index 00000000..aed0dd5c --- /dev/null +++ b/site/JY_HU/AI/interview-questions/index.html @@ -0,0 +1,4727 @@ + + + + + + + + + + + + + + + + + + + + + + + + + AI算法岗面试问题汇总 - JY-HF learning site + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + +
    +
    + +
    + + + + +
    + + +
    + +
    + + + + + + + + + +
    +
    + + + +
    +
    +
    + + + + + + + + + +
    +
    +
    + + + + +
    +
    + + + + + + + +

    AI算法岗面试问题汇总

    + +

    1. 解释SVM的工作原理。

    +

    SVM,全称支持向量机(Support Vector Machine),是一种有监督学习算法,主要用于解决数据挖掘或模式识别领域中的数据分类问题。

    +

    SVM的工作原理是建立一个最优决策超平面,使得该平面两侧距平面最近的两类样本之间的距离最大化,从而对分类问题提供良好的泛化力(推广能力)。这里的“支持向量”是指训练集中的某些训练点,这些点最靠近分类决策面,是最难分类的数据点。

    +

    SVM可以处理二类分类问题,也可以扩展到多类分类问题。在二类分类问题中,SVM寻找一个最优超平面,将两类样本分隔开。这个最优超平面需要满足间隔最大化的条件,即两侧距平面最近的两类样本之间的距离最大化。当训练样本线性可分时,通过硬间隔最大化,学习一个线性分类器,即线性可分支持向量机。当训练数据近似线性可分时,引入松弛变量,通过软间隔最大化,学习一个线性分类器,即线性支持向量机。当训练数据线性不可分时,通过使用核技巧及软间隔最大化,学习非线性支持向量机。

    +

    SVM使用核函数来处理非线性可分的情况。核函数的定义是K(x,y)=<ϕ(x),ϕ(y)>,即在特征空间的内积等于它们在原始样本空间中通过核函数K计算的结果。通过使用核函数,SVM可以将样本从原始空间映射到一个更高维的特征空间,使得样本在这个特征空间内线性可分。

    +

    2. k-means和k-means++算法有什么区别?

    +

    两者之间的唯一区别是初始化质心的方式。在k-means算法中,质心从给定点随机初始化。这种方法存在一个缺点,即有时这种随机初始化会导致非优化的聚类,这是由于两个聚类的初始化可能彼此接近。

    +

    为了解决这个问题,k-means++算法应运而生。在k-means++中,第一个质心从数据点中随机选择。后续质心的选择基于它们与初始质心的分离。一个点被选为下一个质心的概率与该点和已经被选择的最近质心之间的平方距离成比例。这保证了质心均匀地分散开,并降低了收敛到不理想聚类的可能性。这有助于算法达到全局最小值,而不是陷入局部最小值。

    +

    3. 解释机器学习中常用的一些相似性度量。

    +

    一些最常用的相似性度量如下:

    +
      +
    • 余弦相似性-通过考虑n维的两个向量,我们计算两者之间夹角的余弦。该相似性度量的范围从[-1,1]变化,其中值1表示两个向量高度相似,而-1表示两个向量彼此完全不同。
    • +
    • 欧几里得或曼哈顿距离-这两个值表示n维平面中两点之间的距离。两者之间的唯一区别在于两者的计算方式。
    • +
    • Jaccard相似性-它也被称为IoU或Intersection over union,它广泛用于对象检测领域,以评估预测边界框和地面真实边界框之间的重叠。
    • +
    +

    4. 当数据分布右偏和左偏时,均值、中位数和众数会发生什么变化?

    +

    标准正态分布特征:均值=中位数=众数

    +

    左偏态特征:众数>中位数>均值

    +

    右偏态特征:均值>中位数>众数

    +

    右偏分布

    +

    图片

    +

    左偏分布,

    +

    图片

    +

    5. 对于离群值,决策树和随机森林谁的鲁棒性更强。

    +

    决策树和随机森林对离群值都相对稳健。随机森林模型是多个决策树的集成,因此,随机森林模型的输出是多个决策树的聚合。因此,当我们对结果进行平均时,过拟合的可能性就会降低。因此,我们可以说随机森林模型对离群值更具鲁棒性。

    +

    6. L1正则化和L2正则化有什么区别?它们的意义是什么?

    +

    L1正则化:在L1正则化中,也被称为Lasso正则化,其中我们在损失函数中添加模型权重的绝对值之和。

    +

    在L1正则化中,那些根本不重要的特征的权重被惩罚为零,因此,反过来,我们通过使用L1正则化技术来获得特征选择。

    +

    L2正则化:在L2正则化中,也称为岭正则化,我们将权重的平方添加到损失函数中。在这两种正则化方法中,权重都是不利的,但它们帮助实现的目标之间存在细微的差异。

    +

    在L2正则化中,权重不会被惩罚为0,但对于不相关的特征,它们接近于零。它通常用于通过将权重缩小到零来防止过拟合,特别是当有许多特征并且数据有噪声时。

    +

    7. 什么是径向基函数?解释它的用途。

    +

    RBF(径向基函数)是一种用于机器学习的实值函数,其值仅取决于输入和称为中心的固定点。径向基函数的公式如下:

    +

    图片

    +

    机器学习系统经常将RBF函数用于各种函数,包括:

    +
      +
    • RBF网络可以用来逼近复杂函数。通过训练网络的权重以适应一组输入输出对,
    • +
    • RBF网络可以用于无监督学习来定位数据组。通过将RBF中心视为聚类中心,
    • +
    • RBF网络可以用于分类任务,通过训练网络的权重,根据输入与RBF节点的距离将输入分组。
    • +
    +

    它是SVM算法中通常使用的非常著名的内核之一,用于将低维数据映射到高维平面,因此,我们可以确定一个边界,该边界可以将这些平面的不同区域中的类以尽可能多的余量分开。

    +

    8. 解释用于处理数据不平衡的SMOTE方法。

    +

    SMOTE是用来处理数据集中数据不平衡问题的方法之一。在这种方法中,基于现有的少数类,我们通过使用线性插值合成新的数据点。使用这种方法的优点是模型不会在相同的数据上进行训练。但是使用这种方法的缺点是它向数据集添加了不需要的噪声,并且可能对模型的性能产生负面影响。

    +

    9. 准确率得分是否总是衡量分类模型性能的良好指标?

    +

    不,有时候我们在不平衡的数据集上训练模型时,准确度分数并不是衡量模型性能的好指标。在这种情况下,我们使用查准率和查全率来衡量分类模型的性能。此外,f1-score是另一个可用于衡量性能的指标,但最终,f1-score也是使用精确度和召回率计算的,因为f1-score只是精确度和召回率的调和平均值。

    +

    10. 什么是 KNN 插值填充?

    +

    我们通常通过数据的描述性统计测量(如平均值、众数或中位数)来估算空值,但KNN 插值是一种更复杂的填补空值的方法。在该方法中还使用距离参数,其也被称为k参数。这项工作在某种程度上类似于聚类算法。缺失值是参照缺失值的邻域点进行插补的。

    +

    11. 解释XGB模型的工作流程。

    +

    XGB模型是机器学习集成技术的一个例子,在这种方法中,权重通过将它们传递到决策树来以顺序的方式进行优化。在每一遍之后,权重变得越来越好,因为每棵树都试图优化权重,最终,我们获得了手头问题的最佳权重。像正则化梯度和小批量梯度下降这样的技术已经被用来实现这个算法,所以它以非常快速和优化的方式工作。

    +

    12. 将给定数据集拆分为训练和验证数据的目的是什么?

    +

    主要目的是保留一些模型尚未训练的剩余数据,以便我们可以在训练后评估机器学习模型的性能。此外,有时我们使用验证数据集在多个先进的机器学习模型中进行选择。就像我们首先训练一些模型一样,比如LogisticRegression,XGBoost或任何其他模型,而不是使用验证数据测试它们的性能,并选择验证和训练精度之间差异较小的模型。

    +

    13. 解释一些处理数据中缺失值的方法。

    +

    处理缺失值的一些方法如下:

    +
      +
    • 删除具有空值的行,可能会导致丢失一些重要信息。
    • +
    • 如果列包含的信息价值很低,则删除包含空值的列。可能会导致丢失一些重要信息。
    • +
    • 使用描述性统计测量(如平均值、众数和中位数)插补空值。
    • +
    • 使用KNN 插值等方法以更复杂的方式估算空值。
    • +
    +

    14. k-means和KNN算法有什么区别?

    +

    k-means算法是用于聚类目的的流行的无监督机器学习算法之一。但KNN是一种通常用于分类任务的模型,是一种有监督的机器学习算法。k-means算法通过在数据集中形成聚类来帮助我们标记数据。

    +

    15. 什么是LDA线性判别分析?

    +

    LDA是一种有监督的机器学习降维技术,因为它也使用目标变量进行降维。它通常用于分类问题。LDA主要致力于两个目标:

    +
      +
    • 最大化两个类的均值之间的距离。
    • +
    • 最大限度地减少每个类中的差异。
    • +
    +

    16. 如何在二维中可视化高维数据?

    +

    最常用和有效的方法之一是使用t-SNE算法。该算法采用了一些非线性的复合形方法对给定的数据进行降维。我们还可以使用PCA或LDA将n维数据转换为2维,以便我们可以绘制它以获得更好的分析视觉效果。但是PCA和t-SNE之间的区别在于前者试图保持数据集的方差,而t-SNE试图保持数据集中的局部相似性。

    +

    17. 维度灾难背后的原因是什么?

    +

    随着输入数据的维度增加,概括或学习数据中存在的模式所需的数据量也增加。对于模型,很难从有限数量的数据集中识别每个特征的模式,或者我们可以说,由于数据的高维性和用于训练模型的有限数量的示例,权重没有得到适当的优化。由于这一点,在输入数据的维数达到一定的阈值后,我们不得不面对维数灾难。

    +

    18. 度量MAE或MSE或RMSE, 哪个对离群值有更好的鲁棒性。

    +

    在上述三个指标中,与MSE或RMSE相比,MAE对离群值具有鲁棒性。这背后的主要原因是因为平方误差值。在离群值的情况下,误差值已经很高,然后我们将其平方,这导致误差值的爆炸超过预期,并为梯度产生误导性结果。

    +

    19. 为什么删除高度相关的特征被认为是一种良好的做法?

    +

    当两个特征高度相关时,它们可能向模型提供类似的信息,这可能导致过拟合。如果数据集中存在高度相关的特征,那么它们不必要地增加了特征空间的维数,有时会产生维数灾难的问题。如果特征空间的维数很高,那么模型训练可能需要比预期更多的时间,这将增加模型的复杂性和出错的机会。这在某种程度上也有助于我们实现数据压缩,因为这些功能已经被删除,而没有太多的数据丢失。

    +

    20. 推荐系统中基于内容的过滤算法和协同过滤算法有什么区别?

    +

    在一个基于内容的推荐系统中,内容和服务的相似性进行评估,然后通过使用这些相似性措施,从过去的数据,我们推荐产品给用户。但另一方面,在协同过滤中,我们根据相似用户的偏好推荐内容和服务。例如,如果一个用户过去已经使用了A和B服务,并且新用户已经使用了服务A,则将基于另一用户的偏好向他推荐服务A。

    + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + +
    + + + +
    + + + +
    +
    +
    +
    + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/site/JY_HU/3 ZJU-AI-ML/labs & hw review/index.html b/site/JY_HU/AI/labs & hw review/index.html similarity index 54% rename from site/JY_HU/3 ZJU-AI-ML/labs & hw review/index.html rename to site/JY_HU/AI/labs & hw review/index.html index fe02a478..2f0521c8 100644 --- a/site/JY_HU/3 ZJU-AI-ML/labs & hw review/index.html +++ b/site/JY_HU/AI/labs & hw review/index.html @@ -14,7 +14,7 @@ - + @@ -147,6 +147,50 @@ + + +
    @@ -234,6 +278,14 @@ + + + + + + + + @@ -243,7 +295,7 @@
  • - + Jy Hu CS @@ -256,6 +308,9 @@ + + + @@ -522,7 +577,7 @@ - 1 数字逻辑设计 + 大二下 @@ -532,7 +587,246 @@ + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + @@ -2490,7 +4500,7 @@

    课程Lab&hw

    - 2024-07-02 + 2024-07-03 @@ -2552,13 +4562,13 @@

    课程Lab&hw

    -
    + - + diff --git a/site/JY_HU/AI/notes for ZJU-AI-ML/index.html b/site/JY_HU/AI/notes for ZJU-AI-ML/index.html new file mode 100644 index 00000000..5b0b4219 --- /dev/null +++ b/site/JY_HU/AI/notes for ZJU-AI-ML/index.html @@ -0,0 +1,4983 @@ + + + + + + + + + + + + + + + + + + + + + + + + + 赶快补课抄笔记 - JY-HF learning site + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + + + + 跳转至 + + +
    +
    + +
    + + + + +
    + + +
    + +
    + + + + + + + + + +
    +
    + + + +
    +
    +
    + + + + + + + + + +
    +
    +
    + + + + +
    +
    + + + + + + + +

    notes for ZJU-AI-ML

    +

    machine learning bullet points

    +

    期末主要考后四章?

    +

    第8章

    +

    集成学习算法之Boosting - 知乎 (zhihu.com)

    +

    一文看懂决策树(Decision Tree) - 知乎 (zhihu.com)

    +

    【机器学习】Bootstrap详解 - 知乎 (zhihu.com)

    +

    KMeans(K均值)和KNN(K最近邻)是两种不同的机器学习算法,它们在任务和实现上有很大的区别。

    +

    KMeans(K均值):

    +
      +
    1. 任务:
    2. +
    3. KMeans 是一种聚类算法,用于将数据分成K个不同的组或簇,使得每个数据点属于最近的簇中心。
    4. +
    5. 目标是最小化每个簇内的点与簇中心的平方距离之和。
    6. +
    7. 工作原理:
    8. +
    9. 首先,选择K个初始簇中心。
    10. +
    11. 然后,将每个数据点分配到离它最近的簇中心。
    12. +
    13. 更新簇中心为分配给该簇的所有数据点的平均值。
    14. +
    15. 重复上述两个步骤,直到簇中心不再变化或变化很小。
    16. +
    17. 应用:
    18. +
    19. KMeans 可用于图像压缩、文档聚类、无监督特征学习等。
    20. +
    +

    KNN(K最近邻):

    +
      +
    1. 任务:
    2. +
    3. KNN 是一种分类和回归算法,用于根据最近邻居的标签对新数据进行分类或预测。
    4. +
    5. 工作原理:
    6. +
    7. 对于给定的数据点,找到与其最近的K个训练数据点。
    8. +
    9. 对于分类,采用多数投票的原则确定该点的类别。
    10. +
    11. 对于回归,采用K个邻居的平均值来预测该点的值。
    12. +
    13. 应用:
    14. +
    15. KNN 可用于模式识别、图像识别、推荐系统等。
    16. +
    +

    区别:

    +
      +
    1. 任务:
    2. +
    3. KMeans 用于聚类,将数据分成K个簇。
    4. +
    5. KNN 用于分类和回归,根据最近邻居的标签对数据进行分类或预测。
    6. +
    7. 目标函数:
    8. +
    9. KMeans 的目标是最小化簇内平方距离之和。
    10. +
    11. KNN 的目标是基于最近邻居进行分类或回归。
    12. +
    13. 监督/无监督:
    14. +
    15. KMeans 是无监督学习,不需要类别标签。
    16. +
    17. KNN 既可以是监督学习也可以是无监督学习,具体取决于它是用于分类还是回归任务。
    18. +
    19. 输出:
    20. +
    21. KMeans 输出是数据点所属的簇。
    22. +
    23. KNN 输出是分类标签(对于分类)或连续值(对于回归)。
    24. +
    +

    总体而言,KMeans 和 KNN 是两种不同类型的算法,用于解决不同的问题。 KMeans 是一种无监督学习算法,用于聚类,而 KNN 通常用于监督学习中的分类和回归任务

    +

    监督学习和无监督学习是机器学习中两种不同类型的学习范式,它们之间的主要区别在于训练数据的标签信息。

    +

    监督学习(Supervised Learning):

    +
      +
    1. 定义
    2. +
    3. 在监督学习中,算法接收带有标签(类别或输出)的训练数据。
    4. +
    5. 每个训练样本都包括输入特征和相应的标签。
    6. +
    7. 任务
    8. +
    9. 监督学习的目标是学习一个从输入到输出的映射,以便在给定新输入时能够预测相应的输出标签。
    10. +
    11. 典型任务包括分类和回归。
    12. +
    13. 示例
    14. +
    15. 分类:预测输入数据属于哪个类别(例如,垃圾邮件分类)。
    16. +
    17. 回归:预测输入数据的数值输出(例如,房价预测)。
    18. +
    19. 训练数据
    20. +
    21. 训练数据包括输入-输出对,每个输入都有一个对应的输出标签。
    22. +
    +

    无监督学习(Unsupervised Learning):

    +
      +
    1. 定义
    2. +
    3. 在无监督学习中,算法接收没有标签信息的训练数据。
    4. +
    5. 训练样本只包括输入特征,没有相应的输出标签。
    6. +
    7. 任务
    8. +
    9. 无监督学习的目标是探索数据的结构,发现数据中的模式和关系。
    10. +
    11. 典型任务包括聚类、降维和关联规则学习。
    12. +
    13. 示例
    14. +
    15. 聚类:将相似的数据点分组到同一类别中。
    16. +
    17. 降维:减少数据维度,保留关键特征。
    18. +
    19. 关联规则学习:发现数据中的关联性,例如购物篮分析。
    20. +
    21. 训练数据
    22. +
    23. 训练数据没有输出标签,算法试图从数据中学习隐藏的结构。
    24. +
    +

    区别总结:

    +
      +
    • 数据标签
    • +
    • 监督学习需要带有标签的训练数据。
    • +
    • 无监督学习使用没有标签的训练数据。
    • +
    • 目标
    • +
    • 监督学习目标是预测输出标签。
    • +
    • 无监督学习目标是发现数据中的模式和结构。
    • +
    • 任务
    • +
    • 监督学习任务包括分类和回归。
    • +
    • 无监督学习任务包括聚类、降维和关联规则学习。
    • +
    • 示例
    • +
    • 监督学习示例包括图像分类、语音识别。
    • +
    • 无监督学习示例包括社交网络分析、信用卡欺诈检测。
    • +
    +

    无监督学习通常用于在数据中发现隐藏的结构,而监督学习则用于构建输入和输出之间的映射关系。这两者在解决不同类型的问题时发挥着重要的作用。

    +

    LSTM

    +

    一步干四件事情:

    +

    输入新的输入信息和上一个状态的cell state和hidden state,输出hidden state和cell state

    +

    根据当前新的输入,选择从上个状态的cell state中要忘记的内容,

    +

    根据当前新的输入,选择从上个状态的cell state中要更新的内容

    +

    根据更新后的状态和当前新的输入,更新hidden state的内容

    +

    Softmax、ReLU(Rectified Linear Unit)、和Sigmoid是常用的激活函数,它们在深度学习中用于不同的场景。以下是它们的函数表达式和主要应用情形:

    +
      +
    1. Softmax函数:
    2. +
    3. 函数表达式:
    4. +
    5. 给定一个向量$ z = [z_1, z_2, ..., z_k]$,Softmax函数将每个元素转化为非负且和为1的概率值。 + $ \text{Softmax}(z)i = \frac{e^{z_i}}{\sum $}^{k} e^{z_j}
    6. +
    7. 应用情形: 主要用于多类别分类问题的输出层。Softmax将模型的原始输出转化为类别概率分布,便于模型在训练时计算损失并进行梯度下降。
    8. +
    9. ReLU函数:
    10. +
    11. 函数表达式:
    12. +
    13. ReLU激活函数将所有负输入设为零,保持正输入不变。 + ${ReLU}(x) = \max(0, x) $
    14. +
    15. 应用情形: 用于隐藏层的激活函数。ReLU的非线性特性使得模型能够学习更复杂的表示,同时避免了梯度消失问题。
    16. +
    17. Sigmoid函数:
    18. +
    19. 函数表达式:
    20. +
    21. Sigmoid函数将输入映射到一个取值范围在0到1之间的概率值。 + ${Sigmoid}(x) = \frac{1}{1 + e^{-x}} $
    22. +
    23. 应用情形: 主要用于二元分类问题的输出层。Sigmoid将模型的原始输出映射为0到1之间的概率,方便进行二元分类的阈值判定。
    24. +
    +

    这些激活函数的选择通常取决于任务的性质和网络的结构。一般而言,Softmax适用于多类别分类,ReLU适用于隐藏层以增加模型的非线性表达能力,而Sigmoid适用于二元分类。

    +

    week 9

    +

    word embedding 词嵌入

    +

    Convert words into numerical form (e.g., vector). +例如,Embed words into a mathematical space.

    +

    one-hot编码的优点和缺点:维度太高,无法表征相似(靠近)程度

    +

    distributional representation 分布式表示方法

    +

    distributional hypothesis指出,应该用这个词所处的语境来生成词向量

    +

    word2vec is used for distributional representation

    +

    inference based methods:在自然语言处理(NLP)中,skip-gram和CBOW(Continuous Bag of Words)是两种用于学习词向量表示的模型,它们被称为“inference based methods”(基于推理的方法)的原因主要与它们的训练目标和方法有关。

    +

    这两种模型都是基于推断(inference)的方法,因为它们的核心目标是通过观察词汇之间的上下文关系来推断每个词的词向量表示。具体而言:

    +
      +
    1. Skip-gram模型: 在skip-gram中,模型试图从给定的中心词预测其周围的上下文词。这就好像模型在推断中心词的上下文信息。因此,skip-gram是一种基于上下文推断的方法。
    2. +
    3. CBOW模型: 与skip-gram相反,CBOW试图从周围的上下文词预测中心词。CBOW将上下文中的词汇信息结合起来,试图推断中心词。因此,CBOW也是一种基于上下文推断的方法,只是它关注的是中心词。
    4. +
    +

    这两种方法之所以被称为“inference based methods”,是因为它们的核心任务是从给定的上下文信息中推断单词的表示。这与一些其他方法,如计数方法(count-based methods)不同,后者主要关注的是统计词汇的共现信息而不是直接推断词向量。

    +

    总的来说,skip-gram和CBOW模型被称为基于推理的方法,因为它们通过观察上下文关系来推断词汇的语义表示,从而实现更好的词向量学习。

    +

    Continuous bag-of-words model(CBOW model)

    +

    Predict one word (target word) from multiple words (context). +The convergence rate is fast. +The distributional representation (word vector) is relatively inferior.

    +

    Skip-gram model

    +

    Predict multiple words (context) from one word (target word). +The convergence rate is slow. +The distributional representation (word vector) is relatively superior.

    +

    CBOW(Continuous Bag of Words)和Skip-gram是自然语言处理(NLP)中用于生成词向量的两种流行模型。关于CBOW的词向量相对较差的说法可能受到一些因素的影响,但需要注意的是,这些模型的性能可能取决于具体的任务、数据集和训练参数。

    +

    以下是CBOW的词向量在某些情境下被认为相对较差的一些原因:

    +
      +
    1. 上下文过度简化: CBOW倾向于对窗口内的上下文词求平均,以预测目标词。这可能导致在处理多义词(具有多个含义的词)或捕捉含义微妙差异时,表征相对过于简化。
    2. +
    3. 丢失词序信息: CBOW忽略了上下文窗口内的词序,因为它将上下文词视为无序集合。这可能导致顺序信息的丢失,而这对某些任务可能至关重要。
    4. +
    5. 对频繁词汇的优势: CBOW在语料库中频繁出现的词汇上表现较好,因为在训练过程中它对它们进行了优先考虑。然而,对于稀有词汇或特定词汇关系的捕捉效果可能不够显著。
    6. +
    7. 上下文窗口大小: 在CBOW中,上下文窗口大小的选择会影响词向量的质量。窗口太小可能无法捕捉足够的上下文信息,而窗口太大可能引入噪声。
    8. +
    9. 任务特定性能: 对相对较差的看法可能是与具体任务有关的。对于某些NLP任务,Skip-gram或其他嵌入模型可能在性能上优于CBOW。
    10. +
    +

    值得注意的是,在CBOW和Skip-gram之间的选择通常取决于数据集的具体特性以及下游任务的需求。在实践中,研究人员和从业者可能会尝试使用这两种模型,以确定哪种模型更适合其特定的用例。此外,诸如基于Transformer的更近期的词向量模型等技术的进步在各种NLP应用中超越了传统方法,如CBOW和Skip-gram。

    +

    image-20240102195030931

    +

    "RNN能够Correlate temporal information" 表示循环神经网络(Recurrent Neural Network,RNN)能够关联或捕捉时间上的信息。在这种上下文中,"temporal information" 指的是与时间相关的数据、模式或序列。

    +

    RNN是一种具有循环结构的神经网络,它在处理序列数据时表现出色。这意味着它能够考虑先前的时间步信息,从而更好地理解和预测序列中的模式。RNN的循环结构允许信息在网络中传递,使得网络能够捕捉和利用时间上的依赖关系。

    +

    具体而言,RNN中的隐藏状态允许网络在处理序列时保留过去的信息,并在当前时间步使用。这种机制使得RNN能够关联不同时间步的输入,从而更好地理解序列中的动态模式。这样,RNN就能够在处理时间序列数据时有效地"correlate temporal information",也就是关联或捕捉时间上的信息。

    +

    然而,传统的RNN在处理长序列时可能会面临梯度消失或梯度爆炸的问题,为了解决这一问题,一些改进的结构,如长短时记忆网络(LSTM)和门控循环单元(GRU)等,被提出来以更有效地捕捉和利用时间信息。这些改进的结构在处理长期依赖性时表现更好。

    +

    Large models, especially those based on transformer architectures like OpenAI's GPT-3, have shown significant advancements in various natural language processing (NLP) and machine learning tasks. These models are known for their ability to capture complex patterns in data, generate coherent and contextually relevant outputs, and achieve state-of-the-art performance in multiple benchmarks.

    +

    Here are some considerations regarding the future of large models:

    +
      +
    1. +

      Increased Model Size: There is a trend of increasing model sizes to improve performance. Researchers continue to explore even larger models with more parameters to push the boundaries of what's possible in terms of understanding and generating natural language.

      +
    2. +
    3. +

      Broader Applicability: Large models are being adapted and fine-tuned for a broader range of tasks beyond NLP, including computer vision, reinforcement learning, and more. This trend may continue as researchers aim to develop models with general intelligence.

      +
    4. +
    5. +

      Resource Intensiveness: Training and deploying large models require substantial computational resources, which may limit accessibility. Future developments might focus on making these models more efficient and accessible, allowing a wider range of researchers and applications to benefit from them.

      +
    6. +
    7. +

      Ethical Considerations: As large models become more powerful, there's a growing need to address ethical concerns, including issues related to biases in training data, potential misuse, and the environmental impact of training such models.

      +
    8. +
    9. +

      Hybrid Models: Future research might explore hybrid models that combine the strengths of large pre-trained models with more task-specific architectures. This approach could enhance efficiency and performance for specific applications.

      +
    10. +
    +

    agents

    +
      +
    1. Explainability: There is a growing demand for models that not only perform well but also provide interpretable and explainable results. Future developments may involve designing large models that are more transparent and easier to interpret.
    2. +
    +

    It's important to note that the field of machine learning is dynamic, and new developments may occur beyond my last update. The future of large models will likely depend on ongoing research, technological advancements, and societal considerations.

    +

    贝叶斯分类器:

    +

    训练样本为 特征 对应 分类

    +

    需要预测的是:某特征x下对应的分类y,求出最大可能性的y,argmax p(y|x)

    +

    训练方法是:

    + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + +
    + + + +
    + + + +
    +
    +
    +
    + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git "a/site/JY_HU/4 \345\233\276\345\203\217\344\277\241\346\201\257\345\244\204\347\220\206 DIP/DIP/index.html" b/site/JY_HU/AI/srtp-2024-plan/index.html similarity index 53% rename from "site/JY_HU/4 \345\233\276\345\203\217\344\277\241\346\201\257\345\244\204\347\220\206 DIP/DIP/index.html" rename to site/JY_HU/AI/srtp-2024-plan/index.html index 05c41c21..d090759c 100644 --- "a/site/JY_HU/4 \345\233\276\345\203\217\344\277\241\346\201\257\345\244\204\347\220\206 DIP/DIP/index.html" +++ b/site/JY_HU/AI/srtp-2024-plan/index.html @@ -11,10 +11,10 @@ - + - + @@ -22,7 +22,7 @@ - 4 图像信息处理 DIP - JY-HF learning site + srtp - JY-HF learning site @@ -80,7 +80,7 @@
    - + 跳转至 @@ -114,7 +114,7 @@
    - 4 图像信息处理 DIP + srtp
    @@ -152,6 +152,50 @@ + + +
    @@ -239,6 +283,14 @@ + + + + + + + + @@ -248,7 +300,7 @@
  • - + Jy Hu CS @@ -261,6 +313,9 @@ + + + @@ -527,7 +582,7 @@ - 1 数字逻辑设计 + 大二下 @@ -537,7 +592,7 @@
  • - + + + + + + + + + + + + + + + + +
  • + + + + + + + + + + +
  • + + + + + + + + + + + + + + + + + + + +
  • + + + + + + + + +
  • @@ -2545,43 +4482,10 @@ -

    DIP

    -

    DPI是

    -

    课程大纲

    -

    目录课程学习内容任课教师课程教材推荐书单分数构成

    -

    图像信息处理

    -

    CS 专业选修

    -

    课程学习内容

    -

    教授内容以图像基本概念、基本操作为基础,围绕图像合成与编辑核心,并介绍了当前数字图像处理的现状、发展和一些关键技术。 主要知识点为:

    -
      -
    • 图像获取
    • -
    • 图像显示和打印
    • -
    • 图像存储和传输
    • -
    • 图像增强和恢复
    • -
    • 图像识别和理解
    • -
    -

    任课教师

    -

    本门课程只由宋明黎一位老师开设。

    -

    授课方式:双语(绝大部分 PPT 为英文,老师授课使用汉语)。

    -

    授课水平:口齿清晰,逻辑清晰,智云 1.5 倍速刚好。

    -

    给分情况:一般。不建议抱太高期望,但认真学的话得分应该不会太低。

    -

    其他:黎叔是一名火影厨。

    -

    课程教材

    -

    -

    推荐书单

    -
      -
    • Digital Image Processing Using MATLAB, Gonzalez
    • -
    • 《数字图像处理编程入门》,吕凤军
    • -
    -

    分数构成

    -

    卷面(60%)+ 作业(40%)

    -

    一学期大概会有 5~7 次作业,要使用 C/C++ 编程,不可调用 OpenCV 等图形处理库。

    -

    矢量图格式

    -

    BITMAPFILEHEADER

    -

    BITMAPINFOHEDER

    -

    morphing 变形、映射

    -

    bilateral filter 双边滤波

    -

    guided filter

    +

    srtp 2023 plan

    +

    google colab

    +

    使用模型,想一个应用场景

    +

    视频剪辑

    @@ -2604,7 +4508,7 @@

    分数构成 - 2024-07-02 + 2024-07-03 @@ -2614,7 +4518,7 @@

    分数构成 - 2023-11-18 + 2024-07-03 @@ -2649,7 +4553,7 @@

    分数构成 - +

    - + - + @@ -3011,7 +5023,7 @@
    Method 2
    - 2024-07-02 + 2024-07-03 @@ -3056,7 +5068,7 @@
    Method 2