7 Pages

chap7

Course: CPS 100, Fall 2009
School: Duke
Rating:
 
 
 
 
 

Word Count: 545

Document Preview

Search Balanced Trees Binary search trees keep keys ordered, with efficient lookup Insert, Delete, Find, all are O(log n) in average case Worst case is bad Compared to hashing? Advantages? Balanced trees are guaranteed O(log n) in the worst case Fundamental operation is a rotation: keep tree roughly balanced AVL tree was the first one, still studied since simple conceptually Red-Black tree uses rotations,...

Register Now

Unformatted Document Excerpt

Coursehero >> North Carolina >> Duke >> CPS 100

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.
Search Balanced Trees Binary search trees keep keys ordered, with efficient lookup Insert, Delete, Find, all are O(log n) in average case Worst case is bad Compared to hashing? Advantages? Balanced trees are guaranteed O(log n) in the worst case Fundamental operation is a rotation: keep tree roughly balanced AVL tree was the first one, still studied since simple conceptually Red-Black tree uses rotations, harder to code, better in practice B-trees are used when data is stored on disk rather than in memory Splay trees rebalance sometimes, amortized good performance, simple (relatively) to implement 9.1 CPS 100 Rotations and balanced trees Height-balanced trees For every node, left and right subtree heights differ by at most 1 After insertion/deletion need to rebalance Every operation leaves tree in a balanced state: invariant property of tree Find deepest node thats unbalanced On path from root to inserted/deleted node Rebalance at this unbalanced point only Are these trees heightbalanced? CPS 100 9.2 Tree Balancing example Tree with AVL property What happens if we insert a node with a value of 1? 12 8 4 2 6 10 14 16 Need to rotate tree to maintain AVL property 12 4 2 1 6 8 10 14 16 Which nodes in the tree are unbalanced? What would have happened if we inserted a node with a value of 5? What are the four ways an insertion can unbalance a tree? 9.3 CPS 100 Rotation to rebalance N N C A B A B C When a node N is unbalanced height differs by 2 (must be more than one) Change N->left->left doLeft Change N->left->right doLeftRight Change N->right->left Tree * doLeft(Tree * root) doRightLeft { Tree * newRoot = root->left; Change N->right->right root->left newRoot->right; = doRight newRoot->right = root; First/last cases are symmetric return newRoot; Middle cases require two rotations } First of the two puts tree into doLeft or doRight CPS 100 9.4 Rotation to rebalance N ????? N C A B A B C Suppose we add a new node in right subtree of left child of root Single rotation cant fix Need to rotate twice First stage is shown at bottom Rotate blue node right This is left child of unbalanced C A B1 B2 A B1 B2 Tree * doRight(Tree * root) { Tree * newRoot = root->right; root->right = newRoot->left; newRoot->left = root; return newRoot; } 9.5 CPS 100 Double rotation complete Calculate where to rotate and what case, do the rotations Tree * doRight(Tree * root) { Tree * newRoot = root->right; root->right = newRoot->left; newRoot->left = root; return newRoot; } Tree * doLeft(Tree * root) { Tree * newRoot = root->left; root->left = newRoot->right; newRoot->right = root; return newRoot; } C A B1 B2 A B1 B2 C B1 A B2 C CPS 100...

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:

Duke - CPS - 150
cps150, Fall 2001homework-5Due Date: 1. Written Part Due on 11/02, Friday, in class. 2. Programming Part Due on 11/02, Friday, midnight. (Be aware that every problem involve implementation in Matlab). Part I: Sensitivity to perturbation We consid
Duke - CPS - 230
11AWw5f11IwXW1 ~1Y11A1A~wXw1 X11~kA1k`w17XwWA11`Xww05!1! X YXF Qc4baIVP HX E~w141I` XyefYXWAXw1 3V1UTTT5Q43HGw1W5#F1w1! ` # F FRSSSRP I F D
Duke - CPS - 216
Eddies: Continuously Adaptive Query Processingby Ron Avnur and Joseph M. HellersteinIntroductionLarge-scale query engines (WANs, clusters) must be able to perform robustly under changing conditions Telegraph is a system being developed to provide
Duke - CPS - 216
CPS 216 Fall 2001 Course Project Important Dates Milestone 1: Thursday, October 18 Milestone 2: Thursday, November 15 Project Demo and Presentation Period: December 3-7, 10-12 Final Project Report Due: Thursday, December 13 You can choose either one
Duke - CPS - 100
Balanced Search TreesqqBinary search trees keep keys ordered, with efficient lookup Insert, Delete, Find, all are O(log n) in average case Worst case is bad Compared to hashing? Advantages? Balanced trees are guaranteed O(log n) in the worst
Duke - CPS - 100
Efficient ProgrammingqSee readwords.cppqDesigning and building efficient programs efficiently requires knowledge and practice Hopefully the programming language helps, it's not intended to get in the way Object-oriented concepts, and more gen
Duke - CPS - 100
Sorting: From Theory to PracticeqWhy do we study sorting? Because we have to Because sorting is beautiful Because and There are n sorting algorithms, how many should we study? O(n), O(log n), Why do we study more than one algorithm? q
Duke - CPS - 100
Graphs: Structures and AlgorithmsHow do packets of bits/information get routed on the internet Message divided into packets on client (your) machine Packets sent out using routing tables toward destination Packets may take different routes to des
Duke - CPS - 100
CPS 100E - Program Design and Analysis I Prof. Rodger Section: Templates, Stacks, Queues handout Read W3, W6.1-6.3, W15, W11Overloading FunctionsFunctions can have the same name if they have di erent arguments. This is called overloading. When the
Duke - CPS - 100
CPS 100E - Program Design and Analysis I Prof. Rodger Section: Vectors in classes, Pointers handout Read A8.4, A12.1-12.3, W1 A class declaration does not create any memory. When variables of that type of class are de ned using the constructor then m
Duke - CPS - 100
CPS 100E - Program Design and Analysis I Prof. Rodger Section: Balanced Trees and Hu man Coding handout Read Chap 12.1Balanced TreesAVL Trees 2-3 trees, B-trees Red-Black TreeRed-Black TreeBinary search tree properties every node is red or blac
BYU - CATALOG - 0406
Programs of Study and Course DescriptionsFollowing is a list of undergraduate courses and programs for Stern College for Women and Sy Syms School of Business. Unless otherwise noted, courses meet for the same number of hours per week as the credit v
Duke - CPS - 100
From bits to bytes to intsHow are data stored?At some level everything is stored as either a zero or a one A bit is a binary digit a byte is a binary term (8 bits) We should be grateful we can deal with Strings rather than sequences of 0's
Duke - CPS - 100
Intro to GraphsDefinitions and VocabularyA graph consists of a set of vertices (or nodes) and a set of edges (or arcs) where each edge connects a pair of vertices. If the pair of vertices defining an edge is ordered, then it is a directed graph.
Duke - CPS - 100
Binary TreesLinked lists: efficient insertion/deletion, inefficient search ArrayList: search can be efficient, insertion/deletion not Binary trees: efficient insertion, deletion, and search trees used in many contexts, not just for searching, e.g.
Duke - CPS - 100
Graphical User Interfaces (GUIs) Components Flat Layouts Hierarchical Layouts Designing a GUI Coding a GUI(These notes come from CompSci 4, Java for Video Games)CompSci 100E30.1Components JLabel text/image display JTextField sin
Duke - CPS - 100
Inheritance and Interfaces Single inheritance in JavaInheritance models an "is-a" relationshipA class can extend only one class in Java A dog is a mammal, an ArrayList is a List, a square is a shape, Write general programs to understand
Duke - CPS - 100
Java 5 New Features Generics Generics Enhanced for loop Autoboxing/unboxing Typesafe enums Other Allows classes to store objects whose type is irrelevant to storing class, while allowing type-safe retrieval E.g., Collection SyntaxArr
Duke - CPS - 100
Binary TreesFrom doubly-linked lists to binary treesLinked lists: efficient insertion/deletion, inefficient search ArrayList: search can be efficient, insertion/deletion not Binary trees: efficient insertion, deletion, and search trees used i
Duke - CPS - 100
Balanced Binary Search TreesBalanced Binary Search TreesPathological BST Keeping BSTrees Balanced Insert nodes from ordered list Search: O(_) ? Binary Tree is balanced if height of left and right subtree differ by no more than one, recurs
BYU - CATALOG - 0204
Sy Syms School of Businessy Syms School of Business offers business programs for undergraduate men and women. It was established in 1987 through major gifts by Sy Syms, a member of the Universitys Board of Trustees, and other business leaders. The S
BYU - CATALOG - 0204
Irving I.Stone Beit Midrash ProgramEstablished in 1995, the Irving I. Stone Beit Midrash Program offers undergraduate men a structured Jewish studies program designed for students with special scheduling needs and interests. It maintains a high l
Duke - CPS - 100
Data and InformationOrganizing Data: ideas and issues!How and why do we organize data? Differences between data and information? What about knowledge?!Often there is a time/space tradeoff ! If we use more space (memory) we can solve a data/ i
Duke - CPS - 100
Loop Invariants!Bean Can game! !!Want to reason about the correctness of a proposed iterative solution Loop invariants provide a means to effectively about the correctness of codeCan contains N black beans and M white beans initially Emptie
Duke - CPS - 108
LibrariesqIn C+ it's possible to create static libraries and shared libraries Static libraries (end in .a) are combined/linked into an executable Executables are large. If library is updated in a binary compatible way, programs still need to be
Duke - CPS - 108
Overloading operatorsqWhy overload operators? (=, =, <, >, +=, ) notational convenience match user expectations because we can (except : and . and .*) Remember, overloaded operators are just function calls operands are parameters, thus subject
Duke - CPS - 108
Software DesignSee Alan Cooper, The Essentials of User Interface Design q who designs the software?Implentation modelworsebetterusers modelqqImplementation is view of software developer, users view is mental model, software designer ha
Duke - CPS - 100
Backtracking, Search, HeuristicsqClassic problem: N queensqMany problems require an approach similar to solving a maze Certain mazes can be solved using the "right-hand" rule Other mazes, e.g., with islands, require another approach If you h
Duke - CPS - 100
Heaps, Priority Queues, CompressionqPriority QueueqCompression is a high-profile application .zip, .mp3, .jpg, .gif, .gz, Why is compression important? Whats the difference between compression for .mp3 files and compression for .zip files?
Duke - CPS - 100
cps 100 "Green I do not Lack" as sung to the tune of Sir-mix alot's " Baby's got back" Intro-oh my god, Joey look at this apt it is so big uhh it looks like one of those big time programs but u know who understands those programs they only work becau
Duke - CPS - 140
CPS 140Project 3 Project Due: Saturday, April 24, 8am 50 pointsSpring 1999No LATE projects accepted after Thursday, April 29, 8am.The purpose of this assignment is to write an interpretor for the LSYS programming language see the project 1 and
Duke - CPS - 140
Section: Turing Machines Review Regular Languages FA, RG, RE recognize Context Free Languages PDA, CFG recognize1DFA:input tape a tape head current state 0 5 4 3 1 2 b b a bhead moves2Turing Machine:input tape a tape head current state
Duke - CPS - 140
CPS 140 - Mathematical Foundations of CS Dr. S. Rodger Section: The Structure of a Compiler 1.1 What is a Compiler? I. Translator Definition: program in language X - translator for X - program in language YExamples: Source Language High Level Assem
Duke - CPS - 140
CPS 140 - Mathematical Foundations of CS Dr. S. Rodger Section: Transforming Grammars Ch. 6 handoutMethods for Transforming Grammars Read Ch 6 in Linz BookWe will consider CFL without . It would be easy to add to any grammar by adding a new start
Duke - CPS - 140
Section: Turing Machines - Building Blocks 1. Given Turing Machines M1 and M2 Notation for Run M1 Run M2M1 M2SHSHM1M2SHz;z,Rz;z,LSHz represents any symbol in12. Given Turing Machines M1 and M2M1 M2SHSHM1x
Duke - CPS - 140
Grammars unrestricted grammarAutomata Turing machineAll Languages Rec. Enum. Lang.CFGContext-free Lang. Regular Lang.pushdown automataregular grammarfinite automata1Power of Machines automata Can do? FA PDA TM integers arith exprC
Duke - CPS - 140
CPS 140 - Mathematical Foundations of CS Dr. Susan Rodger Section: Introduction Ch. 1 handoutgrammarsall languagesautomataunrestricted grammarrecursively enumerable languagesTuring machineCFGcontext-free languages regular languagesp
Duke - CPS - 140
CPS 140Project 2 Due: Tuesday, March 25 50 pointsSpring 2003The purpose of this assignment is to write a parser for the SAPL programming language (see the project 1 handout for a description of the tokens in the SAPL programming language). Your
Duke - CPS - 140
Section: Recursively Enumerable Languages1Denition: A language L is recursively enumerable if there exists a TM M such that L=L(M).recursively enumerable languages context-free languages regular languagesDenition: A language L is recursive if
Duke - CPS - 140
Section: Pushdown Automata Ch. 7 - Pushdown Automata A DFA=(Q,q0,F)input tape a a tape head b b a b head movescurrent state 0 11Modify DFA by adding a stack. New machine is called Pushdown Automata (PDA).input tapeaa tape headaabb
Duke - CPS - 140
Section: Properties of Regular Languages Example L = {anban | n > 0}Closure Properties A set is closed over an operation if L1, L2 class L1 op L2 = L3 L3 class1L1={x | x is a positive even integer} L is closed under addition? multiplication?
Duke - CPS - 140
CPS 140Homework 5 Due: Tuesday, Mar. 30 22 pointsSpring 1999On homework, you may discuss with other students in the course about how to solve a problem, but the write-up should be your own. You must include the names of any students you consult
Duke - CPS - 140
CPS 140 - Mathematical Foundations of CS Dr. S. Rodger Section: The Structure of a Compiler 1.1 What is a Compiler? I. Translator Definition: program in translator program in language - for - language X X Y1Examples: Source Object Language Langua
Duke - CPS - 140
CPS 140Lab 2 Due: Thursday, March. 25, 8pm 20 pointsSpring 1999Problem:Using JFLAP, construct pushdown automata for the following languages. NOTE: If you have problems typing Z in the labels, then instead use little z and push it onto the stac
Duke - CPS - 140
Your id was mailed to you.Grades as of 5/9/99id finex exam1 exam2 proj2 proj3 lab1 lab2 120 100 100 50 50 26 20 =11 81.00 81.50 77.00 40.00 45.00 26.00 19.00 15 106.50 93.00 95.00 45.00
Duke - CPS - 237
a V o dA V r V }t r $ o trc &V sH V V b b 5b s( b b b b b b 5 V V tH d b 2 b b b A( V c V trfV V
Duke - CPS - 237
Probability and Algorithms Leonard J. Schulman Notes for lecture 12, Feb 24, 2003. Sampling graph colorings.Caltech CS150, Winter 2003 Scribe: Wonjin JangLet be the number of vertices and be the max degree in G. We wish to sample -colorings unifo
Duke - CPS - 237
Quantum Computing Lecture 14a (notes on QEC)Michele MoscaClassical Error Correcting CodesSuppose errors in our physical system for storing 0 and 1 cause each physical bit to be toggled independently with probability p We can reduce the probabili
Duke - CPS - 140
Section: LL Parsing LL(k) Parser: top-down parser - starts with start symbol on stack, and repeatedly replace nonterminals until string is generated. predictive parser - predict next rewrite rule rst L of LL means - read input string left to right
Duke - CPS - 210
Security (part 1)CPS210 Spring 2006Current Forensic MethodsManual inspection of existing logs System, application logsNot enough informationNetwork logMay be encryptedDisk imageOnly shows final stateMachine level logs (ReVirt)No semanti
Duke - CPS - 004
Computer Science 4: Java for Video Gameswww.cs.duke.edu/education/courses/spring06/cps004/ Instructors Dietolf (Dee) Ramm D226 LSRC dr@cs.duke.edu Robert Duvall D228 LSRC rcd@cs.duke.eduCompSci 44.1Introduction Administrative material Int
Duke - CPS - 004
JavadocCompSci 4Javadoc27jd.1The Plan What is Javadoc? Writing Javadoc comments Using the Javadoc tool PracticeCompSci 4Javadoc27jd.2What is Javadoc?Javadoc is a way to comment your code that enables automatic generation of web
Duke - CPS - 004
Computer Science 4: Java for Video Gameswww.cs.duke.edu/education/courses/spring06/cps004/ Instructors Dietolf (Dee) Ramm D226 LSRC dr@cs.duke.edu Robert Duvall D228 LSRC rcd@cs.duke.eduIntroduction Administrative material Introduction thinki
Duke - CPS - 004
The Plan Graphics Hardware Coordinate System Built-in Shapes User-defined Shapes Sprites and Shapes Making a SpriteCompSci 45.1CompSci 45.2HardwareCoordinate Systems Monitor Resolutions (640x480, 800x600, 1280x1024) Bit
Duke - CPS - 001
Todays topics!Write Your Names(or just exercise your curiosity)!Complexity " Notes from Mason Matthews " Great Ideas Ch. 13 Computability " Great Ideas Ch. 15, Brookshear Ch. 11CPS 00111.1CPS 00111.2What is Computer Science?What c
Duke - CPS - 001
KeyEscrowasaSecurity andRecoveryDevicePresented by: Kevin Ji, Maura Tresch, Eyan Townsend, Whitney Anderson, Turner Rooney, Dan Tulley WhatisaKeyEscrowSystemKey Escrow is the use of a third party (the escrow service) to save and catalog private
UC Davis - LOG - 0503
A Homage toAlfred SchnittkeIrina Schnittke, piano Tatyana Grindenko, violin Alexander Ivashkin, cello Wednesday 30 March 2005, 7.30pmConcert in aid of the Alfred Schnittke Archive in London Sponsored by the Centre for Russian Music, Goldsmiths C
UC Davis - ATT - 0503
A Homage toAlfred SchnittkeIrina Schnittke, piano Tatyana Grindenko, violin Alexander Ivashkin, cello Wednesday 30 March 2005, 7.30pmConcert in aid of the Alfred Schnittke Archive in London Sponsored by the Centre for Russian Music, Goldsmiths C
Duke - STA - 205
Midterm ExaminationSTA 205: Probability and Measure Theory Wednesday, 2005 Mar 9, 2:50-4:05 pmThis is a closed-book examination. You may use a single one-sided sheet of prepared notes, if you wish, but you may not share materials. If a question se
Duke - STA - 216
Bayesian Hypothesis Testing in GLMs: One-Sided and Ordered Alternatives Often interest may focus on comparing a null hypothesis of no dierence between groups to an ordered restricted alternative. For example, we may have a k level ordered categoric
Duke - STA - 103
STA103Probability/Statistical InferenceJenises contact infoInstructor: Jenise Swall Office: 221 Old Chem Bldg. Phone: 684-4608 Office hours: Wed. 9:30PM-10:30PM, Thu. 1:30PM-2:30PM jenise@stat.duke.eduTA contact infoChristine KohnenMickel