Exam Questions Chapter 1

Total Page:16

File Type:pdf, Size:1020Kb

Exam Questions Chapter 1 Exam questions Mark Allen Weiss School of Computer Science Florida International University University Park Miami FL Abstract This rep ort contains a collection of multiplechoice questions organized by b o ok chapter that can b e used 1 a for examinations Answers are provided at the end This rep ort was typeset in L T X Original source is E available Chapter What is the approximate value of log a b c d e none of the ab ove If log n equals what is the value of log n a b c d e none of the ab ove When p erforming a pro of by induction which is the case that is trivially true a the basis b the inductive hypothesis c the lemma d the theorem e none of the ab ove 1 Many of these questions app ear in dierent form in the Instructors Resource Manual for Algorithms Data Structures and Problem Solving with C published by AddisonWesley The following routine violates which rules of recursion function Recurse N Integer return Integer is begin if N then return else return N Recurse N Recurse N end if end Recurse a No base case b Fails to make progress c Performs redundant work d Two of the ab ove e All of a b and c Which of the following is the most likely result of failing to make progress towards a base case in a recursive call a compiler enters into an innite lo op b error at compilation time c exception is raised at run time d recursive routine enters an innite lo op when it runs e recursive routine terminates with bad value but no other error Answers B A A D C Chapter Which of the following functions grows fastest a n log n n b c log n 2 d n 20 e n Which of the following functions grows fastest a n log n b n log n c n log n d n e There is a tie among two or more functions for fastest growth rate The next three questions apply to the fol lowing code fragment for i in N loop for j in i loop for k in ij loop Sum Sum end loop end loop end loop for p in NN loop for q in p loop Sum Sum end loop end loop How many times is statement executed a O N 2 b O N 3 c O N 4 d O N e none of the ab ove How many times is statement executed a O N 2 b O N 3 c O N 4 d O N e none of the ab ove What is the running time of the fragment 4 a O N 5 b O N 6 c O N 7 d O N e none of the ab ove Supp ose T n O F n and T n O F n Which of the following are true 1 2 a T n T n O F n 1 2 b T n T n O F n 1 2 c T nT n O 1 2 d T n O T n 1 2 e none of the ab ove Programs A and B are analyzed and found to have worstcase running times no greater than 2 n log n and n resp ectively Which of the following statements do es the analysis imply a Program A will run faster on average for suciently large n b Program B will run faster on average for small n c Program A is probably simpler to co de than program B d There exists some input for which program B takes longer than program A e none of the ab ove An algorithm takes seconds for an input size of If the algorithm is quadratic approx imately how long do es it take to solve a problem of size a seconds b seconds c seconds d seconds e none of the ab ove An algorithm takes seconds for an input of size If the algorithm is quadratic how large a problem can b e solved in two minutes a b c d e none of the ab ove An algorithm takes seconds to solve a problem of size and ten minutes to solve a problem of size What is the likely running time of the algorithm a constant b linear c quadratic d cubic e none of the ab ove Which of a to d is false ab out the binary search a the input array must b e sorted b successful searches take logarithmic time on average c unsuccessful searches take logarithmic time on average d the worst case for any search is logarithmic e all of the ab ove are true Which of the following can b e done in O log n arithmetic op erations a Raising a number to the nth p ower b Computing the greatest common divisor of some integer and n c Adding two ndigit numbers d Two of the ab ove e All of a b and c A recursive algorithm works by solving two halfsized problems recursively with an additional lineartime overhead The total running time is most accurately given by a O log n b O n c O n log n 2 d O n e none of the ab ove The solution to T n T bnc with T is most accurately given by a O log n b O n c O n log n 2 d O n e none of the ab ove Approximately how many random numbers are using in the p ermutation generation algorithm in Exercise c a b log n c n d n log n e none of the ab ove What is the running time of the following routine Check if N is prime function IsPrime N Integer return Boolean is I Integer begin if N or else N then return TRUE end if if N MOD then return FALSE end if while i i N loop if N MOD i then return FALSE else I I end if end loop return TRUE end IsPrime a constant time b O log N c O N p d O N e none of the ab ove Answers B B C D A A E C A C E D C A C D Chapter Which of the following op erations is not eciently supp orted by a singlylinked list a accessing the element in the current p osition b insertion after the current p osition c insertion b efore the current p osition d moving to the p osition immediately following the current p osition e all of the ab ove are eciently supp orted Which statement placed in the list package implementation inserts an item X after p osition Current a Current new Node X Current b Current new Node X CurrentNext c CurrentNext new Node X Current d CurrentNext new Node X CurrentNext e none of the ab ove The header no de of a linked list a simplies deletion b simplies insertion c uses only constant extra space d two of the ab ove e all three of a b and c If a header no de is used which of the following indicates a list L with one item a LHeaderNext null b LHeaderNext null c LHeaderNext null and then LHeaderNextNext null d LHeaderNext null and then LHeaderNextNext null e none of the ab ove Insertion of a no de into a doubly linked list requires how many changes to various Next and Prev p ointers a no changes b Next Prev c Next Prev d Next Prev e none of the ab ove What op eration is supp orted in constant time by the doubly linked list but not by the singly linked list a Advance b Backup c First d Retrieve e all of the ab ove are always constant time The UNIX editor vi allows searching in b oth directions with wraparound if necessary If the sequence of lines is stored as a linked list which of the following is most reasonable a singly linked list b doubly linked list c circular singly linked list d circular doubly linked list e none of the ab ove What happ ens when wraparound is implemented for a queue a If Front advances past the last array p osition it is reset to the rst array p osition b If Rear advances past the last array p osition it is reset to the rst array p osition c Both a and b d Neither a nor b Using the text implementation if Front and Rear have identical values what is the size of the queue a b c d the answer cannot b e determined e none of the ab ove For the linked list implementation of the stack where are the pushes and p ops p erformed a Push in front of the rst element p op the rst element b Push after the last element p op the last element c Push after the last element p op the rst element d Push in front of the rst element p op the last element e Push after the rst element p op the rst element For the linked list implementation of the queue where are the enqueue and dequeues p er formed a Enqueue in front of the rst element dequeue the rst element b Enqueue after the last element dequeue the last element c Enqueue after the last element dequeue the rst element d Enqueue in front of the rst element dequeue the last element e Enqueue after the rst element dequeue the rst element For the linked list implementation if the stack is not empty which of the following statements in a main pro cedure can b e used to access the top element in the stack S a SElement b STopOfStack c STopOfStackElement d TopOfStackElement e none of the ab ove Answers C D E D C B D C B A C E Chapter Which of the following traversals requires more than linear time in the worst case a inorder b level order c p ostorder d preorder e all of these traversals are linear time In which of the following traversals is the no de pro cessed b efore the recursive calls to the children complete a inorder b level order c p ostorder d preorder e none of the ab ove What is the maximum number of no des in a binary tree with L leaves a L L b L+1 c d there is no maximum e none of the ab ove Which of the following is true ab out the height of a no de a The height of a no de is one less than the height of its parent b The height of an empty tree is c The height of a leaf is d The height of a tree can b e larger than its depth e all of the ab ove are false The rst child next sibling implementation a allows easy access to the parent b is appropriate for binary trees c uses C p ointers p er no de where C is the number of children d all of the ab ove e none of a b and c Which traversal computes the total size of each directory in the UNIX le system a inorder b level order c p ostorder d preorder e two or more of the ab ove traversals could b e used Let CX b e the number of leaves in a binary tree ro oted at T Assume that IsLeafT returns if T is a leaf Which of the following observations leads to a recursive implementation a CTCTLeftCTRight b CTCTLeftCTRight c CTCTLeftCTRightIsLeafT d CTCTLeftCTRightIsLeafT e none of the ab ove Which traversal do es not use a stack a inorder b level order c p ostorder d preorder
Recommended publications
  • Data Structures and Algorithms Binary Heaps (S&W 2.4)
    Data structures and algorithms DAT038/TDA417, LP2 2019 Lecture 12, 2019-12-02 Binary heaps (S&W 2.4) Some slides by Sedgewick & Wayne Collections A collection is a data type that stores groups of items. stack Push, Pop linked list, resizing array queue Enqueue, Dequeue linked list, resizing array symbol table Put, Get, Delete BST, hash table, trie, TST set Add, ontains, Delete BST, hash table, trie, TST A priority queue is another kind of collection. “ Show me your code and conceal your data structures, and I shall continue to be mystified. Show me your data structures, and I won't usually need your code; it'll be obvious.” — Fred Brooks 2 Priority queues Collections. Can add and remove items. Stack. Add item; remove the item most recently added. Queue. Add item; remove the item least recently added. Min priority queue. Add item; remove the smallest item. Max priority queue. Add item; remove the largest item. return contents contents operation argument value size (unordered) (ordered) insert P 1 P P insert Q 2 P Q P Q insert E 3 P Q E E P Q remove max Q 2 P E E P insert X 3 P E X E P X insert A 4 P E X A A E P X insert M 5 P E X A M A E M P X remove max X 4 P E M A A E M P insert P 5 P E M A P A E M P P insert L 6 P E M A P L A E L M P P insert E 7 P E M A P L E A E E L M P P remove max P 6 E M A P L E A E E L M P A sequence of operations on a priority queue 3 Priority queue API Requirement.
    [Show full text]
  • Lecture 04 Linear Structures Sort
    Algorithmics (6EAP) MTAT.03.238 Linear structures, sorting, searching, etc Jaak Vilo 2018 Fall Jaak Vilo 1 Big-Oh notation classes Class Informal Intuition Analogy f(n) ∈ ο ( g(n) ) f is dominated by g Strictly below < f(n) ∈ O( g(n) ) Bounded from above Upper bound ≤ f(n) ∈ Θ( g(n) ) Bounded from “equal to” = above and below f(n) ∈ Ω( g(n) ) Bounded from below Lower bound ≥ f(n) ∈ ω( g(n) ) f dominates g Strictly above > Conclusions • Algorithm complexity deals with the behavior in the long-term – worst case -- typical – average case -- quite hard – best case -- bogus, cheating • In practice, long-term sometimes not necessary – E.g. for sorting 20 elements, you dont need fancy algorithms… Linear, sequential, ordered, list … Memory, disk, tape etc – is an ordered sequentially addressed media. Physical ordered list ~ array • Memory /address/ – Garbage collection • Files (character/byte list/lines in text file,…) • Disk – Disk fragmentation Linear data structures: Arrays • Array • Hashed array tree • Bidirectional map • Heightmap • Bit array • Lookup table • Bit field • Matrix • Bitboard • Parallel array • Bitmap • Sorted array • Circular buffer • Sparse array • Control table • Sparse matrix • Image • Iliffe vector • Dynamic array • Variable-length array • Gap buffer Linear data structures: Lists • Doubly linked list • Array list • Xor linked list • Linked list • Zipper • Self-organizing list • Doubly connected edge • Skip list list • Unrolled linked list • Difference list • VList Lists: Array 0 1 size MAX_SIZE-1 3 6 7 5 2 L = int[MAX_SIZE]
    [Show full text]
  • Game Trees, Quad Trees and Heaps
    CS 61B Game Trees, Quad Trees and Heaps Fall 2014 1 Heaps of fun R (a) Assume that we have a binary min-heap (smallest value on top) data structue called Heap that stores integers and has properly implemented insert and removeMin methods. Draw the heap and its corresponding array representation after each of the operations below: Heap h = new Heap(5); //Creates a min-heap with 5 as the root 5 5 h.insert(7); 5,7 5 / 7 h.insert(3); 3,7,5 3 /\ 7 5 h.insert(1); 1,3,5,7 1 /\ 3 5 / 7 h.insert(2); 1,2,5,7,3 1 /\ 2 5 /\ 7 3 h.removeMin(); 2,3,5,7 2 /\ 3 5 / 7 CS 61B, Fall 2014, Game Trees, Quad Trees and Heaps 1 h.removeMin(); 3,7,5 3 /\ 7 5 (b) Consider an array based min-heap with N elements. What is the worst case running time of each of the following operations if we ignore resizing? What is the worst case running time if we take into account resizing? What are the advantages of using an array based heap vs. using a BST-based heap? Insert O(log N) Find Min O(1) Remove Min O(log N) Accounting for resizing: Insert O(N) Find Min O(1) Remove Min O(N) Using a BST is not space-efficient. (c) Your friend Alyssa P. Hacker challenges you to quickly implement a max-heap data structure - "Hah! I’ll just use my min-heap implementation as a template", you think to yourself.
    [Show full text]
  • Heaps a Heap Is a Complete Binary Tree. a Max-Heap Is A
    Heaps Heaps 1 A heap is a complete binary tree. A max-heap is a complete binary tree in which the value in each internal node is greater than or equal to the values in the children of that node. A min-heap is defined similarly. 97 Mapping the elements of 93 84 a heap into an array is trivial: if a node is stored at 90 79 83 81 index k, then its left child is stored at index 42 55 73 21 83 2k+1 and its right child at index 2k+2 01234567891011 97 93 84 90 79 83 81 42 55 73 21 83 CS@VT Data Structures & Algorithms ©2000-2009 McQuain Building a Heap Heaps 2 The fact that a heap is a complete binary tree allows it to be efficiently represented using a simple array. Given an array of N values, a heap containing those values can be built, in situ, by simply “sifting” each internal node down to its proper location: - start with the last 73 73 internal node * - swap the current 74 81 74 * 93 internal node with its larger child, if 79 90 93 79 90 81 necessary - then follow the swapped node down 73 * 93 - continue until all * internal nodes are 90 93 90 73 done 79 74 81 79 74 81 CS@VT Data Structures & Algorithms ©2000-2009 McQuain Heap Class Interface Heaps 3 We will consider a somewhat minimal maxheap class: public class BinaryHeap<T extends Comparable<? super T>> { private static final int DEFCAP = 10; // default array size private int size; // # elems in array private T [] elems; // array of elems public BinaryHeap() { .
    [Show full text]
  • Priority Queues and Binary Heaps Chapter 6.5
    Priority Queues and Binary Heaps Chapter 6.5 1 Some animals are more equal than others • A queue is a FIFO data structure • the first element in is the first element out • which of course means the last one in is the last one out • But sometimes we want to sort of have a queue but we want to order items according to some characteristic the item has. 107 - Trees 2 Priorities • We call the ordering characteristic the priority. • When we pull something from this “queue” we always get the element with the best priority (sometimes best means lowest). • It is really common in Operating Systems to use priority to schedule when something happens. e.g. • the most important process should run before a process which isn’t so important • data off disk should be retrieved for more important processes first 107 - Trees 3 Priority Queue • A priority queue always produces the element with the best priority when queried. • You can do this in many ways • keep the list sorted • or search the list for the minimum value (if like the textbook - and Unix actually - you take the smallest value to be the best) • You should be able to estimate the Big O values for implementations like this. e.g. O(n) for choosing the minimum value of an unsorted list. • There is a clever data structure which allows all operations on a priority queue to be done in O(log n). 107 - Trees 4 Binary Heap Actually binary min heap • Shape property - a complete binary tree - all levels except the last full.
    [Show full text]
  • Advanced Data Structures
    Advanced Data Structures PETER BRASS City College of New York CAMBRIDGE UNIVERSITY PRESS Cambridge, New York, Melbourne, Madrid, Cape Town, Singapore, São Paulo Cambridge University Press The Edinburgh Building, Cambridge CB2 8RU, UK Published in the United States of America by Cambridge University Press, New York www.cambridge.org Information on this title: www.cambridge.org/9780521880374 © Peter Brass 2008 This publication is in copyright. Subject to statutory exception and to the provision of relevant collective licensing agreements, no reproduction of any part may take place without the written permission of Cambridge University Press. First published in print format 2008 ISBN-13 978-0-511-43685-7 eBook (EBL) ISBN-13 978-0-521-88037-4 hardback Cambridge University Press has no responsibility for the persistence or accuracy of urls for external or third-party internet websites referred to in this publication, and does not guarantee that any content on such websites is, or will remain, accurate or appropriate. Contents Preface page xi 1 Elementary Structures 1 1.1 Stack 1 1.2 Queue 8 1.3 Double-Ended Queue 16 1.4 Dynamical Allocation of Nodes 16 1.5 Shadow Copies of Array-Based Structures 18 2 Search Trees 23 2.1 Two Models of Search Trees 23 2.2 General Properties and Transformations 26 2.3 Height of a Search Tree 29 2.4 Basic Find, Insert, and Delete 31 2.5ReturningfromLeaftoRoot35 2.6 Dealing with Nonunique Keys 37 2.7 Queries for the Keys in an Interval 38 2.8 Building Optimal Search Trees 40 2.9 Converting Trees into Lists 47 2.10
    [Show full text]
  • L11: Quadtrees CSE373, Winter 2020
    L11: Quadtrees CSE373, Winter 2020 Quadtrees CSE 373 Winter 2020 Instructor: Hannah C. Tang Teaching Assistants: Aaron Johnston Ethan Knutson Nathan Lipiarski Amanda Park Farrell Fileas Sam Long Anish Velagapudi Howard Xiao Yifan Bai Brian Chan Jade Watkins Yuma Tou Elena Spasova Lea Quan L11: Quadtrees CSE373, Winter 2020 Announcements ❖ Homework 4: Heap is released and due Wednesday ▪ Hint: you will need an additional data structure to improve the runtime for changePriority(). It does not affect the correctness of your PQ at all. Please use a built-in Java collection instead of implementing your own. ▪ Hint: If you implemented a unittest that tested the exact thing the autograder described, you could run the autograder’s test in the debugger (and also not have to use your tokens). ❖ Please look at posted QuickCheck; we had a few corrections! 2 L11: Quadtrees CSE373, Winter 2020 Lecture Outline ❖ Heaps, cont.: Floyd’s buildHeap ❖ Review: Set/Map data structures and logarithmic runtimes ❖ Multi-dimensional Data ❖ Uniform and Recursive Partitioning ❖ Quadtrees 3 L11: Quadtrees CSE373, Winter 2020 Other Priority Queue Operations ❖ The two “primary” PQ operations are: ▪ removeMax() ▪ add() ❖ However, because PQs are used in so many algorithms there are three common-but-nonstandard operations: ▪ merge(): merge two PQs into a single PQ ▪ buildHeap(): reorder the elements of an array so that its contents can be interpreted as a valid binary heap ▪ changePriority(): change the priority of an item already in the heap 4 L11: Quadtrees CSE373,
    [Show full text]
  • CS210-Data Structures-Module-29-Binary-Heap-II
    Data Structures and Algorithms (CS210A) Lecture 29: • Building a Binary heap on 풏 elements in O(풏) time. • Applications of Binary heap : sorting • Binary trees: beyond searching and sorting 1 Recap from the last lecture 2 A complete binary tree How many leaves are there in a Complete Binary tree of size 풏 ? 풏/ퟐ 3 Building a Binary heap Problem: Given 풏 elements {푥0, …, 푥푛−1}, build a binary heap H storing them. Trivial solution: (Building the Binary heap incrementally) CreateHeap(H); For( 풊 = 0 to 풏 − ퟏ ) What is the time Insert(푥,H); complexity of this algorithm? 4 Building a Binary heap incrementally What useful inference can you draw from Top-down this Theorem ? approach The time complexity for inserting a leaf node = ?O (log 풏 ) # leaf nodes = 풏/ퟐ , Theorem: Time complexity of building a binary heap incrementally is O(풏 log 풏). 5 Building a Binary heap incrementally What useful inference can you draw from Top-down this Theorem ? approach The O(풏) time algorithm must take O(1) time for each of the 풏/ퟐ leaves. 6 Building a Binary heap incrementally Top-down approach 7 Think of alternate approach for building a binary heap In any complete 98 binaryDoes treeit suggest, how a manynew nodes approach satisfy to heapbuild propertybinary heap ? ? 14 33 all leaf 37 11 52 32 nodes 41 21 76 85 17 25 88 29 Bottom-up approach 47 75 9 57 23 heap property: “Every ? node stores value smaller than its children” We just need to ensure this property at each node.
    [Show full text]
  • CS 270 Algorithms
    CS 270 Algorithms Week 10 Oliver Kullmann Binary heaps Sorting Heapification Building a heap 1 Binary heaps HEAP- SORT Priority 2 Heapification queues QUICK- 3 Building a heap SORT Analysing 4 QUICK- HEAP-SORT SORT 5 Priority queues Tutorial 6 QUICK-SORT 7 Analysing QUICK-SORT 8 Tutorial CS 270 General remarks Algorithms Oliver Kullmann Binary heaps Heapification Building a heap We return to sorting, considering HEAP-SORT and HEAP- QUICK-SORT. SORT Priority queues CLRS Reading from for week 7 QUICK- SORT 1 Chapter 6, Sections 6.1 - 6.5. Analysing 2 QUICK- Chapter 7, Sections 7.1, 7.2. SORT Tutorial CS 270 Discover the properties of binary heaps Algorithms Oliver Running example Kullmann Binary heaps Heapification Building a heap HEAP- SORT Priority queues QUICK- SORT Analysing QUICK- SORT Tutorial CS 270 First property: level-completeness Algorithms Oliver Kullmann Binary heaps In week 7 we have seen binary trees: Heapification Building a 1 We said they should be as “balanced” as possible. heap 2 Perfect are the perfect binary trees. HEAP- SORT 3 Now close to perfect come the level-complete binary Priority trees: queues QUICK- 1 We can partition the nodes of a (binary) tree T into levels, SORT according to their distance from the root. Analysing 2 We have levels 0, 1,..., ht(T ). QUICK- k SORT 3 Level k has from 1 to 2 nodes. Tutorial 4 If all levels k except possibly of level ht(T ) are full (have precisely 2k nodes in them), then we call the tree level-complete. CS 270 Examples Algorithms Oliver The binary tree Kullmann 1 ❚ Binary heaps ❥❥❥❥ ❚❚❚❚ ❥❥❥❥ ❚❚❚❚ ❥❥❥❥ ❚❚❚❚ Heapification 2 ❥ 3 ❖ ❄❄ ❖❖ Building a ⑧⑧ ❄ ⑧⑧ ❖❖ heap ⑧⑧ ❄ ⑧⑧ ❖❖❖ 4 5 6 ❄ 7 ❄ HEAP- ⑧ ❄ ⑧ ❄ SORT ⑧⑧ ❄ ⑧⑧ ❄ Priority 10 13 14 15 queues QUICK- is level-complete (level-sizes are 1, 2, 4, 4), while SORT ❥ 1 ❚❚ Analysing ❥❥❥❥ ❚❚❚❚ QUICK- ❥❥❥ ❚❚❚ SORT ❥❥❥ ❚❚❚❚ 2 ❥❥ 3 ♦♦♦ ❄❄ ⑧ Tutorial ♦♦ ❄❄ ⑧⑧ ♦♦♦ ⑧ 4 ❄ 5 ❄ 6 ❄ ⑧⑧ ❄❄ ⑧ ❄ ⑧ ❄ ⑧⑧ ❄ ⑧⑧ ❄ ⑧⑧ ❄ 8 9 10 11 12 13 is not (level-sizes are 1, 2, 3, 6).
    [Show full text]
  • AVL Tree, Bayer Tree, Heap Summary of the Previous Lecture
    DATA STRUCTURES AND ALGORITHMS Hierarchical data structures: AVL tree, Bayer tree, Heap Summary of the previous lecture • TREE is hierarchical (non linear) data structure • Binary trees • Definitions • Full tree, complete tree • Enumeration ( preorder, inorder, postorder ) • Binary search tree (BST) AVL tree The AVL tree (named for its inventors Adelson-Velskii and Landis published in their paper "An algorithm for the organization of information“ in 1962) should be viewed as a BST with the following additional property: - For every node, the heights of its left and right subtrees differ by at most 1. Difference of the subtrees height is named balanced factor. A node with balance factor 1, 0, or -1 is considered balanced. As long as the tree maintains this property, if the tree contains n nodes, then it has a depth of at most log2n. As a result, search for any node will cost log2n, and if the updates can be done in time proportional to the depth of the node inserted or deleted, then updates will also cost log2n, even in the worst case. AVL tree AVL tree Not AVL tree Realization of AVL tree element struct AVLnode { int data; AVLnode* left; AVLnode* right; int factor; // balance factor } Adding a new node Insert operation violates the AVL tree balance property. Prior to the insert operation, all nodes of the tree are balanced (i.e., the depths of the left and right subtrees for every node differ by at most one). After inserting the node with value 5, the nodes with values 7 and 24 are no longer balanced.
    [Show full text]
  • Leftist Heap: Is a Binary Tree with the Normal Heap Ordering Property, but the Tree Is Not Balanced. in Fact It Attempts to Be Very Unbalanced!
    Leftist heap: is a binary tree with the normal heap ordering property, but the tree is not balanced. In fact it attempts to be very unbalanced! Definition: the null path length npl(x) of node x is the length of the shortest path from x to a node without two children. The null path lengh of any node is 1 more than the minimum of the null path lengths of its children. (let npl(nil)=-1). Only the tree on the left is leftist. Null path lengths are shown in the nodes. Definition: the leftist heap property is that for every node x in the heap, the null path length of the left child is at least as large as that of the right child. This property biases the tree to get deep towards the left. It may generate very unbalanced trees, which facilitates merging! It also also means that the right path down a leftist heap is as short as any path in the heap. In fact, the right path in a leftist tree of N nodes contains at most lg(N+1) nodes. We perform all the work on this right path, which is guaranteed to be short. Merging on a leftist heap. (Notice that an insert can be considered as a merge of a one-node heap with a larger heap.) 1. (Magically and recursively) merge the heap with the larger root (6) with the right subheap (rooted at 8) of the heap with the smaller root, creating a leftist heap. Make this new heap the right child of the root (3) of h1.
    [Show full text]
  • Kd Trees What's the Goal for This Course? Data St
    Today’s Outline - kd trees CSE 326: Data Structures Too much light often blinds gentlemen of this sort, Seeing the forest for the trees They cannot see the forest for the trees. - Christoph Martin Wieland Hannah Tang and Brian Tjaden Summer Quarter 2002 What’s the goal for this course? Data Structures - what’s in a name? Shakespeare It is not possible for one to teach others, until one can first teach herself - Confucious • Stacks and Queues • Asymptotic analysis • Priority Queues • Sorting – Binary heap, Leftist heap, Skew heap, d - heap – Comparison based sorting, lower- • Trees bound on sorting, radix sorting – Binary search tree, AVL tree, Splay tree, B tree • World Wide Web • Hash Tables – Open and closed hashing, extendible, perfect, • Implement if you had to and universal hashing • Understand trade-offs between • Disjoint Sets various data structures/algorithms • Graphs • Know when to use and when not to – Topological sort, shortest path algorithms, Dijkstra’s algorithm, minimum spanning trees use (Prim’s algorithm and Kruskal’s algorithm) • Real world applications Range Query Range Query Example Y A range query is a search in a dictionary in which the exact key may not be entirely specified. Bellingham Seattle Spokane Range queries are the primary interface Tacoma Olympia with multi-D data structures. Pullman Yakima Walla Walla Remember Assignment #2? Give an algorithm that takes a binary search tree as input along with 2 keys, x and y, with xÃÃy, and ÃÃ ÃÃ prints all keys z in the tree such that x z y. X 1 Range Querying in 1-D
    [Show full text]