intTypePromotion=1
zunia.vn Tuyển sinh 2024 dành cho Gen-Z zunia.vn zunia.vn
ADSENSE

Lecture Data Structures: Lesson 33

Chia sẻ: Hàn Thiên Ngạo | Ngày: | Loại File: PPT | Số trang:14

15
lượt xem
1
download
 
  Download Vui lòng tải xuống để xem tài liệu đầy đủ

Lecture Data Structures: Lesson 33 provide students with knowledge about priority queue using heap; the selection problem; a faster way is to put the N elements into an array and apply the buildHeap algorithm on this array; disjoint set ADT;...

Chủ đề:
Lưu

Nội dung Text: Lecture Data Structures: Lesson 33

  1. Priority Queue Using Heap #include “Event.cpp” #include “Heap.cpp” #define PQMAX 30 class PriorityQueue { public: PriorityQueue() { heap = new Heap( PQMAX ); }; ~PriorityQueue() { delete heap; };    
  2. Lecture No.33 Data Structure Dr. Sohail Aslam    
  3. Priority Queue Using Heap Event* remove() { if( !heap->isEmpty() ) { Event* e; heap->deleteMin( e ); return e; } return (Event*)NULL; cout
  4. Priority Queue Using Heap int insert(Event* e) { if( !heap->isFull() ) { heap->insert( e ); return 1; } cout getSize(); }; };    
  5. The Selection Problem  Given a list of N elements (numbers, names etc.), which can be totally ordered, and an integer k, find the kth smallest (or largest) element.  One way is to put these N elements in an array an sort it. The kth smallest of these is at the kth position.    
  6. The Selection Problem  A faster way is to put the N elements into an array and apply the buildHeap algorithm on this array.  Finally, we perform k deleteMin operations. The last element extracted from the heap is our answer.  The interesting case is k = N/2, since this is known as the median.    
  7. HeapSort  If k = N, and we record the deleteMin elements as they come off the heap, we will have essentially sorted the N elements.  Later in the course, we will refine this idea to obtain a fast sorting algorithm called heapsort.    
  8. Disjoint Set ADT  Suppose we have a database of people.  We want to figure out who is related to whom.  Initially, we only have a list of people, and information about relations is gained by updates of the form “Haaris is related to Saad”.    
  9. Disjoint Set ADT  Key property: If Haaris is related to Saad and Saad is related to Ahmad, then Haaris is related to Ahmad.  Once we have relationships information, we would like to answer queries like “Is Haaris related to Ahmad?”    
  10. Disjoint Set ADT Blob Coloring  A well-known low-level computer vision problem for black and white images is the following: Gather together all the picture elements (pixels) that belong to the same "blobs", and give each pixel in each different blob an identical label.    
  11. Disjoint Set ADT Blob Coloring  Thus in the following image, there are five blobs.  We want to partition the pixels into disjoint sets, one set per blob.    
  12. Disjoint Set ADT The image segmentation problem.    
  13. Equivalence Relations  A binary relation  over a set S is called an equivalence relation if it has following properties 1. Reflexivity: for all element xS, x  x 2. Symmetry: for all elements x and y, x  y if and only if y  x 3. Transitivity: for all elements x, y and z, if x  y and y  z then x  z  The relation “is related to” is an equivalence relation over the set of people    
  14. Equivalence Relations  The  relationship is not an equivalence relation.  It is reflexive, since x  x,  and transitive, since x  y and y  z implies x  z,  it is not symmetric since x  y does not imply y  x.    
ADSENSE

CÓ THỂ BẠN MUỐN DOWNLOAD

 

Đồng bộ tài khoản
2=>2