đây là 1 trong những cấu trúc và giải thuật của môn cấu trúc dữ liệu trong java có nghĩa là phần đệ quy.Nó thực hiện các bài toán như tính giai thừa,....có một số giải thuật như chuyển từ số thập phân sang số nhị phân hay ngược lại.chúc các bạn học tốt
Trang 1ĐỆ QUY
Trang 2 Là cách một hàm tự gọi lại chính bản thân của nó
Trang 3BÀI TOÁN “G IAI THỪA ”
Trang 4BÀI TOÁN “G IAI THỪA ”
Trang 5BÀI TOÁN “D RAWING AN E NGLISH R ULER ”
Trang 6BÀI TOÁN “D RAWING AN E NGLISH R ULER ”
Trang 7GIẢI THUẬT TÌM KIẾM NHỊ PHÂN
The algorithm maintains two parameters, low and high, such that all the
candidate elements have index at least low and at most high Initially, low
=0 and high=n−1 We then compare the target value to the median
candidate, that is, the element with index
mid=⌊(low+high)/2⌋
We consider three cases:
If the target equals the median candidate, then we have found the item
we are looking for, and the search terminates successfully
If the target is less than the median candidate, then we recur on the
first half of the sequence, that is, on the interval of indices from low to mid−1
If the target is greater than the median candidate, then we recur on the
second half of the sequence, that is, on the interval of indices frommid+1 to high An unsuccessful search occurs if low >high, as the interval [low, high]is empty
Trang 8GIẢI THUẬT TÌM KIẾM NHỊ PHÂN
Trang 9 Phát biểu
Chia số thập phân cho 2 cho đến khi thương bằng 0
Đọc phần dư theo chiều ngược lại
LinkedList<Integer> result = new LinkedList<>();
public String decToBi(int num){
if((num/2) != 0){
result.addFirst(num%2);
decToBi(num/2);
}else{
result.addFirst(num%2);
}
return this.listToString(result);
}
Thử một số cách chuyển đổi khác???
S Ư ̉ D Ụ NG ĐÊ ̣ QUY GIẢI QUYẾT BÀI TOÁN