# Register now to access 7 million high quality study materials (What's Course Hero?) Course Hero is the premier provider of high quality online educational resources. With millions of study documents, online tutors, digital flashcards and free courseware, Course Hero is helping students learn more efficiently and effectively. Whether you're interested in exploring new subjects or mastering key topics for your next exam, Course Hero has the tools you need to achieve your goals.

5 Pages

### End of Term Review 1.4

Course: CSE 2011Z, Fall 2011
School: York University
Rating:

Word Count: 184

#### Document Preview

Trees AVL AVL trees are balanced. An AVL Tree is a binary search tree in which the heights of siblings can differ by at most 1. height 0 0 0 0 0 CSE 2011 Prof. J. Elder 0 0 - 16 - 0 0 Last Updated: 4/1/10 2:37 PM Height of an AVL Tree Claim: The height of an AVL tree storing n keys is O(log n). CSE 2011 Prof. J. Elder - 17 - Last Updated: 4/1/10 2:37 PM Insertion Imbalance may occur at any ancestor of...

Register Now

#### Unformatted Document Excerpt

Coursehero >> Canada >> York University >> CSE 2011Z

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.
Trees AVL AVL trees are balanced. An AVL Tree is a binary search tree in which the heights of siblings can differ by at most 1. height 0 0 0 0 0 CSE 2011 Prof. J. Elder 0 0 - 16 - 0 0 Last Updated: 4/1/10 2:37 PM Height of an AVL Tree Claim: The height of an AVL tree storing n keys is O(log n). CSE 2011 Prof. J. Elder - 17 - Last Updated: 4/1/10 2:37 PM Insertion Imbalance may occur at any ancestor of the inserted node. height = 3 2 1 0 7 Insert(2) 1 4 1 3 0 height = 4 0 5 0 2 0 1 0 2 Problem! 4 1 3 0 1 0 8 0 0 5 0 0 0 CSE 2011 Prof. J. Elder 3 8 7 - 18 - Last Updated: 4/1/10 2:37 PM Insertion: Rebalancing Strategy Step 1: Search Starting the at inserted node, traverse toward the root until an imbalance is discovered. 3 2 1 2 height = 4 0 1 Problem! 4 1 3 0 7 8 0 0 5 0 0 CSE 2011 Prof. J. Elder - 19 - Last Updated: 4/1/10 2:37 PM Insertion: Rebalancing Strategy Step 2: Repair The repair strategy is called trinode restructuring. height = 4 7 3 nodes x, y and z are distinguished: z = the parent of the high sibling 3 y = the high sibling x = the high child of the high sibling 2 We can now think of the subtree rooted at z as consisting of these 3 nodes plus their 4 subtrees 1 2 Problem! 4 1 3 0 1 0 8 0 0 5 0 0 CSE 2011 Prof. J. Elder - 20 - Last Updated: 4/1/10 2:37 PM
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:

York University - CSE - 2011Z
Insertion: Trinode Restructuring ExampleNote that y is the middle value.height=hzh-1yRestructureyh-1h-2T0xh-3h-3h-2T3T2T0xh-2T1h-3T2zh-3T3one is h-3 &amp;one is h-4T1one is h-3 &amp;one is h-4CSE 2011Prof. J. Elder- 21 -Last Upd
York University - CSE - 2011Z
Removal: Rebalancing StrategyStep 2: RepairWe again use trinode restructuring.height = 33 nodes x, y and z are distinguished:7z = the parent of the high sibling2y = the high sibling4x = the high child of the high sibling (ifchildren are equally
York University - CSE - 2011Z
Splay TreesSelf-balancing BSTInvented by Daniel Sleator and Bob TarjanAllows quick access to recently accessedelementsD. SleatorBad: worst-case O(n)Good: average (amortized) case O(log n)Often perform better than other BSTs inpracticeR. TarjanC
York University - CSE - 2011Z
ZigPerformed when the node x has no grandparenti.e., its parent is the rootyxzigxwyT4wT3T1T1T2T3T4T2CSE 2011Prof. J. Elder- 36 -Last Updated: 4/1/10 2:37 PMTopic 2. SortingCSE 2011Prof. J. Elder- 37 -Last Updated: 4/1/10 2:37 PM
York University - CSE - 2011Z
Stable SortA sorting algorithm is said to be stable if the ordering ofidentical keys in the input is preserved in the output.The stable sort property is important, for example, whenentries with identical keys are already ordered byanother criterion.
York University - CSE - 2011Z
Merge SortMerge two sorted lists into one25,31,52,88,9814,23,25,30,31,52,62,79,88,9814,23,30,62,79CSE 2011Prof. J. Elder- 46 -Last Updated: 4/1/10 2:37 PMAnalysis of Merge-SortThe height h of the merge-sort tree is O(log n)at each recursive cal
York University - CSE - 2011Z
The Quick-Sort AlgorithmAlgorithm QuickSort(S)if S.size() &gt; 1(L, E, G) = Partition(S)QuickSort(L)QuickSort(G)S = (L, E, G)CSE 2011Prof. J. Elder- 51 -Last Updated: 4/1/10 2:37 PMIn-Place Quick-SortNote: Use the lecture slides here instead of t
York University - CSE - 2011Z
Comparison Sort: Decision TreesFor a 3-element array, there are 6 external nodes.For an n-element array, there are n ! external nodes.CSE 2011Prof. J. Elder- 56 -Last Updated: 4/1/10 2:37 PMComparison SortTo store n! external nodes, a decision tre
York University - CSE - 2011Z
RadixSort344125333134224334143225325243333143Sort wrt which 243digit first?344134224The least334significant.1252253252 241 25Sort wrt which 2 25digit Second? 3 253 33The next least 1 343 34significant.1 432 433 44Is sort
York University - CSE - 2011Z
GraphsDefinitions &amp; PropertiesImplementationsDepth-First SearchTopological SortBreadth-First SearchWeighted GraphsSingle-Source Shortest Path on DAGsGeneral Single-Source Shortest Path (Dijkstras Algorithm)CSE 2011Prof. J. Elder- 66 -Last Upda
York University - CSE - 2011Z
DFS Example on Undirected GraphAunexploredAbeing exploredAfinishedABunexplored edgediscovery edgeDEDECback edgeABADEBCCSE 2011Prof. J. ElderC- 71 -Last Updated: 4/1/10 2:37 PMExample (cont.)ABADEBDDCECAEABDEB
York University - CSE - 2011Z
DAGs and Topological OrderingA directed acyclic graph (DAG) is adigraph that has no directed cyclesA topological ordering of a digraphis a numberingDv1 , , vnBof the vertices such that for everyedge (vi , vj), we have i &lt; jCDAG GAExample: in
York University - CSE - 2011Z
BFS Example (cont.)L0L1L0ABCEL0L1DFL0CECSE 2011Prof. J. ElderBL2ABL2L1L1D- 81 -CEDFABL2FACEDFLast Updated: 4/1/10 2:37 PMBFS Example (cont.)L0L1L0L1ABL2CEL1DBL2FACEDFABL2L0CECSE 2011Prof.
York University - CSE - 2011Z
Relaxing an edgeCan we improve shortest-path estimate for v by first going to uand then following edge (u,v)?RELAX(u, v, w)if d[v] &gt; d[u] + w(u, v) thend[v][v]CSE 2011Prof. J. Elderd[u] + w(u, v)u- 86 -Last Updated: 4/1/10 2:37 PMGeneral sing
York University - CSE - 2011Z
Example 2. Single-Source Shortest Path ona General Graph (May Contain Cycles)This is fundamentally harder, because the first paths wediscover may not be the shortest (not monotonic).CSE 2011Prof. J. Elder- 91 -Last Updated: 4/1/10 2:37 PMDijkstras
York University - CSE - 2011Z
ExampleCSE 2011Prof. J. Elder- 96 -Last Updated: 4/1/10 2:37 PMExampleCSE 2011Prof. J. Elder- 97 -Last Updated: 4/1/10 2:37 PMExampleCSE 2011Prof. J. Elder- 98 -Last Updated: 4/1/10 2:37 PM
York University - CSE - 2011Z
Graphs337LAXCSE 2011Prof. J. ElderORD802SFO18431233-1-DFWLast Updated: 4/1/10 10:16 AMApplicationsElectronic circuitsPrinted circuit boardIntegrated circuitTransportation networksHighway networkFlight networkComputer networksLocal are
York University - CSE - 2011Z
PathsPathsequence of alternatingvertices and edgesbegins with a vertexends with a vertexVaeach edge is preceded andfollowed by its endpointsSimple pathP1dUcpath such that all its verticesand edges are distinctExamplesbXP2hZeWgfP
York University - CSE - 2011Z
Spanning TreesA spanning tree of a connectedgraph is a spanning subgraph thatis a treeA spanning tree is not uniqueunless the graph is a treeSpanning trees have applicationsto the design of communicationnetworksGraphA spanning forest of a graph
York University - CSE - 2011Z
Running Time of Graph AlgorithmsRunning time often a function of both |V| and |E|.For convenience, we sometimes drop the | . | inasymptotic notation, e.g. O(V+E).CSE 2011Prof. J. Elder- 16 -Last Updated: 4/1/10 10:16 AMImplementing a Graph (Simpli
York University - CSE - 2011Z
York University - CSE - 2011Z
Depth-First SearchExplore every edge, starting from different vertices if necessary.As soon as vertex discovered, explore from it.Keep track of progress by colouring vertices:Black: undiscovered verticesRed: discovered, but not finished (still explor
York University - CSE - 2011Z
Properties of DFSProperty 1DFS-Visit(u) visits all thevertices and edges in theconnected component of uAProperty 2The discovery edgeslabeled by DFS-Visit(u)form a spanning tree of theconnected component of uCSE 2011Prof. J. ElderBDEC- 31
York University - CSE - 2011Z
DFS Algorithm with Discovery and Finish TimesDFS-Visit (u)Precondition: vertex u is undiscoveredPostcondition: all vertices reachable from u have been processedcolour[u ]REDtime time + 1d[u] timefor each v Adj[u ] /explore edge (u,v )if color[v ]
York University - CSE - 2011Z
FoundNot HandledStack&lt;node,# edges&gt;DFSs1/b2/ad/e/f/g/c//j//i/a,0s,1hm//kCSE 2011Prof. J. Elderl- 41 -/Last Updated: 4/1/10 10:16 AMFoundNot HandledStack&lt;node,# edges&gt;DFSs1/b2/ad3/e/f/g/c//j//i
York University - CSE - 2011Z
FoundNot HandledStack&lt;node,# edges&gt;DFSs1/b2/ad3/e/f/g/c//j//i4/7hmc,1a,1s,1/5/6kCSE 2011Prof. J. Elderl- 46 -/Last Updated: 4/1/10 10:16 AMFoundNot HandledStack&lt;node,# edges&gt;DFSs1/b2/ad3/e/f/g/c/
York University - CSE - 2011Z
FoundNot HandledStack&lt;node,# edges&gt;DFSs1/b2/ad3/e/f/g/c//j8//i4/7hml,1i,3c,2a,1s,1/5/6kCSE 2011Prof. J. Elderl- 51 -9/Last Updated: 4/1/10 10:16 AMFoundNot HandledStack&lt;node,# edges&gt;DFSs1/b2/ad3/e/f
York University - CSE - 2011Z
FoundNot HandledStack&lt;node,# edges&gt;DFSs1/b2/ad3/e/f/g11/c//j8/12/i4/7hmm,0j,2g,1i,4c,2a,1s,113/5/6kCSE 2011Prof. J. Elderl 9/10- 56 -Last Updated: 4/1/10 10:16 AMFoundNot HandledStack&lt;node,# edges&gt;DFSs1/b
York University - CSE - 2011Z
DFSs1/b2/ad3/e/f/g11/16c/FoundNot HandledStack&lt;node,# edges&gt;17/j 12/158/i4/7hf,0i,5c,2a,1s,1m 13/145/6kCSE 2011Prof. J. Elderl 9/10- 61 -Last Updated: 4/1/10 10:16 AMDFSs1/b2/ad3/e/f/g11/16c/FoundNot
York University - CSE - 2011Z
DFSs1/b2/ad3/19e//g11/16c/FoundNot HandledStack&lt;node,# edges&gt;f 17/18j 12/158/19i4/7a,1s,1hm 13/145/6kCSE 2011Prof. J. Elderl 9/10- 66 -Last Updated: 4/1/10 10:16 AMDFSs1/b2/ad3/19e//g11/16c/FoundNot Handl
York University - CSE - 2011Z
DFSs1/b2/20ad3/19e21//g11/16c/FoundNot HandledStack&lt;node,# edges&gt;f 17/18j 12/158/19i4/7d,2s,2hm 13/145/6kCSE 2011Prof. J. Elderl 9/10- 71 -Last Updated: 4/1/10 10:16 AMDFSs1/b2/20ad3/19e21/f 17/18j 12/15 e,0d
York University - CSE - 2011Z
DFSs1/b 25/262/20ae 22/23d 21/243/19g11/16cFoundNot HandledStack&lt;node,# edges&gt;f 17/18j 12/158/19i4/7s,4hm 13/145/6kCSE 2011Prof. J. Elderl 9/10- 81 -Last Updated: 4/1/10 10:16 AMDFSTree EdgesBack EdgesForward EdgesCross
York University - CSE - 2011Z
DFS on Undirected GraphsSuppose that (u,v) is a forward edge or across edge in a DFS of an undirected graph.(u,v) is a forward edge or a cross edge when vis already handled (grey) when accessed fromu.This means that all vertices reachable from vhav
York University - CSE - 2011Z
DAGs and Topological OrderingA directed acyclic graph (DAG) is adigraph that has no directed cyclesA topological ordering of a digraphis a numberingDv1 , , vnBof the vertices such that for everyedge (vi , vj), we have i &lt; jCDAG GAExample: in
York University - CSE - 2011Z
Linear OrderAlg: DFSahijkbcdegfCSE 2011Prof. J. ElderFoundNot HandledStackfgedl- 96 -. fLast Updated: 4/1/10 10:16 AMLinear OrderAlg: DFSahijkbcdegfFoundNot HandledStacklgedlWhen node is popped off stack, ins
York University - CSE - 2011Z
Linear OrderAlg: DFSaFoundNot HandledStackhijkbcdegflLinear Order:CSE 2011Prof. J. Elder- 101 -d,e,g,l,fLast Updated: 4/1/10 10:16 AMLinear OrderAlg: DFSahijkbcdekjigfFoundNot HandledStacklLinear Order:CSE 2011
York University - CSE - 2011Z
Linear OrderAlg: DFSaFoundNot HandledStackhijkbcdegfcblLinear Order:CSE 2011Prof. J. Elder- 106 -i,j,k,d,e,g,l,fLast Updated: 4/1/10 10:16 AMLinear OrderAlg: DFSaFoundNot HandledStackhijkbcdegflbLinear Order:CSE
York University - CSE - 2011Z
aLinear OrderAlg: DFSFoundNot HandledStackhijkbcdegflLinear Order:CSE 2011Prof. J. Elder- 111 -a,h,b,c,i,j,k,d,e,g,l,f Done!Last Updated: 4/1/10 10:16 AMDFS Algorithm for Topologial SortMakes sense. But how do we prove that it work
York University - CSE - 2011Z
DFSs1/b2/20ae 22/23d 21/243/19g11/16c/FoundNot HandledStack&lt;node,# edges&gt;f 17/18j 12/158/19i4/7s,3hm 13/145/6kCSE 2011Prof. J. Elderl 9/10- 76 -Last Updated: 4/1/10 10:16 AMDFSs1/b2/20ae 22/23d 21/243/19g11/16c2
York University - CSE - 2011Z
CSE 2011 Fundamentals of Data StructuresComputer programming is an art, because it applies accumulatedknowledge to the world, because it requires skill and ingenuity, andespecially because it produces objects of beauty.- Donald KnuthCSE 2011Prof. J.
York University - CSE - 2011Z
Summary of RequirementsComponentWeightProgramming Assignments (4)20%Midterm test (closed book)30%Final exam (closed book)50%Please see syllabus posted on website for more detailed information.CSE 2011Prof. J. ElderLast Updated: January 5, 2012
York University - CSE - 2011Z
Data Structures &amp; Object-Oriented Design Definitions Software Engineering Efficiency and Asymptotic Analysis Principles of Object-Oriented Design Inheritance Polymorphism Interfaces Casting GenericsCSE 2011Prof. J. ElderLast Updated: January 5
York University - CSE - 2011Z
Data Structures We Will StudyLinear Data Structures Arrays Linked Lists Stacks Queues Priority QueuesNon-Linear Data Structures Trees Heaps Hash Tables Search TreesGraphs Directed Graphs Weighted GraphsCSE 2011Prof. J. ElderLast Updated:
York University - CSE - 2011Z
Premature Optimization Premature optimization is the root of all evil. Donald KnuthCSE 2011Prof. J. ElderLast Updated: January 5, 2012Premature Optimization In general we want programs to be efficient. But: Obviously it is more important that they
York University - CSE - 2011Z
Abstraction The psychological profiling of a programmer is mostly theability to shift levels of abstraction, from low level to highlevel. To see something in the small and to seesomething in the large. Donald KnuthWassily Kandinsky (Russian, 1866-19
York University - CSE - 2011Z
Types of Method Overriding Generally methods of a subclass replace superclassmethods. An exception is constructor methods, which do notreplace, but refine superclass constructor methods. Thus invocation of a constructor method starts with thehighest
York University - CSE - 2011Z
Polymorphism Polymorphism = many forms Polymorphism allows an object variable to take differentforms, depending upon the specific class of the object itrefers to. Suppose an object o is defined to be of class S. It is now valid to instantiate o as a
York University - CSE - 2011Z
ADT Examplepublic interface Device cfw_public String make();public String model();InterfaceDevicepublic class Camera implements Device cfw_private String cameraMake;private String cameraModel;private int numPix;Camera(String mk, String mdl, int
York University - CSE - 2011Z
Generics A generic type is a type that is not defined atcompilation time.when instantiated as a variable. A generic type becomes fully defined only at run time. This allows us to define a class in terms of a set offormal type parameters, that can be
York University - CSE - 2011Z
Subtyping with Wildcards In order to obtain this kind of subtyping with generics, you can usewildcards. For example:Couple&lt;? extends Camera, ? extends Camera&gt; stereoCamera= new Couple&lt;DigitalCamera,DigitalCamera&gt;();orCouple&lt;? extends Camera, ? exte
York University - CSE - 2011Z
Lecture 3Linear Data StructuresChapters 3.1-3.3 , 5.1-5.2, 6.1CSE 2011Prof. J. Elder-1-Last Updated: 12-01-17 9:52 AMOutline Our goal in this lecture is to Review the basic linear data structures Demonstrate how each can be defined as an Abstrac
York University - CSE - 2011Z
Arrays in Java (java.util.Arrays)For an array of length n, the index bounds are 0 to n-1.Java arrays are homogeneous all array components must be of the same (object or primitive) type. but, an array of an object type can contain objects of any respec
York University - CSE - 2011Z
ExampleExample [ 2D array of objects in Java = an array of arrays of references]Square[][] board = new Square[2][3];CSE 2011Prof. J. Elder- 11 -Last Updated: 12-01-17 9:52 AMThe Java.util.Arrays ClassArrays in Java Useful Built-In Methods in Java
York University - CSE - 2011Z
The Array List ADT (6.1) The Array List ADT extends the notion of array by storinga sequence of arbitrary objects An element can be accessed, inserted or removed byspecifying its rank (number of elements preceding it) An exception is thrown if an inc
York University - CSE - 2011Z
Performance In the array based implementation The space used by the data structure is O(n) size, isEmpty, get and set run in O(1) time add and remove run in O(n) time In an add operation, when the array is full,instead of throwing an exception, we c
York University - CSE - 2011Z
Doubling Strategy Analysis We replace the array k = log2 n times The total time T(n) of a series of n add(o)operations is proportional ton + 1 + 2 + 4 + 8 + + 2k = n + 2k + 1 -1 = 3n -1geometric series Thus T(n) is O(n)2 The amortized time of an a
York University - CSE - 2011Z
Applications of Stacks Page-visited history in a Web browser Undo sequence in a text editor Chain of method calls in the Java Virtual Machine Parsing mathCSE 2011Prof. J. Elder- 31 -Last Updated: 12-01-17 9:52 AMMethod Stack in the JVM The Java
York University - CSE - 2011Z
Example array-based stack in Javapublic class ArrayStackimplements Stack cfw_public Object pop()throws EmptyStackException cfw_if isEmpty()throw new EmptyStackException(Empty stack: cannot pop);Object temp = S[top];/ facilitates garbage collectio
York University - CSE - 2011Z
Queue ExampleOperation Qenqueue(5)(5)enqueue(3)(5, 3)dequeue()5(3)enqueue(7)(3, 7)dequeue()3(7)front()7(7)dequeue()7()dequeue()error()isEmpty()true()enqueue(9)(9)enqueue(7)(9, 7)size()2(9, 7)e
York University - CSE - 2011Z
Queue Interface in Java Java interfacecorresponding toour Queue ADT Requires thedefinition of classEmptyQueueExceptionCSE 2011Prof. J. Elderpublic interface Queue cfw_public int size();public boolean isEmpty();public Object front()throws Empt
York University - CSE - 2011Z
Example Java Class for Singly-Linked Listpublic class SLinkedList cfw_/ Instance variables:protected Node head; /head node of listprotected Node tail; /tail node of listprotected long size; /number of nodes in list/* Default constructor that creates