TAILIEUCHUNG - Feaculty of Computer Science and Engineering Department of Computer Scienc Tutorial 3 Questions

For each of the AVL trees obtained in Question 1 determine the tree obtained when the root is withdrawn. Question 3. Write a global function in pseudo code to generate an AVL tree from an input list by insert elements in the list into an initial empty AVL. Refer to Question 1 for an example. algorithm generateAVLfromList (val list ) This algorithm generate a AVL from the input list Pre Post the AVL is built by inserting elements in the list into an initial empty tree one-by-one from the beginning. | Faculty of Computer Science and Engineering Department of Computer Science DATA STRUCTURES ALGORITHMS Tutorial 3 Questions Recursion and Binary Tree Part 1. Recursion Required Questions Question 1. What would be the contents of queue Q1 after the following code is executed and the following data are entered 1 Q1 createQueue 2 S1 createStack 3 loop not end of file 1 read number 2 if number not 0 1 pushStack S1 number 3 else 1 popStack S1 x Q1 5 4 6 8 67 32 9 5 2 popStack S1 x 3 loop not empty S1 S1 10 6 20 23 54 1 popStack S1 x 5 2 enqueue Q1 x 4 end loop 4 end if 4 end loop The data are 9 5 10 4 0 5 4 6 8 67 32 25 51 0 54 23 20 6 10 Question 2. The following algorithm is to reverse a queue Algorithm reverse val q Queue Pre true Return a reversed queue of q 1 S createStack 2 Q createQueue 3 while not empty q 1 dequeue q temp 2 pushStack S temp 4 while not empty S 1 popStack S temp 2 enqueu Q temp 4 return Q End reverse Develop a similar algorithm to append a stack to a queue Algorithm append val q Queue val s Stack Pre true Return a reversed queue of q 1 S createStack 2 Q creatQueue 3 while not empty S 1 popStack S temp 2 enqueue q temp 4 reverse Q 5 while not empty q 1 dequeue q temp 2 enqueue Q temp 6 return Q Algorithm append val q Queue val s Stack End append Pre true 1 4 Faculty of Computer Science and Engineering Department of Computer Science Return element of s is appended into q with the same order. For example if q 1 2 3 s 4 5 6 then q 1 2 3 4 5 6 after append. Queue front . rear Stack bottom . top 6 5 4 Question 3. 4 5 6 Consider the following algorithm Algorithm fun1 x integer 1 if x 5 1 return 2 x 2 else 1 return 2 fun1 x - 2 5 3 end if end fun1 What would be returned if fun1 is called as a. fun1 4 8 b. fun1 5 17 c. fun1 8 47 d. fun1 20 2 2 2 anh 3233 Question 4. Develop recursive algorithm for the following problems. Algorithm compute x integer 1 if x 0 1 return 0 a. Compute the sum of all numbers from 1 to n where n is given as parameter. v Algorithm

TỪ KHÓA LIÊN QUAN
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.