... thực phép so sánh ý tưởng giảm bớt phép so sánh cách thêm vào mảng phần tử cầm canh (sentinel/stand by) có giá trị X để nhận diện hết mảng duyệt B1: i = B2: A[i+1] = X B3: Nếu A[i] ≠ X Thì i++...
... kiếm O(lg n) Vậy độ phức tạp trung bình thuật toán tìm kiếm nhị phân tìm kiếm O(lg n) Minimum and Maximum 39 Từ node gốc luôn tìm node có giá trị khóa nhỏ (minimum) theo trỏ trái gặp Null ... tìm node có giá trị khóa lớn (maximum) theo trỏ phải gặp Null Minimum key Maximum key 20 Minimum and Maximum 40 Độ phức tạp giải thuật O(h) Successor 41 Nếu tất khóa BST khác nhau, successor...
... cờ pos } else begin best := -INFINITY; Gen; { Sinh nước từ vị trí pos } while (còn lấy nước m) and (best < beta) begin if best > Alpha then Alpha := best; Thực nước m; value := -AlphaBeta(-beta,...
... cờ pos } else begin best := -INFINITY; Gen; { Sinh nước từ vị trí pos } while (còn lấy nước m) and (best < beta) begin if best > Alpha then Alpha := best; Thực nước m; value := -AlphaBeta(-beta,...
... TaoMang(int a[], int N); void XuatMang(int a[], int N); int LinearSearch(int a[], int N); void main() { srand((usigned int) time (NULL)); int a[MAX], N = 20, x, kq; TaoMang(a, N); XuatMang(a, N); cout
... thuật toán O(max(M, n)), kết phép đếm nhược điểm thuật toán M lớn khó thực Thuật toán xếp số (exchange radix sort) Ý tưởng thuật toán tương tự quick sort trường hợp đặc biệt mảng cần xếp số nguyên,...
... k=k+1 HeapIndex(v)=k InsertHeap(Q,v) COLOR(v)=GRAY PRE(v)=u dv=d(u)+w(u,v) } if (COLOR(v)=GRAY) and d(v)>d(u)+w(u,v) then{ d(v)=d(u)+w(u,v) PRE(v)=u UpHeap(Q,HeapIndex(v)) } } } Mot doan ma lam...
... candidateList ← null for (sCandidate in sNeighborhood) if tabuList)) (not containsTabuElements(sCandidate, candidateList ← candidateList + sCandidate end end sCandidate ... candidate ← Ø candidateTo talP oi nt ← scheduleTo talP oi nt choice ← r andomChoice() choice is Weekday true candidateUni tBefore ← lessonWee kd ay candidate Uni tAfter ← r andomWeekday() ... false candidateUni tBefore ← l essonHo ur candidate Uni tAfter ← r andomHour() false choice is R oom true false candidate Uni tBefore ← l essonRoo m candidate Uni tAfter ← r andomRoom()...
... AVL Trong trường hợp xấu thời gian thực phép toán BST O(n) Cân AVL – – Do Adelson Velski Landis AVL: Cây TKNP mà chiều cao hai nút chênh lệch nhiều Trên AVL phép tìm kiếm, thêm, xoa nút ... x){ BST-TREE-INSERT(T, x) color[x] ← RED //only RB property can be violated while (x ≠ root[T] and color[p[x]] = RED) { if p[x] = left[p[p[x]] then { y ← right[p[p[x]] // y = aunt/uncle of x ... = right[p[x]] then { Case_2 // Case falls into Case Case_3 } } else 〈“then” clause with “left” and “right” swapped〉 } color[root[T]] ← BLACK Case Là đỏ đen hợp lệ (Gốc đen, nhánh có số nút đen)...