Cho các bạn nào đang học môn CTLD>1. Đây là một số giải thuật sắp xếp tôi cài đặt thử và có tính thời gian chạy cho từng trường hợp. Cho các bạn nào chưa cài đặt được tất cả thuật toán có thể có một cái nhìn hình tượng hơn về sự chênh lệch trong độ phức tạp dẫn tới khác biệt thế nào trong thời gian thực thi. Với một mảng 200.000.000 số nguyên chương trình sẽ cho output dạng như thế này:
Cách cài đặt các thuật toán này vẫn chưa phải là trau chuốt, một số thuật toán vẫn chưa được cài đặt (natural merge sort, shaker sort, v.v..) và không loại trừ một số thuật toán cài đặt bị bug. Hoan nghênh bạn nào có thể tiếp tục trau chuốt, tìm lỗi và bổ sung chương trình cho mọi người tham khảo. Các thắc mắc (nếu có) về chương trinfhay về kiến thức môn CTDL> 1 nói chung có thể đặt tại đây.
Chương trình code bằng ANSI-C và đã test với GNU C compiler 4.7: $ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: /build/src/gcc-4.7-20120324/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared --enable-threads=posix --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --enable-libstdcxx-time --enable-gnu-unique-object --enable-linker-build-id --with-ppl --enable-cloog-backend=isl --enable-lto --enable-gold --enable-ld=default --enable-plugin --with-plugin-ld=ld.gold --with-linker-hash-style=gnu --disable-multilib --disable-libssp --disable-build-with-cxx --disable-build-poststage1-with-cxx --enable-checking=release
Thread model: posix
gcc version 4.7.0 20120324 (prerelease) (GCC)
Code:
Quick sort took 232262606 swap 57782172 comparision sorted, quick sort took 5.27 seconds Heap sort took 470497389 swap 912176610 comparision sorted, heap sort took 12.94 seconds Merge sort took 166666666 swap 520000000 comparision sorted, merge sort took 5.78 seconds Process returned 0 (0x0) execution time : 26.980 s Press ENTER to continue.
Chương trình code bằng ANSI-C và đã test với GNU C compiler 4.7: $ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: /build/src/gcc-4.7-20120324/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared --enable-threads=posix --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --enable-libstdcxx-time --enable-gnu-unique-object --enable-linker-build-id --with-ppl --enable-cloog-backend=isl --enable-lto --enable-gold --enable-ld=default --enable-plugin --with-plugin-ld=ld.gold --with-linker-hash-style=gnu --disable-multilib --disable-libssp --disable-build-with-cxx --disable-build-poststage1-with-cxx --enable-checking=release
Thread model: posix
gcc version 4.7.0 20120324 (prerelease) (GCC)
Comment