Search Tree Applications
|
|
- Moris Newman
- 6 years ago
- Views:
Transcription
1 Search Tree Applications 7.1
2 Line Segment Intersection: Detection 7.2
3 Horizontal-Vertical Line Segment Intersection Given: set L H of horizontal line segments; set L V of vertical line segments. Does any line segment in L V intersect a line segment in L H? 7.3
4 Horizontal-Vertical Line Segment Intersection h i U Q S g f e V W d c R a T b 7.4
5 Horizontal-Vertical Line Segment Intersection Brute force algorithm: 1 foreach vertical line segment σ V L V do 2 foreach horizontal line segment σ H L H do 3 if σ H σ V then 4 q σ H σ V ; 5 return (q); 6 end 7 end 8 end 9 return ( No intersection ); 7.5
6 Sort Horizontal Lines h i U Q S g f e V W d c R a T b 7.6
7 1 L V vertical line segments; Sort Horizontal Lines 2 L H horizontal line segments sorted by increasing y; 3 foreach vertical line segment σ V L V do 4 σ H first line segment in L H with σ H.y σ V.miny; 5 while (σ H NIL) and (σ H.y σ v.maxy) do 6 if σ H σ V then 7 q σ H σ V ; 8 return (q); 9 end /* Get next horizontal segment in L H */ 10 σ H σ H.Next; 11 end 12 end 13 return ( No intersection ); 7.7
8 Line Sweep Algorithm h i U Q S g f e V W d c R a T b 7.8
9 Line Sweep Algorithm 1 L V vertical line segments sorted by increasing x; 2 L H horizontal line segments sorted by increasing y; 3 foreach vertical line segment σ V L V do 4 σ H first line segment in L H with σ H.y σ V.miny; 5 while (σ H NIL) and (σ H.y σ v.maxy) do 6 if σ H σ V then 7 q σ H σ V ; 8 return (q); 9 end /* Get next horizontal segment in L H */ 10 σ H σ H.Next; 11 end 12 end 13 return ( No intersection ); 7.9
10 Line Sweep Algorithm h i U Q S g f e V W d c R a T b 7.10
11 Tree Minimum Greater Than or Equal to Find minimum key greater than or equal to
12 Tree Minimum Greater Than or Equal to function TreeMinGE(T, K) /* Return node with min key greater than or equal to K */ 1 u NIL; 2 v T.root; 3 while (v NIL) do 4 if (K v.key) then 5 u v; 6 v v.left; 7 else 8 v v.right; 9 end 10 end 11 return (u); 7.12
13 Horizontal-Vertical Line Segment Intersection 1 T.Init(); 2 L endpoints of all line segments sorted by x-coordinate; 3 foreach point p L do 4 if (p is the left endpoint of a horizontal segment σ H ) then 5 Create new tree node u with 6 u.key = σ H.y and u.data.lineseg = σ H ; 7 TreeInsert (T, u); 8 else if (p is the lower endpoint of a vertical segment σ V ) then 9 u TreeMinGE (T, p.y); 10 if (u NIL) and (u.y σ V.maxy) then 11 return (u.data.lineseg σ V ); 12 else if (p is the right endpoint of a horizontal segment σ H ) then 13 u tree node representing σ H ; 14 TreeDelete (T,u); 15 end 16 end 17 return ( No intersection ); CSE
14 Line Segment Intersection: Reporting 7.14
15 Report All HV Line Segment Intersections Given: set L H of horizontal line segments; set L V of vertical line segments. Report all the intersections of line segments in L H and L V. 7.15
16 Report All HV Line Segment Intersections h i U Q S g f e V W R d c a T b 7.16
17 Report All HV Line Segment Intersections Brute force algorithm: 1 foreach horizontal line segment σ H L H do 2 foreach vertical line segment σ V L V do 3 if σ H σ V then 4 q σ H σ V ; 5 Report intersection point q; 6 end 7 end 8 end 7.17
18 Running Times of Reporting Let I = number of intersections. Desired running time is Θ(f(n) + I) where f(n) is small (e.g., f(n) Θ(n log 2 (n)).) 7.18
19 Report: Line Sweep Algorithm h i U Q S g f e V W R d c a T b 7.19
20 1 T.Init(); Report All HV Line Segment Intersections 2 L endpoints of all line segments sorted by x-coordinate; 3 foreach point p L do 4 if (p is the left endpoint of a horizontal segment σ H ) then 5 Create new tree node u with 6 u.key = σ H.y and u.data.lineseg = σ H ; 7 u.data.lineseg σ H ; 8 TreeInsert (T, u); 9 else if (p is the lower endpoint of a vertical segment σ V ) then 10 Report line segments in T intersecting σ V ; 11 else if (p is the right endpoint of a horizontal segment σ H ) then 12 u tree node representing σ H ; 13 TreeDelete (T,u); 14 end 15 end 7.20
21 Report in Range Report all nodes of the following tree with keys in range [8, 25]: (Range [8, 25] includes 8 and 25.)
22 Report in Range: Running Time procedure TreeRangeReport(x, k min, k max ) 1 if (x NIL) then 2 if (k min x.key) then 3 TreeRangeReport(x.left, k min, k max ); 4 end 5 if (k min x.key k max ) then print x.key; 6 if (x.key k max ) then 7 TreeRangeReport(x.right, k min, k max ); 8 end 9 end h = tree height I = number of nodes reported. Running time: 7.22
23 1 T.Init(); Report All HV Line Segment Intersections 2 L endpoints of all line segments sorted by x-coordinate; 3 foreach point p L do 4 if (p is the left endpoint of a horizontal segment σ H ) then 5 Create new tree node u with 6 u.key = σ H.y and u.data.lineseg = σ H ; 7 u.data.lineseg σ H ; 8 TreeInsert (T, u); 9 else if (p is the lower endpoint of a vertical segment σ V ) then 10 TreeRangeReport (T.root, σ V.miny, σ V.maxy); 11 else if (p is the right endpoint of a horizontal segment σ H ) then 12 u tree node representing σ H ; 13 TreeDelete (T,u); 14 end 15 end 7.23
24 Line Segment Intersection: Counting 7.24
25 Count HV Line Segment Intersections Given: set L H of horizontal line segments; set L V of vertical line segments. For each σ V L V, count number of intersections with lines in L H. 7.25
26 Count HV Line Segment Intersections h i U Q S g f e V W R d c a T b 7.26
27 1 count 0; 2 T.Init(); Count HV Line Segment Intersections 3 L endpoints of all line segments sorted by x-coordinate; 4 foreach point p L do 5 if (p is the left endpoint of a horizontal segment σ H ) then 6 Create new tree node u; 7 u.key σ H.y; 8 u.data.lineseg σ H ; 9 TreeInsert (T, u); 10 else if (p is the lower endpoint of a vertical segment σ V ) then 11 count count+ CountNumIntersections (T, σ V ); 12 else if (p is the right endpoint of a horizontal segment σ H ) then 13 u tree node representing σ H ; 14 TreeDelete (T,u); 15 end 16 end 7.27
28 Binary Search Tree: Counting For each node u in the binary search tree, add a field u.size which stores the number of nodes in the subtree rooted at u
29 Count Nodes Greater Than or Equal to function TreeCountGE(x, K) /* Return number of nodes with keys greater than or equal to K in subtree rooted at x */ 1 count 0; 2 v x; 3 while (v NIL) do 4 if (v.key K) then 5 count count + 1; 6 if (v.right NIL) then count count + v.right.size; 7 v v.left; 8 else 9 v v.right; 10 end 11 end 12 return (count); 7.29
30 Count Number of Nodes in Range function TreeRangeCount(x, k min, k max ) /* Return number of nodes with keys in range [k min, k max ] in subtree rooted at x */ 1 v x; 2 while (v NIL) and (v.key [k min, k max ]) do 3 if (v.key k min ) then v v.right; 4 else if (v.key k max ) then v v.left; 5 end 6 if (v NIL) then 7 count L TreeCountGE(v.left, k min ); 8 count R TreeCountLE(v.right, k max ); 9 return (1 + count L + count R ); 10 else return (0); 7.30
31 1 count 0; 2 T.Init(); Count HV Line Segment Intersections 3 L endpoints of all line segments sorted by x-coordinate; 4 foreach point p L do 5 if (p is the left endpoint of a horizontal segment σ H ) then 6 Create new tree node u; 7 u.key σ H.y; 8 u.data.lineseg σ H ; 9 TreeInsert (T, u); 10 else if (p is the lower endpoint of a vertical segment σ V ) then 11 count count+ TreeRangeCount (T, σ V.miny, σ V.maxy); 12 else if (p is the right endpoint of a horizontal segment σ H ) then 13 u tree node representing σ H ; 14 TreeDelete (T,u); 15 end 16 end 7.31
32 Point Location u G t E F D s q C B A v r 7.32
33 Point Location Given: set S rect of non-intersecting, axis-parallel rectangles; set S point of points. Report the rectangle containing each point. 7.33
34 Data Structures: Applications 7.34
35 Data Structures Stack; Heap (HeapSort, Prim s MST algorithm, Dijkstra s shortest path algorithm); Red-black tree (Line segment intersection); Hash table (Duplicate elements, counting number of elements); Union-find structure (Connected components). 7.35
36 Exercise: Deep Thought - Highest Priority You are in charge of the supercomputer Deep Thought. Deep Thought has an Input List of programs which it needs to process; Every minute new programs are being added to the Input List by scientists from across the world; Each program has a priority number from 1 to ; Each time Deep Thought completes a program, it selects the next program with highest priority from the Input List and works on that program. Give a data structure for quickly adding new programs to the list and selecting the next program for Deep Thought to process. 7.36
37 Exercise: Deep Thought - Count Competitive scientists always want to know how many other programs in the Input List have priority less than their program, and how many have priority greater than their program. Every minute new programs are being added to the Input List by scientists from across the world; Each program has a priority number from 1 to ; Each time Deep Thought completes a program, it selects the next program with highest priority from the Input List and works on that program. Give a data structure which allows a scientist to quickly query how many programs in the Input List have higher priority and how many programs have lower priority. 7.37
38 Exercise: Deep Thought - Wait Because Deep Thought is such a valuable resource, some scientists want to hog Deep Thought for their research. For this reason, you instituted a rule that after a scientist has submitted a program, she must wait 24 hours until she can submit another program. Each scientist has a 128 bit password which she must submit with her program; Each program has a submission time which is the time the program was added to the Input List. Give a data structure for quickly determining if the scientist who submitted a program has waited 24 hours from the last time she submitted a program. 7.38
39 Exercise: Deep Thought - Median Priority Some selfish scientists have been assigning high priority to their programs to get them processed first. To punish such selfishness, Deep Thought no longer selects the program with highest priority from the Input List. Instead, Deep Thought selects the program with median priority. Every minute new programs are being added to the Input List by scientists from across the world; Each time Deep Thought completes a program, it selects the next program with median priority from the Input List and works on that program. Let n be the number of programs in the Input List. The median priority is an integer I such that n/2 elements have priority less than or equal to I and n/2 elements have priority greater than or equal to I. Give a data structure for quickly adding new programs to the list and selecting the next program for Deep Thought to process. 7.39
Priority Queues. Priority Queues Trees and Heaps Representations of Heaps Algorithms on Heaps Building a Heap Heapsort.
Priority Queues Trees and Heaps Representations of Heaps Algorithms on Heaps Building a Heap Heapsort Philip Bille Priority Queues Trees and Heaps Representations of Heaps Algorithms on Heaps Building
More informationComputational Geometry
Windowing queries Windowing Windowing queries Zoom in; re-center and zoom in; select by outlining Windowing Windowing queries Windowing Windowing queries Given a set of n axis-parallel line segments, preprocess
More informationCS2 Algorithms and Data Structures Note 6
CS Algorithms and Data Structures Note 6 Priority Queues and Heaps In this lecture, we will discuss priority queues, another important ADT. As stacks and queues, priority queues store arbitrary collections
More informationCSE2331/5331. Topic 6: Binary Search Tree. Data structure Operations CSE 2331/5331
CSE2331/5331 Topic 6: Binary Search Tree Data structure Operations Set Operations Maximum Extract-Max Insert Increase-key We can use priority queue (implemented by heap) Search Delete Successor Predecessor
More informationSorting and Searching
Sorting and Searching Lecture 2: Priority Queues, Heaps, and Heapsort Lecture 2: Priority Queues, Heaps, and Heapsort Sorting and Searching 1 / 24 Priority Queue: Motivating Example 3 jobs have been submitted
More informationComputer Science 385 Design and Analysis of Algorithms Siena College Spring Lab 8: Greedy Algorithms Due: Start of your next lab session
Computer Science 385 Design and Analysis of Algorithms Siena College Spring 2017 Lab 8: Greedy Algorithms Due: Start of your next lab session You will be assigned groups of size 2 or 3 for this lab. Only
More informationSorting and Searching
Sorting and Searching Lecture 2: Priority Queues, Heaps, and Heapsort Lecture 2: Priority Queues, Heaps, and Heapsort Sorting and Searching 1 / 24 Priority Queue: Motivating Example 3 jobs have been submitted
More informationCS2 Algorithms and Data Structures Note 6
CS Algorithms and Data Structures Note 6 Priority Queues and Heaps In this lecture, we will discuss another important ADT: PriorityQueue. Like stacks and queues, priority queues store arbitrary collections
More informationAlgorithms and Theory of Computation. Lecture 7: Priority Queue
Algorithms and Theory of Computation Lecture 7: Priority Queue Xiaohui Bei MAS 714 September 5, 2017 Nanyang Technological University MAS 714 September 5, 2017 1 / 15 Priority Queues Priority Queues Store
More informationCSci 231 Final Review
CSci 231 Final Review Here is a list of topics for the final. Generally you are responsible for anything discussed in class (except topics that appear italicized), and anything appearing on the homeworks.
More informationBinary Search Trees. Nearest Neighbor Binary Search Trees Insertion Predecessor and Successor Deletion Algorithms on Trees.
Binary Search Trees Nearest Neighbor Binary Search Trees Insertion Predecessor and Successor Deletion Algorithms on Trees Philip Bille Binary Search Trees Nearest Neighbor Binary Search Trees Insertion
More informationBinary Search Trees. Binary Search Trees. Nearest Neighbor. Nearest Neighbor
Philip Bille Nearest Neighbor Nearest neighbor. Maintain dynamic set S supporting the following operations. Each element has key x.key and satellite data x.data. PREDECESSOR(k): return element with largest
More informationChapter 6 Heapsort 1
Chapter 6 Heapsort 1 Introduce Heap About this lecture Shape Property and Heap Property Heap Operations Heapsort: Use Heap to Sort Fixing heap property for all nodes Use Array to represent Heap Introduce
More informationStacks, Queues, and Priority Queues. Inf 2B: Heaps and Priority Queues. The PriorityQueue ADT
Stacks, Queues, and Priority Queues Inf 2B: Heaps and Priority Queues Lecture 6 of ADS thread Kyriakos Kalorkoti School of Informatics University of Edinburgh Stacks, queues, and priority queues are all
More informationCOMP 251 Winter 2017 Online quizzes with answers
COMP 251 Winter 2017 Online quizzes with answers Open Addressing (2) Which of the following assertions are true about open address tables? A. You cannot store more records than the total number of slots
More informationWeighted Graphs and Greedy Algorithms
COMP 182 Algorithmic Thinking Weighted Graphs and Greedy Algorithms Luay Nakhleh Computer Science Rice University Reading Material Chapter 10, Section 6 Chapter 11, Sections 4, 5 Weighted Graphs In many
More information( ) ( ) C. " 1 n. ( ) $ f n. ( ) B. " log( n! ) ( ) and that you already know ( ) ( ) " % g( n) ( ) " #&
CSE 0 Name Test Summer 008 Last 4 Digits of Mav ID # Multiple Choice. Write your answer to the LEFT of each problem. points each. The time for the following code is in which set? for (i=0; i
More information( D. Θ n. ( ) f n ( ) D. Ο%
CSE 0 Name Test Spring 0 Multiple Choice. Write your answer to the LEFT of each problem. points each. The time to run the code below is in: for i=n; i>=; i--) for j=; j
More information( ) + n. ( ) = n "1) + n. ( ) = T n 2. ( ) = 2T n 2. ( ) = T( n 2 ) +1
CSE 0 Name Test Summer 00 Last Digits of Student ID # Multiple Choice. Write your answer to the LEFT of each problem. points each. Suppose you are sorting millions of keys that consist of three decimal
More informationDesign and Analysis of Algorithms
CSE 1, Winter 201 Design and Analysis of Algorithms Lecture 7: Bellman-Ford, SPs in DAGs, PQs Class URL: http://vlsicad.ucsd.edu/courses/cse1-w1/ Lec. Added after class Figure.: Single-Edge Extensions
More informationBinary Search Trees. July 13th, Computer Information Systems. c 2009 Vaidė Narváez
Binary Search Trees Vaidė Narváez Computer Information Systems July 13th, 2010 Introduction Dynamic set operations: Search, Minimum, Maximum Predecessor, Successor Insert, Delete Time proportional to the
More informationCOP 4531 Complexity & Analysis of Data Structures & Algorithms
COP 4531 Complexity & Analysis of Data Structures & Algorithms Lecture 9 Minimum Spanning Trees Thanks to the text authors who contributed to these slides Why Minimum Spanning Trees (MST)? Example 1 A
More information( ) n 3. n 2 ( ) D. Ο
CSE 0 Name Test Summer 0 Last Digits of Mav ID # Multiple Choice. Write your answer to the LEFT of each problem. points each. The time to multiply two n n matrices is: A. Θ( n) B. Θ( max( m,n, p) ) C.
More informationChapter 4. Greedy Algorithms. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.
Chapter 4 Greedy Algorithms Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. 1 4.5 Minimum Spanning Tree Minimum Spanning Tree Minimum spanning tree. Given a connected
More informationRange Searching II: Windowing Queries
Computational Geometry Lecture : Windowing Queries INSTITUT FÜR THEORETISCHE INFORMATIK FAKULTÄT FÜR INFORMATIK Tamara Mchedlidze Chih-Hung Liu 23.11.2015 1 Object types in range queries y0 y x x0 Setting
More informationAdvanced Algorithm Design and Analysis (Lecture 12) SW5 fall 2005 Simonas Šaltenis E1-215b
Advanced Algorithm Design and Analysis (Lecture 12) SW5 fall 2005 Simonas Šaltenis E1-215b simas@cs.aau.dk Range Searching in 2D Main goals of the lecture: to understand and to be able to analyze the kd-trees
More informationAlgorithm Analysis Graph algorithm. Chung-Ang University, Jaesung Lee
Algorithm Analysis Graph algorithm Chung-Ang University, Jaesung Lee Basic definitions Graph = (, ) where is a set of vertices and is a set of edges Directed graph = where consists of ordered pairs
More informationLower Bound on Comparison-based Sorting
Lower Bound on Comparison-based Sorting Different sorting algorithms may have different time complexity, how to know whether the running time of an algorithm is best possible? We know of several sorting
More information( ). Which of ( ) ( ) " #& ( ) " # g( n) ( ) " # f ( n) Test 1
CSE 0 Name Test Summer 006 Last Digits of Student ID # Multiple Choice. Write your answer to the LEFT of each problem. points each. The time to multiply two n x n matrices is: A. "( n) B. "( nlogn) # C.
More informationCSC Design and Analysis of Algorithms. Lecture 8. Transform and Conquer II Algorithm Design Technique. Transform and Conquer
CSC 301- Design and Analysis of Algorithms Lecture Transform and Conquer II Algorithm Design Technique Transform and Conquer This group of techniques solves a problem by a transformation to a simpler/more
More information23.2 Minimum Spanning Trees
23.2 Minimum Spanning Trees Kruskal s algorithm: Kruskal s algorithm solves the Minimum Spanning Tree problem in O( E log V ) time. It employs the disjoint-set data structure that is similarly used for
More informationBinary Tree. Preview. Binary Tree. Binary Tree. Binary Search Tree 10/2/2017. Binary Tree
0/2/ Preview Binary Tree Tree Binary Tree Property functions In-order walk Pre-order walk Post-order walk Search Tree Insert an element to the Tree Delete an element form the Tree A binary tree is a tree
More informationCSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators)
Name: Email address: Quiz Section: CSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators) Instructions: Read the directions for each question carefully before answering. We will
More information3. Priority Queues. ADT Stack : LIFO. ADT Queue : FIFO. ADT Priority Queue : pick the element with the lowest (or highest) priority.
3. Priority Queues 3. Priority Queues ADT Stack : LIFO. ADT Queue : FIFO. ADT Priority Queue : pick the element with the lowest (or highest) priority. Malek Mouhoub, CS340 Winter 2007 1 3. Priority Queues
More information( ) D. Θ ( ) ( ) Ο f ( n) ( ) Ω. C. T n C. Θ. B. n logn Ο
CSE 0 Name Test Fall 0 Multiple Choice. Write your answer to the LEFT of each problem. points each. The expected time for insertion sort for n keys is in which set? (All n! input permutations are equally
More informationCSE 373 Spring 2010: Midterm #1 (closed book, closed notes, NO calculators allowed)
Name: Email address: CSE 373 Spring 2010: Midterm #1 (closed book, closed notes, NO calculators allowed) Instructions: Read the directions for each question carefully before answering. We may give partial
More informationExamination Questions Midterm 2
CS1102s Data Structures and Algorithms 12/3/2010 Examination Questions Midterm 2 This examination question booklet has 6 pages, including this cover page, and contains 12 questions. You have 30 minutes
More informationChapter 5 Data Structures Algorithm Theory WS 2016/17 Fabian Kuhn
Chapter 5 Data Structures Algorithm Theory WS 06/ Fabian Kuhn Examples Dictionary: Operations: insert(key,value), delete(key), find(key) Implementations: Linked list: all operations take O(n) time (n:
More informationCSE 202: Design and Analysis of Algorithms Lecture 3
CSE 202: Design and Analysis of Algorithms Lecture 3 Instructor: Kamalika Chaudhuri Announcement Homework 1 out Due on Mon April 11 in class No late homeworks will be accepted Greedy Algorithms Direct
More informationD. Θ nlogn ( ) D. Ο. ). Which of the following is not necessarily true? . Which of the following cannot be shown as an improvement? D.
CSE 0 Name Test Fall 00 Last Digits of Mav ID # Multiple Choice. Write your answer to the LEFT of each problem. points each. The time to convert an array, with priorities stored at subscripts through n,
More informationRanking. In an ordered set or a dictionary: Rank of key k is i iff k is the ith smallest key. Example: if s stores these keys 42, 55, 61, then:
Ranking In an ordered set or a dictionary: Rank of key k is i iff k is the ith smallest key. Example: if s stores these keys 42, 55, 61, then: s.rank(42) returns 1 s.rank(55) returns 2 s.rank(61) returns
More information( ) n 5. Test 1 - Closed Book
Name Test 1 - Closed Book Student ID # Multiple Choice. Write your answer to the LEFT of each problem. points each 1. During which operation on a leftist heap may subtree swaps be needed? A. DECREASE-KEY
More informationMinimum Spanning Trees
Minimum Spanning Trees Overview Problem A town has a set of houses and a set of roads. A road connects and only houses. A road connecting houses u and v has a repair cost w(u, v). Goal: Repair enough (and
More information1 Tree Sort LECTURE 4. OHSU/OGI (Winter 2009) ANALYSIS AND DESIGN OF ALGORITHMS
OHSU/OGI (Winter 2009) CS532 ANALYSIS AND DESIGN OF ALGORITHMS LECTURE 4 1 Tree Sort Suppose a sequence of n items is given. We can sort it using TreeInsert and DeleteMin: TreeSort Initialize an empty
More informationCSE 431/531: Analysis of Algorithms. Greedy Algorithms. Lecturer: Shi Li. Department of Computer Science and Engineering University at Buffalo
CSE 431/531: Analysis of Algorithms Greedy Algorithms Lecturer: Shi Li Department of Computer Science and Engineering University at Buffalo Main Goal of Algorithm Design Design fast algorithms to solve
More informationComputer Science E-22 Practice Final Exam
name Computer Science E-22 This exam consists of three parts. Part I has 10 multiple-choice questions that you must complete. Part II consists of 4 multi-part problems, of which you must complete 3, and
More informationDecreasing a key FIB-HEAP-DECREASE-KEY(,, ) 3.. NIL. 2. error new key is greater than current key 6. CASCADING-CUT(, )
Decreasing a key FIB-HEAP-DECREASE-KEY(,, ) 1. if >. 2. error new key is greater than current key 3.. 4.. 5. if NIL and.
More informationComputer Science Spring 2005 Final Examination, May 12, 2005
Computer Science 302 00 Spring 2005 Final Examination, May 2, 2005 Name: No books, notes, or scratch paper. Use pen or pencil, any color. Use the backs of the pages for scratch paper. If you need more
More informationInstructions. Definitions. Name: CMSC 341 Fall Question Points I. /12 II. /30 III. /10 IV. /12 V. /12 VI. /12 VII.
CMSC 341 Fall 2013 Data Structures Final Exam B Name: Question Points I. /12 II. /30 III. /10 IV. /12 V. /12 VI. /12 VII. /12 TOTAL: /100 Instructions 1. This is a closed-book, closed-notes exam. 2. You
More informationLecture 7. Transform-and-Conquer
Lecture 7 Transform-and-Conquer 6-1 Transform and Conquer This group of techniques solves a problem by a transformation to a simpler/more convenient instance of the same problem (instance simplification)
More information) $ f ( n) " %( g( n)
CSE 0 Name Test Spring 008 Last Digits of Mav ID # Multiple Choice. Write your answer to the LEFT of each problem. points each. The time to compute the sum of the n elements of an integer array is: # A.
More informationn 2 ( ) ( ) Ο f ( n) ( ) Ω B. n logn Ο
CSE 220 Name Test Fall 20 Last 4 Digits of Mav ID # Multiple Choice. Write your answer to the LEFT of each problem. 4 points each. The time to compute the sum of the n elements of an integer array is in:
More informationCOS 226 Midterm Exam, Spring 2009
NAME: login ID: precept: COS 226 Midterm Exam, Spring 2009 This test is 10 questions, weighted as indicated. The exam is closed book, except that you are allowed to use a one page cheatsheet. No calculators
More informationDictionaries. Priority Queues
Red-Black-Trees.1 Dictionaries Sets and Multisets; Opers: (Ins., Del., Mem.) Sequential sorted or unsorted lists. Linked sorted or unsorted lists. Tries and Hash Tables. Binary Search Trees. Priority Queues
More information18. Binary Search Trees
Trees. Binary Search Trees [Ottman/Widmayer, Kap..1, Cormen et al, Kap. 12.1-12.] Trees are Generalized lists: nodes can have more than one successor Special graphs: graphs consist of nodes and edges.
More informationMinimum-Spanning-Tree problem. Minimum Spanning Trees (Forests) Minimum-Spanning-Tree problem
Minimum Spanning Trees (Forests) Given an undirected graph G=(V,E) with each edge e having a weight w(e) : Find a subgraph T of G of minimum total weight s.t. every pair of vertices connected in G are
More information& ( D. " mnp ' ( ) n 3. n 2. ( ) C. " n
CSE Name Test Summer Last Digits of Mav ID # Multiple Choice. Write your answer to the LEFT of each problem. points each. The time to multiply two n " n matrices is: A. " n C. "% n B. " max( m,n, p). The
More informationTest points UTA Student ID #
CSE Name Test points UTA Student ID # Multiple Choice. Write your answer to the LEFT of each problem. points each. Which of the following statements is true about HEAPSOT? A. It is stable.. It has a worse-case
More informationlogn D. Θ C. Θ n 2 ( ) ( ) f n B. nlogn Ο n2 n 2 D. Ο & % ( C. Θ # ( D. Θ n ( ) Ω f ( n)
CSE 0 Test Your name as it appears on your UTA ID Card Fall 0 Multiple Choice:. Write the letter of your answer on the line ) to the LEFT of each problem.. CIRCLED ANSWERS DO NOT COUNT.. points each. The
More informationChapter 4. Greedy Algorithms. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.
Chapter 4 Greedy Algorithms Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. 1 4.5 Minimum Spanning Tree Minimum Spanning Tree Minimum spanning tree. Given a connected
More informationThomas H. Cormen Charles E. Leiserson Ronald L. Rivest. Introduction to Algorithms
Thomas H. Cormen Charles E. Leiserson Ronald L. Rivest Introduction to Algorithms Preface xiii 1 Introduction 1 1.1 Algorithms 1 1.2 Analyzing algorithms 6 1.3 Designing algorithms 1 1 1.4 Summary 1 6
More informationComputation Geometry Exercise Range Searching II
Computation Geometry Exercise Range Searching II LEHRSTUHL FÜR ALGORITHMIK I INSTITUT FÜR THEORETISCHE INFORMATIK FAKULTÄT FÜR INFORMATIK Guido Brückner 20.07.2018 1 Object types in range queries y0 y
More informationn 2 ( ) ( ) + n is in Θ n logn
CSE Test Spring Name Last Digits of Mav ID # Multiple Choice. Write your answer to the LEFT of each problem. points each. The time to multiply an m n matrix and a n p matrix is in: A. Θ( n) B. Θ( max(
More informationReview of course COMP-251B winter 2010
Review of course COMP-251B winter 2010 Lecture 1. Book Section 15.2 : Chained matrix product Matrix product is associative Computing all possible ways of parenthesizing Recursive solution Worst-case running-time
More informationECE250: Algorithms and Data Structures Final Review Course
ECE250: Algorithms and Data Structures Final Review Course Ladan Tahvildari, PEng, SMIEEE Professor Software Technologies Applied Research (STAR) Group Dept. of Elect. & Comp. Eng. University of Waterloo
More informationCSE 421 Greedy Alg: Union Find/Dijkstra s Alg
CSE 1 Greedy Alg: Union Find/Dijkstra s Alg Shayan Oveis Gharan 1 Dijkstra s Algorithm Dijkstra(G, c, s) { d s 0 foreach (v V) d[v] //This is the key of node v foreach (v V) insert v onto a priority queue
More informationCOMP 250 Midterm #2 March 11 th 2013
NAME: STUDENT ID: COMP 250 Midterm #2 March 11 th 2013 - This exam has 6 pages - This is an open book and open notes exam. No electronic equipment is allowed. 1) Questions with short answers (28 points;
More informationAlgorithms, Spring 2014, CSE, OSU Lecture 4: Binary search trees
6331 - Algorithms, Spring 2014, CSE, OSU Lecture 4: Binary search trees Instructor: Anastasios Sidiropoulos January 15, 2014 Binary search trees For every node x: x.k : key x.p : pointer to the parent
More informationChapter 9. Greedy Technique. Copyright 2007 Pearson Addison-Wesley. All rights reserved.
Chapter 9 Greedy Technique Copyright 2007 Pearson Addison-Wesley. All rights reserved. Greedy Technique Constructs a solution to an optimization problem piece by piece through a sequence of choices that
More informationmanaging an evolving set of connected components implementing a Union-Find data structure implementing Kruskal s algorithm
Spanning Trees 1 Spanning Trees the minimum spanning tree problem three greedy algorithms analysis of the algorithms 2 The Union-Find Data Structure managing an evolving set of connected components implementing
More informationn 2 C. Θ n ( ) Ο f ( n) B. n 2 Ω( n logn)
CSE 0 Name Test Fall 0 Last Digits of Mav ID # Multiple Choice. Write your answer to the LEFT of each problem. points each. The time to find the maximum of the n elements of an integer array is in: A.
More informationGeometric Data Structures
Geometric Data Structures 1 Data Structure 2 Definition: A data structure is a particular way of organizing and storing data in a computer for efficient search and retrieval, including associated algorithms
More informationRange searching. with Range Trees
Range searching Computational Geometry [csci 3250] Range searching with Range Trees Given a set of points, preprocess them into a data structure to support fast range queries. 2D Laura Toma Bowdoin College
More informationGraphs and Network Flows ISE 411. Lecture 7. Dr. Ted Ralphs
Graphs and Network Flows ISE 411 Lecture 7 Dr. Ted Ralphs ISE 411 Lecture 7 1 References for Today s Lecture Required reading Chapter 20 References AMO Chapter 13 CLRS Chapter 23 ISE 411 Lecture 7 2 Minimum
More informationWeek 12: Minimum Spanning trees and Shortest Paths
Agenda: Week 12: Minimum Spanning trees and Shortest Paths Kruskal s Algorithm Single-source shortest paths Dijkstra s algorithm for non-negatively weighted case Reading: Textbook : 61-7, 80-87, 9-601
More informationCSC 8301 Design & Analysis of Algorithms: Kruskal s and Dijkstra s Algorithms
CSC 8301 Design & Analysis of Algorithms: Kruskal s and Dijkstra s Algorithms Professor Henry Carter Fall 2016 Recap Greedy algorithms iterate locally optimal choices to construct a globally optimal solution
More informationProblem Pts Score Grader Problem Pts Score Grader
CSE 502 Fundamentals of Computer Science Spring Semester 2015 Homework 5 Assigned: 4/10/2015 Due Date: 4/21/2015 You must read and sign the following statement to get credit for this assignment: I have
More informationRepresentations of Weighted Graphs (as Matrices) Algorithms and Data Structures: Minimum Spanning Trees. Weighted Graphs
Representations of Weighted Graphs (as Matrices) A B Algorithms and Data Structures: Minimum Spanning Trees 9.0 F 1.0 6.0 5.0 6.0 G 5.0 I H 3.0 1.0 C 5.0 E 1.0 D 28th Oct, 1st & 4th Nov, 2011 ADS: lects
More informationComputational Geometry. Lecture 17
Computational Geometry Lecture 17 Computational geometry Algorithms for solving geometric problems in 2D and higher. Fundamental objects: Basic structures: point line segment line point set polygon L17.2
More informationLecture Summary CSC 263H. August 5, 2016
Lecture Summary CSC 263H August 5, 2016 This document is a very brief overview of what we did in each lecture, it is by no means a replacement for attending lecture or doing the readings. 1. Week 1 2.
More informationCSC 1700 Analysis of Algorithms: Heaps
CSC 1700 Analysis of Algorithms: Heaps Professor Henry Carter Fall 2016 Recap Transform-and-conquer preprocesses a problem to make it simpler/more familiar Three types: Instance simplification Representation
More informationProblem Set 6 Solutions
Introduction to Algorithms October 29, 2001 Massachusetts Institute of Technology 6.046J/18.410J Singapore-MIT Alliance SMA5503 Professors Erik Demaine, Lee Wee Sun, and Charles E. Leiserson Handout 24
More informationSolutions to Exam Data structures (X and NV)
Solutions to Exam Data structures X and NV 2005102. 1. a Insert the keys 9, 6, 2,, 97, 1 into a binary search tree BST. Draw the final tree. See Figure 1. b Add NIL nodes to the tree of 1a and color it
More informationAlgorithms and Data Structures
Algorithms and Data Structures Dr. Malek Mouhoub Department of Computer Science University of Regina Fall 2002 Malek Mouhoub, CS3620 Fall 2002 1 6. Priority Queues 6. Priority Queues ffl ADT Stack : LIFO.
More informationQuiz 1 Solutions. Asymptotic growth [10 points] For each pair of functions f(n) and g(n) given below:
Introduction to Algorithms October 15, 2008 Massachusetts Institute of Technology 6.006 Fall 2008 Professors Ronald L. Rivest and Sivan Toledo Quiz 1 Solutions Problem 1. Asymptotic growth [10 points]
More information4.1.2 Merge Sort Sorting Lower Bound Counting Sort Sorting in Practice Solving Problems by Sorting...
Contents 1 Introduction... 1 1.1 What is Competitive Programming?... 1 1.1.1 Programming Contests.... 2 1.1.2 Tips for Practicing.... 3 1.2 About This Book... 3 1.3 CSES Problem Set... 5 1.4 Other Resources...
More informationDifferent binary search trees can represent the same set of values (Fig.2). Vladimir Shelomovskii, Unitech, Papua New Guinea. Binary search tree.
1 Vladimir Shelomovskii, Unitech, Papua New Guinea, CS411 Binary search tree We can represent a binary search tree by a linked data structure in which each node is an object. Each node contains (Fig.1):
More informationCSE 431/531: Algorithm Analysis and Design (Spring 2018) Greedy Algorithms. Lecturer: Shi Li
CSE 431/531: Algorithm Analysis and Design (Spring 2018) Greedy Algorithms Lecturer: Shi Li Department of Computer Science and Engineering University at Buffalo Main Goal of Algorithm Design Design fast
More informationCSE 214 Computer Science II Heaps and Priority Queues
CSE 214 Computer Science II Heaps and Priority Queues Spring 2018 Stony Brook University Instructor: Shebuti Rayana shebuti.rayana@stonybrook.edu http://www3.cs.stonybrook.edu/~cse214/sec02/ Introduction
More informationBig Data Analytics. Special Topics for Computer Science CSE CSE April 14
Big Data Analytics Special Topics for Computer Science CSE 4095-001 CSE 5095-005 April 14 Fei Wang Associate Professor Department of Computer Science and Engineering fei_wang@uconn.edu Scalability I K-d
More informationChapter 4. Greedy Algorithms. Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved.
Chapter 4 Greedy Algorithms Slides by Kevin Wayne. Copyright 2005 Pearson-Addison Wesley. All rights reserved. 1 4.5 Minimum Spanning Tree Minimum Spanning Tree Minimum spanning tree. Given a connected
More informationMinimum Spanning Trees. Minimum Spanning Trees. Minimum Spanning Trees. Minimum Spanning Trees
Properties of Properties of Philip Bille 0 0 Graph G Not connected 0 0 Connected and cyclic Connected and acyclic = spanning tree Total weight = + + + + + + = Applications Network design. Computer, road,
More informationMinimum Spanning Trees
Minimum Spanning Trees Minimum Spanning Trees Representation of Weighted Graphs Properties of Minimum Spanning Trees Prim's Algorithm Kruskal's Algorithm Philip Bille Minimum Spanning Trees Minimum Spanning
More informationCS711008Z Algorithm Design and Analysis
CS711008Z Algorithm Design and Analysis Lecture 7. Binary heap, binomial heap, and Fibonacci heap Dongbo Bu Institute of Computing Technology Chinese Academy of Sciences, Beijing, China 1 / 108 Outline
More informationCOS 226 Algorithms and Data Structures Fall Midterm Solutions
1 COS 226 Algorithms and Data Structures Fall 2010 Midterm Solutions 1. Analysis of algorithms. (a) For each expression in the left column, give the best matching description from the right column. B.
More informationCS711008Z Algorithm Design and Analysis
CS700Z Algorithm Design and Analysis Lecture 7 Binary heap, binomial heap, and Fibonacci heap Dongbo Bu Institute of Computing Technology Chinese Academy of Sciences, Beijing, China 1 / Outline Introduction
More informationThe Algorithms of Prim and Dijkstra. Class 19
The Algorithms of Prim and Dijkstra Class 19 MST Introduction you live in a county that has terrible roads a new county commissioner was elected based on her campaign promise to repave the roads she promised
More informationCSE 548: Analysis of Algorithms. Lectures 14 & 15 ( Dijkstra s SSSP & Fibonacci Heaps )
CSE 548: Analysis of Algorithms Lectures 14 & 15 ( Dijkstra s SSSP & Fibonacci Heaps ) Rezaul A. Chowdhury Department of Computer Science SUNY Stony Brook Fall 2012 Fibonacci Heaps ( Fredman & Tarjan,
More informationComputer Science 302 Spring 2007 Practice Final Examination: Part I
Computer Science 302 Spring 2007 Practice Final Examination: Part I Name: This practice examination is much longer than the real final examination will be. If you can work all the problems here, you will
More information2 A Template for Minimum Spanning Tree Algorithms
CS, Lecture 5 Minimum Spanning Trees Scribe: Logan Short (05), William Chen (0), Mary Wootters (0) Date: May, 0 Introduction Today we will continue our discussion of greedy algorithms, specifically in
More information