Danh mục

Bài giảng Cấu trúc dữ liệu và giải thuật: Thực hiện thuật toán Euclid bằng đệ qui - TS. Đào Nam Anh

Số trang: 21      Loại file: pdf      Dung lượng: 424.49 KB      Lượt xem: 2      Lượt tải: 0    
Xem trước 3 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Bài giảng "Cấu trúc dữ liệu và giải thuật: Thực hiện thuật toán Euclid bằng đệ qui" trình bày các kiến thức về các bước thực hiện thuật toán Euclid bằng đệ qui. Mời các bạn cùng tham khảo nội dung chi tiết.
Nội dung trích xuất từ tài liệu:
Bài giảng Cấu trúc dữ liệu và giải thuật: Thực hiện thuật toán Euclid bằng đệ qui - TS. Đào Nam AnhDATA STRUCTURE AND ALGORITHMRecursive Euclid AlgorithmCẤU TRÚC DỮ LIỆU VÀ GIẢI THUẬTThực hiệu thuật toán Euclid bằng đệ quiDr. Dao Nam AnhData Structure and Algorithm1Resource - ReferenceSlides adapted from Robert Sedgewick,and Kevin Wayne.Major Reference:•Robert Sedgewick, and Kevin Wayne, “Algorithms”Princeton University, 2011, Addison Wesley•Algorithm in C (Parts 1-5 Bundle)- Third Edition byRobert Sedgewick, Addison-WesleyData Structure and Algorithm2Recursive Euclid AlgorithmTìm ước số chung lớn nhất của hai số nguyênpublic class Euclid {public static int gcd(int p, int q) {if (q == 0) return p;else return gcd(q, p % q);}public static void main(String[] args) {int p = Integer.parseInt(args[0]);int q = Integer.parseInt(args[1]);System.out.println(gcd(p, q));}}Data Structure and Algorithm3p = 1272, q = 216environmentgcd(1272, 216)static int gcd(int p, int q) {if (q == 0) return p;else return gcd(q, p % q);}Data Structure and Algorithm4p = 1272, q = 216environmentgcd(1272, 216)static int gcd(int p, int q) {if (q == 0) return p;else return gcd(q, p % q);}Data Structure and Algorithm5

Tài liệu được xem nhiều: