MA/CSSE 473 Day 25 Transform and Conquer Student questions?

Slides:



Advertisements
Similar presentations
COL 106 Shweta Agrawal and Amit Kumar
Advertisements

Chapter 4: Trees Part II - AVL Tree
Transform and Conquer Chapter 6. Transform and Conquer Solve problem by transforming into: a more convenient instance of the same problem (instance simplification)
Transform & Conquer Replacing One Problem With Another Saadiq Moolla.
Chapter 6: Transform and Conquer
Design and Analysis of Algorithms - Chapter 61 Transform and Conquer Solve problem by transforming into: b a more convenient instance of the same problem.
Advanced Data Structures Chapter 16. Priority Queues Collection of elements each of which has a priority. Does not maintain a first-in, first-out discipline.
AA Trees another alternative to AVL trees. Balanced Binary Search Trees A Binary Search Tree (BST) of N nodes is balanced if height is in O(log N) A balanced.
Design and Analysis of Algorithms – Chapter 61 Transform and Conquer Dr. Ying Lu RAIK 283: Data Structures & Algorithms.
1 Chapter 6 Priority Queues (Heaps) General ideas of priority queues (Insert & DeleteMin) Efficient implementation of priority queue Uses of priority queues.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu.
CS 253: Algorithms Chapter 6 Heapsort Appendix B.5 Credit: Dr. George Bebis.
Analysis of Algorithms CS 477/677
TCSS 343, version 1.1 Algorithms, Design and Analysis Transform and Conquer Algorithms Presorting HeapSort.
Version TCSS 342, Winter 2006 Lecture Notes Priority Queues Heaps.
10/22/2002CSE Red Black Trees CSE Algorithms Red-Black Trees Augmenting Search Trees Interval Trees.
Chapter 6: Priority Queues Priority Queues Binary Heaps Mark Allen Weiss: Data Structures and Algorithm Analysis in Java Lydia Sinapova, Simpson College.
Heaps & Priority Queues Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
Source: Muangsin / Weiss1 Priority Queue (Heap) A kind of queue Dequeue gets element with the highest priority Priority is based on a comparable value.
MA/CSSE 473 Day 28 Hashing review B-tree overview Dynamic Programming.
Heapsort Based off slides by: David Matuszek
Compiled by: Dr. Mohammad Alhawarat BST, Priority Queue, Heaps - Heapsort CHAPTER 07.
MA/CSSE 473 Day 20 Josephus problem Transform and conquer examples.
MA/CSSE 473 Day 22 Binary Heaps Heapsort Answers to student questions Exam 2 Tuesday, Nov 4 in class.
MA/CSSE 473 Day 23 Transform and Conquer. MA/CSSE 473 Day 23 Scores on HW 7 were very high (class average was 93%). Good job! (Score was not included.
For Monday Read Weiss, chapter 7, sections 1-3. Homework –Weiss, chapter 4, exercise 6. Make sure you include parentheses where appropriate.
1 CSC 421: Algorithm Design Analysis Spring 2014 Transform & conquer  transform-and-conquer approach  presorting  balanced search trees, heaps  Horner's.
The Binary Heap. Binary Heap Looks similar to a binary search tree BUT all the values stored in the subtree rooted at a node are greater than or equal.
Priority Queues and Binary Heaps Chapter Trees Some animals are more equal than others A queue is a FIFO data structure the first element.
Chapter 21 Binary Heap.
Chapter 21 Priority Queue: Binary Heap Saurav Karmakar.
MA/CSSE 473 Day 21 AVL Tree Maximum height 2-3 Trees Student questions?
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 9.
1 Joe Meehean.  We wanted a data structure that gave us... the smallest item then the next smallest then the next and so on…  This ADT is called a priority.
Priority Queues and Heaps. October 2004John Edgar2  A queue should implement at least the first two of these operations:  insert – insert item at the.
Binary Search Trees (BSTs) 18 February Binary Search Tree (BST) An important special kind of binary tree is the BST Each node stores some information.
8 January Heap Sort CSE 2011 Winter Heap Sort Consider a priority queue with n items implemented by means of a heap  the space used is.
Heaps & Priority Queues
CIS 068 Welcome to CIS 068 ! Lesson 12: Data Structures 3 Trees.
FALL 2005CENG 213 Data Structures1 Priority Queues (Heaps) Reference: Chapter 7.
Internal and External Sorting External Searching
AVL Trees and Heaps. AVL Trees So far balancing the tree was done globally Basically every node was involved in the balance operation Tree balancing can.
Lecture 14 Jianjun Hu Department of Computer Science and Engineering University of South Carolina CSCE350 Algorithms and Data Structure.
Mergeable Heaps David Kauchak cs302 Spring Admin Homework 7?
Lecture 10COMPSCI.220.FS.T Binary Search Tree BST converts a static binary search into a dynamic binary search allowing to efficiently insert and.
HeapSort 25 March HeapSort Heaps or priority queues provide a means of sorting: 1.Construct a heap, 2.Add each item to it (maintaining the heap.
1 CSC 421: Algorithm Design Analysis Spring 2013 Transform & conquer  transform-and-conquer approach  presorting  balanced search trees, heaps  Horner's.
1 Priority Queues (Heaps). 2 Priority Queues Many applications require that we process records with keys in order, but not necessarily in full sorted.
MA/CSSE 473 Day 23 Review of Binary Heaps and Heapsort
MA/CSSE 473 Day 20 Finish Josephus
AVL TREES.
Heaps, Heap Sort and Priority Queues
Data Structures & Algorithms
Chapter 6 Transform-and-Conquer
October 30th – Priority QUeues
MA/CSSE 473 Day 21 AVL Tree Maximum height 2-3 Trees
ADT Heap data structure
7/23/2009 Many thanks to David Sun for some of the included slides!
original list {67, 33,49, 21, 25, 94} pass { } {67 94}
Written Midterm Solutions
Chapter 6 Transform and Conquer.
Transform and Conquer This group of techniques solves a problem by a transformation to a simpler/more convenient instance of the same problem (instance.
Hassan Khosravi / Geoffrey Tien
Chapter 6: Transform and Conquer
Transform and Conquer This group of techniques solves a problem by a transformation to a simpler/more convenient instance of the same problem (instance.
Transform and Conquer Transform and Conquer Transform and Conquer.
Transform and Conquer Transform and Conquer Transform and Conquer.
2-3 Trees Extended tree. Tree in which all empty subtrees are replaced by new nodes that are called external nodes. Original nodes are called internal.
Priority Queues (Heaps)
Priority Queues Binary Heaps
Presentation transcript:

MA/CSSE 473 Day 25 Transform and Conquer Student questions?

Transform and Conquer Algorithms But first: Answer student questions Transform a problem to a simpler instance of the same problem – instance simplification Transformation to a different representation of the same instance – representation change Transformation to an instance of a different problem that we know how to solve – problem reduction Q1

Instance simplification: Presorting an Array The following problems are simplified by pre- sorting the array: –Search (can do Binary or Interpolation search) –Determine whether the array contains duplicates –Find the median of the array –Find the mode of the elements of the array The most frequently-occurring element –A related problem: Anagrams In a large collection of words, find words that are anagrams of each other How can pre-sorting help? Sort the letters of each word –Interval union problem from early part of PLC Q2-3

Instance Simplificaiton: Gaussian Elimination (hopefully you saw it in a DE class) Solve a system of n linear equations in n unknowns –Represent the system by an augmented coefficient matrix –Transform the matrix to triangular matrix by a combination of the following solution-preserving elementary operations: exchange two rows multiply a row by a nonzero constant replace a row by that row plus or minus a constant multiple of a different row –Look at the algorithm and analysis on pp ; if you can't understand them, ask at some point. –Ѳ(n 3 ) [previous HW] Q4-5

Other Applications of G.E. Matrix inverse –Augment a square matrix by the identity matrix –Perform elementary operations until the original matrix is the identity. –The "augmented part" will be the inverse –More details and an example at Jordan_elimination Jordan_elimination

Other Applications of G.E. Determinant calculation –Calculation of the determinant of a triangular matrix is easy What effect does each of the elementary operations have on the determinant? –exchange two rows –multiply a row by a nonzero constant –replace a row by that row plus or minus a constant multiple of a different row Do these operations until you get a triangular matrix Keep track of the operations' cumulative effect on the determinant

LU Decomposition This can speed up all three applications of Gaussian Elimination Write the matrix A as a product of a Lower Triangular matrix L and an upper Triangular matrix U. Example: Q6

Representation change: AVL Trees (what you should remember…) Named for authors of original paper, Adelson-Velskii and Landis (1962). An AVL tree is a height-balanced Binary Search Tree. A BST T is height balanced if T is empty, or if – | height( T L ) - height( T R ) |  1, and – T L and T R are both height-balanced. Show: Maximum height of an AVL tree with N nodes is  (log N). How do we maintain balance after insertion? Exercise: Given a pointer to the root of an AVL tree with N nodes, find the height of the tree in log N time. Details on balance codes and various rotations are in the CSSE 230 slides that are linked from the schedule page. Quiz questions for later (not for submission)

Representation change: 2-3 trees Another approach to balanced trees Keeps all leaves on the same level Some non-leaf nodes have 2 keys and 3 subtrees Others are regular binary nodes. Q7

2-3 tree insertion example More examples of insertion: 3_trees_covered.pdf 3_trees_covered.pdf

Efficiency of 2-3 tree insertion Upper and lower bounds on height of a tree with n elements? Worst case insertion and lookup times is proportional to the height of the tree. Q8

2-3 Tree insertion practice Insert 84 into this tree and show the resulting tree Q9-11

2-3 Tree insertion practice Insert 84 into this tree and show the resulting tree

Binary (max) Heap Quick Review An almost-complete Binary Tree –All levels, except possibly the last, are full –On the last level all nodes are as far left as possible –No parent is smaller than either of its children –A great way to represent a Priority Queue Representing a binary heap as an array: See also Weiss, Chapter 21 (Weiss does min heap) Q? Representation change example

Insertion and RemoveMax Insertion: –Insert at the next position to maintain an almost- complete tree, then percolate up to restore heap property. RemoveMax: –Move last element of the heap to the root, then percolate down to restore heap property. Both operations are Ѳ(log n). Demo: heaps.html heaps.html

HeapSort Arrange array into a heap Starting from the root, remove each element from the heap and move to the end of the array. Animation: heapsort.html heapsort.html Faster heap building algorithm: buildheap ucture/HeapSort/heap_applet.html ucture/HeapSort/heap_applet.html Q?-??