1. Trang chủ
  2. » Luận Văn - Báo Cáo

Lecture 14_Data_Structure_Review.pptx

14 6 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Data Structures Review Basic concept ➢What are key properties of a good algorithm? ➢What are key properties of good data structure? 2 Linked list Given a singly linked list Head containing n integer n[.]

Data Structures Review Basic concept ➢What are key properties of a good algorithm? ➢What are key properties of good data structure? Linked list Given a singly linked list Head containing n integer numbers, your task is to write function sum(head) to calculate the sum of all odd numbers of the list Head Complexity Create a matrix of size n (1) for (i = ; i < n ; i++) (2) for (j = ; j < n ; j++) (3) if (i == j) (4) A[i][j] = 1; (5) else (6) A[i][j] = 0; Complexity: Complexity 1) sum = 0; 2) for ( i = 0; i < n; i + +) 3) for ( j = i + 1; j < = n; j + +) 4) for ( k = 1; k < 10; k + +) 5) sum = sum + i * j * k ; Complexity: Complexity 1) sum = 0; 2) for ( i = 0; i < n; i + +) 3) for ( j = i + 1; j < = n; j + +) 4) for ( k = 1; k < m; k + +) { 5) x = 2*y; 6) sum = sum + i * j * k } Complexity: Complexity 1) for (i = 0; i < n; i ++) 2) for (j = 0; j < m; j ++) { 3) int x = 0; 4) for (k = 0; k < n; k ++) 5) x = x + k; 6) for (k = 0; k < m; k++) 7) x = x +k; } Hash table Given a list of students (id, name): (7,An), (3,Be), (9, Cu), (4, Da), (18, Gi), (14, En), (6, Ba), (25, Go) Your task is to draw the hash table with the hash function f(x) = x mod 11 using both collision handling methods Heap tree Do following tasks with a heap tree: ➢ Construct a max heap tree including: 3, 19, 38, 9, 12, 64, 22, 3, 16, 28, 73 ➢ Insert the following numbers into the above max heap tree: 8, 13 Binary search tree Do the following tasks with a binary search tree: ➢ Create a binary search tree from following numbers: 24, 15, 35, 22, 19, 42, 10, 80, 29 ➢ Draw BSTs after deleting keys 15 and 29 from the above tree 10 Tree traversal Show the order of nodes in the preorder traversal a b f e d g c h i j 11 Tree traversal Show the order of nodes in post-order traversal a b f e d g c h i j 12 Balanced heap tree Draw balanced heap trees for following lists of numbers ❖ 20 15 21 35 67 ❖ 12 20 11 56 21 19 13 Balanced binary search tree Draw balanced binary search trees for following lists of numbers ❖ 20 15 21 35 67 ❖ 12 20 11 56 21 19 14

Ngày đăng: 27/10/2023, 11:01

Xem thêm:

TÀI LIỆU CÙNG NGƯỜI DÙNG

  • Đang cập nhật ...

TÀI LIỆU LIÊN QUAN