TAILIEUCHUNG - Data Structures and Program Design in C++ phần 5

rằng loại chèn sẽ làm là hơn . Một vấn đề đòi hỏi một phút thời gian máy tính sử dụng sắp xếp chèn có thể sẽ yêu cầu chỉ một Mergesort sử dụng hoặc hai thứ hai. Sự xuất hiện của biểu n lg n trong tính toán trước đó không có nghĩa là tình cờ, nhưng liên quan chặt chẽ với các giới hạn thấp hơn được thành lập trong 8,5 mục, | 276 Chapter 7 Searching int list_size if searches 0 list_size 0 cout Exiting test endl The number of searches must be positive. endl The number of list entries must exceed 0. endl return int i target found_at Key comparisons 0 Random number Timer clock for i 0 i searches i target 2 0 list_size - 1 1 if sequential_search the_list target found_at not_present cout Error Failed to find expected target target endl print_out Successful Key comparisons searches Key comparisons 0 for i 0 i searches i target 2 0 list_size if sequential_search the_list target found_at success cout Error Found unexpected target target at found_at endl print_out Unsuccessful Key comparisons searches The details of embedding this function into a working program and writing the output function print_out are left as a project. Exercises E1. One good check for any algorithm is to see what it does in extreme cases. Determine what sequential search does when a there is only one item in the list. b the list is empty. c the list is full. E2. Trace sequential search as it searches for each of the keys present in a list containing three items. Determine how many comparisons are made and thereby check the formula for the average number of comparisons for a successful search. Section Sequential Search 277 sentinel Programming Projects Wit E3. If we can assume that the keys in the list have been arranged in order for example numerical or alphabetical order then we can terminate unsuccessful searches more quickly. If the smallest keys come first then we can terminate the search as soon as a key greater than or equal to the target key has been found. If we assume that it is equally likely that a target key not in the list is in any one of the n 1 intervals before the first key between a pair of successive keys or after the last key then what is the average number of comparisons for .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.