4 Pages

lec9

Course: CSC 8301, Fall 2008
School: Villanova
Rating:
 
 
 
 
 

Word Count: 594

Document Preview

CSC 8301 Lecture 9 CSC 8301- Design and Analysis of Algorithms 8301Transform and Conquer representation change: Heapsort Reading: Chapter 6, Section 6.4 Exercises: 6.4: 1, 2, 3a, 6, 10 Next time: Space-time tradeoffs (Chapter 7) Lecture 9 Transform and Conquer Solve problem by transforming into: a more convenient instance of the same problem (instance implification) (instance implification) presorting Gaussian...

Register Now

Unformatted Document Excerpt

Coursehero >> Pennsylvania >> Villanova >> CSC 8301

Course Hero has millions of student submitted documents similar to the one
below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.

Course Hero has millions of student submitted documents similar to the one below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.
CSC 8301 Lecture 9 CSC 8301- Design and Analysis of Algorithms 8301Transform and Conquer representation change: Heapsort Reading: Chapter 6, Section 6.4 Exercises: 6.4: 1, 2, 3a, 6, 10 Next time: Space-time tradeoffs (Chapter 7) Lecture 9 Transform and Conquer Solve problem by transforming into: a more convenient instance of the same problem (instance implification) (instance implification) presorting Gaussian elimination a different representation of the same instance (representation change) (representation change) balanced search trees heaps and heapsort polynomial evaluation by Horner s rule Fast Fourier Transform a different problem altogether (problem reduction) (problem reduction) reductions to graph problems linear programming CSC 8301 Design and Analysis of Algorithms - Lecture 9 2 Heapsort Solve instance of problem by transforming into another simpler/easier instance of the same problem Definition: A heap is a binary tree with the following conditions: it is essentially complete: The key at each node is keys at its children CSC 8301 Design and Analysis of Algorithms - Lecture 9 3 1 CSC 8301 Lecture 9 Definition implies: Given n, there exists a unique binary tree with n nodes that is essentially complete, with h= lg n The root has the largest key The <a href="/keyword/subtree-rooted/" >subtree rooted</a> at any node of a heap is also a heap CSC 8301 Design and Analysis of Algorithms - Lecture 9 4 Heapsort Algorithm: 1. Build heap Remove root exchange with last (rightmost) leaf Fix up heap (excluding last leaf) 2. 3. Repeat 2, 3 until heap contains just one node. CSC 8301 Design and Analysis of Algorithms - Lecture 9 5 Heap construction Insert elements in the order given breadth-first in a binary breadthtree Starting with the last (rightmost) parental node, fix the heap rooted at it, if it does not satisfy the heap condition: 1. exchange it with its largest child 2. fix the <a href="/keyword/subtree-rooted/" >subtree rooted</a> at it (now in the child s position) Example: 1 2 4 9 3 5 CSC 8301 Design and Analysis of Algorithms - Lecture 9 6 2 CSC 8301 Lecture 9 Representation Use an array to store breadth-first traversal of heap tree: breadthExample: 9 5 1 4 2 3 1 2 3 4 5 6 9 5 3 1 4 2 Left child of node j is at 2j 2j Right child of node j is at 2j+1 2j Parent of node j is at j /2 Parental nodes are represented in the first n /2 locations CSC 8301 Design and Analysis of Algorithms - Lecture 9 7 Analysis of Heapsort See algorithm HeapBottomUp in section 6.4 Fix heap with problem at level h: 2h comparisons For <a href="/keyword/subtree-rooted/" >subtree rooted</a> at level i it does 2(h-i) comparisons 2(h Total for heap construction phase: 2(h-i) 2 i=0 h-1 i = 2 ( n lg (n + 1)) = (n) # nodes at level i CSC 8301 Design and Analysis of Algorithms - Lecture 9 8 Analysis of Heapsort (continued) Recall algorithm: (n) 1. Build heap 2. Remove root exchange with last (rightmost) leaf (log n) 3. Fix up heap (excluding last leaf) Repeat 2, 3 until heap contains just one node. n 1 times Total: (n) + (log n) = (log n) Note: this is the worst case. Average case also (log n). CSC 8301 Design and Analysis of Algorithms - Lecture 9 9 3 CSC 8301 Lecture 9 Priority queues A priority queue is the ADT of an ordered set with the operations: find element with highest priority delete element with highest priority insert element with assigned priority Heaps are very good for implementing priority queues CSC 8301 Design and Analysis of Algorithms - Lecture 9 10 Insertion of a new element Insert element at last position in heap. Compare with its parent and if it violates heap condition exchange them Continue comparing the new element with nodes up the tree until the heap condition is satisfied Example: Efficiency: CSC 8301 Design and Analysis of Algorithms - Lecture 9 11 Bottom-up vs. Top-down heap construction BottomTopTop down: Heaps can be constructed by successively inserting elements into an (initially) empty heap Bottom-up: Put everything in and then fix it BottomWhich one is better? CSC 8301 Design and Analysis of Algorithms - Lecture 9 12 4
Find millions of documents on Course Hero - Study Guides, Lecture Notes, Reference Materials, Practice Exams and more. Course Hero has millions of course specific materials providing students with the best way to expand their education.

Below is a small sample set of documents:

Villanova - ECE - 8830
ECE 8830 Electric DrivesTopic 18: Sensorless and Adaptive Vector Control of Induction Motor Drives Spring 2004 Introduction Position encoders/resolvers are expensive and introduce reliability con
Villanova - ECE - 3240
Villanova - MGT - 2206
Document ViewPage 1 of 3ASK US | HelpInterface language:BasicAdvancedTopicsPublicationsMy Research0 marked itemsEnglishGoDatabases selected: Multiple databases.Document ViewPrint | Email | Copy link | Back to ResultsCite t
Villanova - CSC - 2400
Chapter 3 Intel Architecture 32-bit (IA32)11Compiling into AssemblyC Code (sum.c)int sum(int x, int y) { int t = x+y; return t; } Obtain with command gcc -O -S sum.c Produces file sum.sGenerated Assembly (sum.s)_sum: pushl %ebp movl %esp,
Villanova - MAT - 1505
Villanova - MAT - 2500
Villanova - MAT - 2500
Villanova - MAT - 2705
Villanova - MAT - 1500
Villanova - MATH - 8412
Math 8412, Homework#5. Due February 19, 2008 1. In a study of the eect of baking temperature and mix on cake quality, three mixes were used: A, B, and C. One of the three mixes was chosen at random, ve cakes were poured, and one cake was baked at eac
Villanova - MATH - 8412
Math 8412, Homework#7. Due March 18, 2008 1. Data from a two-factor completely randomized experiment is tabled below. (a) Using SAS, obtain the Type I, Type II, Type III, and Type IV sums of squares for each of the two factors and the interaction. (b
Villanova - MATH - 8412
Villanova - MATH - 8412
Villanova - MATH - 8412
Math 8412, Homework#1. Due January 22, 2008 1. Using the data given below, answer each of the following parts. Treatment 1 1.06 0.95 0.79 0.65 0.82 1.15 0.89 1.12 1.05 Treatment 2 1.58 1.12 1.45 0.91 0.57 0.83 1.16 0.43 Treatment 3 0.29 0.43 0.06 0.0
UNC Asheville - ATMS - 455
Warm Cloud ProcessesDr. Christopher M. Godfrey University of North Carolina AshevilleWarm clouds lie completely below the 0 isotherm0oCATMS 455:Physical Meteorology Spring 2009ATMS 455:Physical Meteorology Spring 2009Some definitionsLiqu
UNC Asheville - ATMS - 455
Physical Meteorology ATMS 455 Spring 2009 Study Guide for Exam IISince the last exam, weve studied ice crystal phenomena, diffraction, scattering, radiation principles, Earths radiation budget, and the surface energy balance. As with the last exam,
UNC Asheville - BIO - 338
BIO338: Mammalian PhysiologyL20: ElectrocardiographyUNC-Asheville, s2009Cardiac ElectrophysiologyJimmyAugustus D. Waller JimmySt Mary's Medical School, London 1856-1922electrodesSalt-water Salt-waterelectrodesWaller's electrogramLi
UNC Asheville - HUM - 124
Indus Valley CivilizationCa. 2700-1500 BCE Located in the lower Indus valley in an area called Sind. A sophisticated Bronze age culture flourished with planned communities. Houses laid out in a grid pattern and sewage systems were very advanced.
UNC Asheville - CHEM - 144
1CHEM 144 April 29, 2005Exam 3 Name_ Chapters 17.4 - 20 Instructor_h = 6.626 X 10-34 Jsec; c = 3.00 X 108 m/sec Grxn= Gorxn + RT ln QR = 0.08206 Latm/Kmole = 8.314 J/ Kmole F = 96485 C/mol = 96485 J/Vmole G = -n F E Ecell = Eocell -(0.0257/
UNC Asheville - HUM - 324
MODERNISMPeter Caulfield and Seamus McNerneyHumanities 324- 4/10/09 Introduction I. The dates and places of ModernismA. The broad limits: 1880-1950B. Germanic Modernism: 1880-1900 1. Germany 2. Austria 3. Scandinavia, esp. NorwayC. Anglo-Amer
UNC Asheville - HUM - 324
ExistentialismFriday, April 24, 2009 Dr. Duane H. Davis Thesis: Existentialism poignantly calls our attention to the limits of idealism and rationalism redolent of the early modern era. The idealism of modern rationalism is to be rejected as providi
UNC Asheville - HUM - 324
THERISEOFFASCISMINTHEINTERWARYEARSHumanities324,April17 ProfessorMcClainOnemightconsiderFascismamethod(1928)FromthisfundamentalcharacterofFascistphilosophyderivesthose qualitiesthatarespokenofasFasciststyleastyleofliteraryexpression andastyleofp
UNC Asheville - HUM - 324
HUM 324Dr. Uldricks 21 April 2009 HITLER/NAZI GERMANY/WORLD WAR II/THE HOLOCAUST I. Hitler's ideology (Mein Kampf) A. Races, racial inequality, &amp; race war B. The pecking order 1. Aryans (Herrenvolk, bermenschen) 2. Romance peoples 3. Slavic peoples
UNC Asheville - HUM - 324
UNC Asheville - BIO - 338
BIO338: Mammalian PhysiologyL25: Blood PressureUNC-Asheville, s2009HOMEOSTASIS and REGULATION of BLOOD PRESSUREHomeostasis State of equilibrium of body; maintaining a constant internal state Physiological responses keep body functioning wit
UNC Asheville - HUM - 214
The Multiple Facets of African CulturesThe Egyptian Cultural Sphere: - Egyptian civilizations (Ancient Egyptian, Hellenic and Coptic) own their existence to the Nile river. However, the desert surrounding the Nile valley limited the spread of Egypt
Buffalo State - FACULTY - 356
3/31/2009Social and Emotional Development in Early ChildhoodPSY 356 Dr. SchuetzeTopics Development of Emotions Play Gender ParentingEmotional Development Rise in self-conscious emotions such as shame, embarrassment, guilt, envy and pride
Buffalo State - FACULTY - 356
3/17/2009Cognitive Development in Early ChildhoodPSY 356 Dr. SchuetzePiaget - Preoperational Stage2 to 7 years Preoperational thought: children use mental representations for objects and events. Operations: logical processes that can be reverse
Buffalo State - BIO - 450
TOPO TA Cloning Kit for SequencingFive-minute cloning of Taq polymerase-amplified PCR products for sequencingCatalog nos. K4530-20, K4575-J10, K4575-01, K4575-40, K4580-01, K4580-40, K4595-01, K4595-40, K4575-02Version O 10 April 2006 25-0276Cor
Buffalo State - FACULTY - 450
TOPO TA Cloning Kit for SequencingFive-minute cloning of Taq polymerase-amplified PCR products for sequencingCatalog nos. K4530-20, K4575-J10, K4575-01, K4575-40, K4580-01, K4580-40, K4595-01, K4595-40, K4575-02Version O 10 April 2006 25-0276Cor
East Los Angeles College - COM - 2040
COM2040/COM6650 Professional IssuesSlide 21. Introduction to Software ContractsCOM2040/COM6650 A software contract is a contract for the supply of software (either bespoke or off-the-shelf). Many such contracts are not sale contracts, but are
East Los Angeles College - COM - 2040
COM2040/COM6650 Professional IssuesSlide 21. Introduction Laws are formalised rules for regulating the behaviour of individuals and organisations in society.COM2040/COM6650 We focus on English law, which is the law governing England and Wale
UNC Asheville - MATH - 280
MATH 280, Section 1 Foundations of Mathematics Spring 2009Relations, Relations, Relations!I'm sure it wouldn't hurt any of us to take a moment to take stock of the sorts of relations we've studied in the past few weeks. Let's just begin by reviewi
Buffalo State - CHE - 403
EXPERIMENT 16. HIGH PERFORMANCE LIQUID CHROMATOGRAPHY The purpose of this experiment is to identify the aromatic hydrocarbons which are present in an unknown mixture and to determine the composition of the mixture. The student will also become famili
East Los Angeles College - PMA - 1050
2 A = {1, 3, 5, 6} B = {2, 3, 6} C = {1, 4, 6} (A B) C (A B) \ C (A \ B) C A \ (B C) A B C A \
UNC Asheville - MATH - 280
MATH 280, Section 1 Foundations of Mathematics Spring 2009Exam 2Working by yourself, please answer each question below on your own paper. You may use your class notes (but please no other resources!), and you may consult with me (but I promise not
UNC Asheville - HUM - 124
Spring 2009 / Driggers / Weekly Calendar / 1Humanities 124.007 The Ancient World Driggers Reading List and Weekly Class CalendarWeek 1 January 12 - 16 Readings: Fiero: 1-17, 36-45 The Asheville Reader (AR): Reading a Primary Text from Antiquity,
UNC Asheville - HUM - 124
Gender and Sexuality in AntiquityJames Driggers I. Why are we having this lecture? What can we hope to learn? A. How was sexuality defined in the ancient world? B. How did notions of sexuality differ from defined sex roles? C. What was the notion of
UNC Asheville - ARTS - 310
The Arts and Crafts Movement Lynne Caldwell (828) 215-9695 - scaldwel@unca.edu Office: 120 New Hall, Hours: Tuesday 12:30 2:00 or by appointment Readings: All readings will be available from the instructor. Course Goals and Objectives: By the end of
UNC Asheville - ARTS - 310
ARTS 310 Arts and IdeasThe Arts and Crafts Movement Lynne Caldwell (828) 215-9695 scaldwel@unca.edu Textbooks: Todd, Pamela. The Arts and Crafts Companion. Bulfinch Press, New York, NY, 2004. Other readings will be assigned and distributed in class
UNC Asheville - MATH - 280
MATH 280, Section 1 Foundations of Mathematics Spring 2009Tools of the Trade: Notation, volume IThe is the rst in a series of notation lists with which I will provide you as the semester progresses. Compiled below is a collection of mathematical s
UNC Asheville - MATH - 191
MATH 191, Section 2 Calculus I Spring 2009Section 4.1: The Chain RuleYou may have noticed that on one or two occasions this semester weve gone to extra lengths to avoid having to nd the derivatives of certain functions directly. Examples. (1) On o
UNC Asheville - MATH - 191
MATH 191, Section 2 Calculus I Spring 2009Section 3.8: I want my MVT!We had a brief encounter earlier with one of the most important theorems from calculus, namely the Intermediate Value Theorem (IVT). You may recall that IVT says the following: I
UNC Asheville - MATH - 191
MATH 191, Section 2 Calculus I Spring 2009Section 4.2: Implicit dierentiation and related rates of changeLets dive right in with andy Example. Suppose we want to nd dx if we know that x2 + y 2 = 1, but were too lazy to solve for y to nd the right
UNC Asheville - HUM - 414
The Military - Energy Connection Dot Sulock, Department of Mathematics, April 2009 I. Does US military spending provide national security? 2007 US military spending: $620 billion - more than rest of worlds combined military spending although we are l
UNC Asheville - HUM - 414
Environmental Ethics: Theoretical Foundations Grace Campbell Humanities 414 April 20, 2009 I. Foundational Assumptions: A. Anthropogenic (Human- Caused) change B. Evolution? C. Science and Ethics II. Nature / Culture Split A. Monotheism B. Scientific
UNC Asheville - ATMS - 103
Stay Informed. Use NOAA Weather RadioNOAANOAA Weather Radio is the best means to receive warnings from the National Weather ServiceThe National Weather Service continuously broadcasts warnings and forecasts that can be received by NOAA Weather R
UNC Asheville - ATMS - 103
Temperature Changes Associated with a Cold Frontal Passage on Tuesday, January 29, 2008Images compiled by: Sam Shea Service Climatologist NOAA Midwestern Regional Climate CenterPrepared by: Dr. Christopher Godfrey University of North Carolina Ashev
UNC Asheville - C - 314
Exploring the Morse PotentialbyTheresa Julia Zielinski Department of Chemistry, Medical Technology, and Physics Monmouth University West Long Branch, NJ 07763-1898tzielins@monmouth.edu Copyright Theresa Julia Zielinski 1997. All rights reserved
UNC Asheville - MATH - 280
MATH 280, Section 1 Foundations of Mathematics Spring 2009Tools of the Trade: Notation and Denitions, volume VMore! This time, the focus is on relations and functions. (1) Recall that a relation R between the sets S and T is nothing more than a su
UNC Asheville - MATH - 280
MATH 280, Section 1 Foundations of Mathematics Spring 2009Tools of the Trade: Notation and Denitions, volume IVMore! (1) Lets start with some more set theory notation and terminology: The set dierence of S and T is the set S \ T = {s S | s T }.
UNC Asheville - MATH - 461
MATH 461, Sections 1 and 2 Abstract Algebra I Fall 2008Citation stylesheetThere is no single &quot;correct&quot; citation style in the field of mathematics; several different citation styles may be used, as long as they are used consistently within a single
UNC Asheville - MATH - 461
MATH 461, Sections 1 and 2 Abstract Algebra I Fall 2008Handout 21: Rings!Denition. A ring (R, +, ) is a triple consisting of a set R such that 1. (R, +) is an abelian group (+ is usually called addition) 2. R is closed under the operation (usuall
East Los Angeles College - HEA - 12423
PROGRAMME DETAIL SPECIFICATION Programme Summary1 Awarding institution 2 Teaching institution university 3a Programme accredited by: 3b Description of accreditation 4 Final award 5 Programme title 6 UCAS code 7 Subject benchmark statementLiverpoo
East Los Angeles College - HEA - 12491
PROGRAMME DETAIL SPECIFICATION Programme Summary1 Awarding institution 2 Teaching institution university 3a Programme accredited by: 3b Description of accreditation 4 Final award 5 Programme title 6 UCAS code 7 Subject benchmark statementLiverpoo
Clark University - CS - 160
Todays LectureCSCI 160: AlgorithmsLecture 18 Fall 2008The Tree Approach Smart Unions Path Compression AnalysisThe Tree ApproachExample0 1 1 -1 2 0 3 -1 4 -1 5 4 6 4 7 601234567We can use an array to represent a forest s[x]
S. New Hampshire - EFL - 537
Language Learning and acquisitionSubmitted by: Mouna Ettoumi Instructor: Katherine McCarthy Center: ManchesterResearch BackgroundThis research answers four main questions: What is transfer? How does 1st language influences the 2nd language? D
Clark University - ECON - 160
Spring 2002Econ 160,Assignment 1Completing this assignment requires knowledge of Excel (or any similar statistical package) accessible in Clark University Computer rooms. If you need instruction in Excel, contact the TA or myself for assistance
Clark University - ECON - 208
Economist.com | Country Briefings: Thailandhttp:/www.economist.com/countries/Thailand/PrinterFriend.GoHistory in briefDec 16th 2003 From Economist.comThe Thais, originally from the mountainous border region between China and South-East Asia,
Clark University - ECON - 208
Economist.com | Country Briefings: Francehttp:/www.economist.com/countries/France/PrinterFriendly.GoHistory in briefJan 30th 2004 From Economist.comCelts, Greeks and other peoples had colonised Gaul (ancient France) when the Romans political
Clark University - ECON - 208
Economist.comhttp:/www.economist.com/surveys/PrinterFriendly.cfm?St.Make or breakFeb 20th 2003 From The Economist print editionReutersUnder its new leader, Luiz Incio Lula da Silva, Brazil could take a leap into prosperityor slide back towa