【离散数学及其应用】The Fundamentals:Algorithms, the Integers, and Matrices

 

1. An algorithm is a finite set of precise instructions for performing a computation or for solving a problem.

Algorithm that make what seems to be the "best" choice at each step are called greedy algorithms.

 

 

 

2. Let f and g be functions from the set of integers or the set of real numbers to the set of real numbers, we say that f(x) is O(g(x)) if there are constants c and k such that |f(x)| <= c|g(x)| whenever x > k.

The constants c and k in the definition of big-O notation are called witnesses to the relationship f(x) is O(g(x)).

 

 

3. 1, logn, n, nlogn, n^2, 2^n, n!

 

 

4. Finding a prime

If n is a composite integer, then n has a prime divisor less than or equal to √n.

 

 

5. THE FUNDAMENTAL THEOREM OF ARITHMETIC

Every positive integer greater than 1 can be written uniquely as a prime or as the product of two or more primes. where the prime factors are wirtten int order of nondecreasing size.

e.g.

100 = 2 * 2 * 5 * 5

641 = 641

999 = 3 * 3 * 3 * 37

1024 = 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2

With nondecreasing size, we can find next prime factor by increasing the last exist prime.

 

 

6. How many primes are less than a positive number x?

THE PRIME NUMBER THEOREM

The ratio of the number of primes not exceeding x and x/lnx approaches 1 as x grows without bound.

The Prime Number Theorem tells us that the number of primes not exceeding x can be approxinated by x/lnx.

 

 

7. ALGORITHM 1: Construction Base b Expansions

Procedure base b expansion(n: positive integer)

q := n

k := 0

while q != 0

begin

ak := q mod b

q := floor(q / b)

k := k + 1

end { the base b expansion of n is (ak-1...a1a0)b }

 

 

8. ALGORITHM 2: Addition of Integers

Procedure add (a, b: positive integers)

{the binary expansions of a and b are (an-1an-2...a1a0)2 and (bn-1bn-2...b1b0)2, respectively}

c := 0

for j := 0 to n - 1

begin

d := floor((aj + bj + c) / 2)

sj := aj + bj + c - 2d

c := d

end

sn := c

{ the binary expansion of the sum is (snsn-1...s0)2 }

e.g.

a0 + b0 = c0 * 2 + s0

a1 + b1 + c0 = c1 * 2 + s1

...

an-1 + bn-1 + cn-2 = cn-1 * 2 + sn-1

sn = cn-1

 

 

9. ALGORITHM 3: Multiplying Integers

Procedure multiply (a, b: positive integers)

{ the binary expansions of a and b are an-1an-2...a1a0)2 and (bn-1bn-2...b1b0)2, respectively}

for j := 0 to n - 1

begin

if bj = 1 then cj := a shifted j places

else cj := 0

end

{ c0, c1, ..., cn-1 are the partial products }

p := 0

for j := 0 to n - 1

p := p + cj

{ p is the value of ab }

e.g.

ab = a(b02^0 + b12^1 + ... + bn-12^n-1)

     = a(b02^0) + a(b2^1) + ... + a(bn-12^n-1)

 

 

10. ALGORITHM 4: Computing div and mod procedure division algorithm

(a: integer, d: positive integer)

q := 0

r := |a|

while r >= d

begin

r := r - d

q := q + 1

end

if a < 0 and r > 0 then

begin

r := d - r

q := -(q+1)

end

{ q = a divd is the quotient, r = a and d is the remainder }

 

 

11. ALGORITHM 5: Modular Exponentiation

(find b^n mod m)

Procedure modular exponentiation

(b : integer, n = (ak-1ak-2...a1a0)2, m : positive intergers)

x := 1

power := b mod m

for i := 0 to k - 1

begin

if ai = 1 then x := (x * power) mod m

power := (power * power) mod m

end

{ x equals b^n mod m }

it uses O((logm)^2logn) bit operations.

 

 

12. Let a = bq + r. where a, b, q, and r are integers. The gcd(a, b) = gcd(b, r)

ALGORITHM 6: The Euclidean Algorithm procedure gcd(a, b : positive integers)

x := a

y := b

while y != 0

begin

r := x mod y

x := y

y := r

end { gcd(a, b) is x }

O(logb)

 

 

13. linear combination

gcd(a, b) can be form sa + tb, where s and t are integers.

"JavaScript engine fundamentals: Shapes and Inline Caches" 是指JavaScript引擎的基本概念:Shapes(形状)和Inline Caches(内联缓存)。 1. Shapes(形状):在JavaScript引擎中,每个对象都有一个形状,用于描述对象的结构和属性。形状包含对象的属性名称、偏移量和其他相关信息。当创建一个新对象时,引擎会根据对象的属性来确定其形状,并将该形状与对象关联起来。这样,在后续对同一形状的对象进行操作时,引擎可以更高效地执行。 形状对于优化JavaScript代码的执行非常重要。引擎可以根据对象的形状来进行内存布局和属性访问的优化,提高代码的执行效率。如果对象的形状发生变化(例如添加或删除属性),引擎会为该对象创建一个新的形状,并相应地调整相关操作。 2. Inline Caches(内联缓存):内联缓存是一种用于加速函数调用和属性访问的技术。当使用JavaScript代码调用函数或访问对象属性时,引擎会在编译阶段生成内联缓存,将函数调用或属性访问与特定的对象关联起来。 内联缓存可以避免每次函数调用或属性访问时都进行动态查找和解析。引擎会根据对象的形状和属性的特征,将函数调用或属性访问的地址直接嵌入到代码中。这样,在后续对同一对象进行函数调用或属性访问时,引擎可以直接使用内联缓存中的地址,避免了额外的查找和解析开销。 通过使用Shapes和Inline Caches,JavaScript引擎可以提高代码的执行效率和性能,加快函数调用和属性访问的速度。这些基本概念是JavaScript引擎优化和执行的关键部分。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值