Suggested Study Strategy

Size: px
Start display at page:

Download "Suggested Study Strategy"

Transcription

1 Final Exam Thursday, 7 August 2014,19:00 22:00 Closed Book Will cover whole course, with emphasis on material after midterm (hash tables, binary search trees, sorting, graphs)

2 Suggested Study Strategy Review and understand the slides. Read the textbook, especially where concepts and methods are not yet clear to you. Do all of the practice problems provided. Do extra practice problems from the textbook. Review the midterm and solutions for practice writing this kind of exam. Practice writing clear, succinct pseudocode! Review the assignments See me or one of the TAs if there is anything that is still not clear.

3 Assistance Regular office hours will not be held You may me by / Skype

4 End of Term Review

5 1. Binary Search Trees 2. Sorting 3. Graphs Summary of Topics

6 Topic 1. Binary Search Trees

7 Binary Search Trees Insertion Deletion AVL Trees Splay Trees

8 Binary Search Trees A binary search tree is a binary tree storing key-value entries at its internal nodes and satisfying the following property: Let u, v, and w be three nodes such that u is in the left subtree of v and w is in the right subtree of v. We have key(u) key(v) key(w) The textbook assumes that external nodes are placeholders : they do not store entries (makes algorithms a little simpler) An inorder traversal of a binary search trees visits the keys in increasing order Binary search trees are ideal for maps or dictionaries with ordered keys

9 Binary Search Tree All nodes in left subtree Any node All nodes in right subtree

10 Search: Define Step Cut sub-tree in half. Determine which half the key would be in. Keep that half. key If key < root, then key is in left half. If key = root, then key is found If key > root, then key is in right half.

11 Insertion (For Dictionary) To perform operation insert(k, o), we search for key k (using TreeSearch) Suppose k is not already in the tree, and let w be the leaf reached by the search We insert k at node w and expand w into an internal node Example: insert 5 w < > > w 9

12 Insertion Suppose k is already in the tree, at node v. We continue the downward search through v, and let w be the leaf reached by the search Note that it would be correct to go either left or right at v. We go left by convention. We insert k at node w and expand w into an internal node Example: insert 6 2 < > > 9 2 w w 6 9

13 Deletion To perform operation remove(k), we search for key k Suppose key k is in the tree, and let v be the node storing k If node v has a leaf child w, we remove v and w from the tree with operation removeexternal(w), which removes w and its parent Example: remove 4 < w > v

14 Deletion (cont.) Now consider the case where the key k to be removed is stored at a node v whose children are both internal we find the internal node w that follows v in an inorder traversal we copy the entry stored at w into node v we remove node w and its left child z (which must be a leaf) by means of operation removeexternal(z) Example: remove v 1 5 v z w

15 Performance Consider a dictionary with n items implemented by means of a binary search tree of height h the space used is O(n) methods find, insert and remove take O(h) time The height h is O(n) in the worst case and O(log n) in the best case It is thus worthwhile to balance the tree (next topic)!

16 AVL Trees AVL trees are balanced. An AVL Tree is a binary search tree in which the heights of siblings can differ by at most height

17 Height of an AVL Tree Claim: The height of an AVL tree storing n keys is O(log n).

18 Insertion Imbalance may occur at any ancestor of the inserted node. height = 3 7 height = Insert(2) 3 4 Problem!

19 Insertion: Rebalancing Strategy Step 1: Search Starting at the inserted node, traverse toward the root until an imbalance is discovered. height = Problem!

20 Insertion: Rebalancing Strategy Step 2: Repair The repair strategy is called trinode restructuring. 3 nodes x, y and z are distinguished: z = the parent of the high sibling y = the high sibling x = the high child of the high sibling We can now think of the subtree rooted at z as consisting of these 3 nodes plus their 4 subtrees height = Problem!

21 Insertion: Trinode Restructuring Example Note that y is the middle value. height = h z h-1 y Restructure y h-1 h-3 T 3 h-2 x h-2 z h-2 x h-3 T 2 h-3 h-3 T 0 T 1 T 2 T 3 T 0 T 1 one is h-3 & one is h-4 one is h-3 & one is h-4

22 Insertion: Trinode Restructuring - 4 Cases There are 4 different possible relationships between the three nodes x, y and z before restructuring: x y z z y x y x z z x y height = h z height = h z height = h z height = h z y h-1 h-3 T 3 y h-3 h-1 T 0 y h-1 h-3 T 3 y h-3 h-1 T 0 h-2 x h-3 h-3 x h-2 h-3 h-2 x x h-2 h-3 T 2 T 1 T 0 T 3 T 0 T 1 T 2 T 3 T 1 T 2 T 1 T 2 one is h-3 & one is h- 4 one is h-3 & one is h- 4 one is h-3 & one is h- 4 one is h-3 & one is h- 4

23 Insertion: Trinode Restructuring - The Whole Tree Do we have to repeat this process further up the tree? No! The tree was balanced before the insertion. Insertion raised the height of the subtree by 1. Rebalancing lowered the height of the subtree by 1. Thus the whole tree is still balanced. height = h z h-1 y Restructure h-1 y h-3 T 3 h-2 x h-2 z h-2 x h-3 T 2 T 0 T 1 h-3 T 2 h-3 T 3 T 0 T 1 one is h-3 & one is h-4 one is h-3 & one is h-4

24 Removal Imbalance may occur at an ancestor of the removed node. height = 3 7 height = Remove(8) 2 4 Problem!

25 Step 1: Search Removal: Rebalancing Strategy Starting at the location of the removed node, traverse toward the root until an imbalance is discovered. height = Problem!

26 Removal: Rebalancing Strategy Step 2: Repair We again use trinode restructuring. 3 nodes x, y and z are distinguished: height = 3 7 z = the parent of the high sibling y = the high sibling x = the high child of the high sibling (if children are equally high, keep chain linear) Problem!

27 Removal: Rebalancing Strategy Step 2: Repair The idea is to rearrange these 3 nodes so that the middle value becomes the root and the other two becomes its children. Thus the linear grandparent parent child structure becomes a triangular parent two children structure. Note that z must be either bigger than both x and y or smaller than both x and y. Thus either x or y is made the root of this subtree, and z is lowered by 1. Then the subtrees T 0 T 3 are attached at the appropriate places. Although the subtrees T 0 T 3 can differ in height by up to 2, after restructuring, sibling subtrees will differ by at most 1. h-2 x T 0 T 1 h-3 or h-3 & h- 4 height = h y T 2 z h-1 h-3 h-2 or h-3 T 3

28 Removal: Trinode Restructuring - 4 Cases There are 4 different possible relationships between the three nodes x, y and z before restructuring: x y z z y x y x z z x y height = h z height = h z height = h z height = h z y h-1 h-3 T 3 y h-3 h-1 T 0 y h-1 h-3 T 3 y h-3 h-1 T 0 h-2 x h-2 or h- 3 T 2 T 1 h-2 or h- 3 x h-2 h-2 or h- 3 T 0 h-2 x x h-2 T 3 h-2 or h- 3 T 0 T 1 T 2 T 3 T 1 T 2 T 1 T 2 h-3 or h-3 & h-4 h-3 or h-3 & h-4 h-3 or h-3 & h-4 h-3 or h-3 & h-4

29 Removal: Trinode Restructuring - Case 1 Note that y is the middle value. height = h y z h-1 h-3 T 3 Restructure h-2 x h or h-1 y h-1 or h-2 z h-2 x T 0 T 1 h-2 or h-3 T 2 T 0 T 1 T 2 T 3 h-3 or h-3 & h- 4 h-2 or h-3 h-3 h-3 or h-3 & h- 4

30 Step 2: Repair Removal: Rebalancing Strategy Unfortunately, trinode restructuring may reduce the height of the subtree, causing another imbalance further up the tree. Thus this search and repair process must be repeated until we reach the root.

31 Topic 2. Sorting

32 Comparison Sorting Selection Sort Bubble Sort Insertion Sort Merge Sort Heap Sort Quick Sort Linear Sorting Counting Sort Radix Sort Bucket Sort Sorting Algorithms

33 Comparison Sorts Comparison Sort algorithms sort the input by successive comparison of pairs of input elements. Comparison Sort algorithms are very general: they make no assumptions about the values of the input elements e.g.,3 11?

34 Sorting Algorithms and Memory Some algorithms sort by swapping elements within the input array Such algorithms are said to sort in place, and require only O(1) additional memory. Other algorithms require allocation of an output array into which values are copied. These algorithms do not sort in place, and require O(n) additional memory swap

35 Stable Sort A sorting algorithm is said to be stable if the ordering of identical keys in the input is preserved in the output. The stable sort property is important, for example, when entries with identical keys are already ordered by another criterion. (Remember that stored with each key is a record containing some useful information.)

36 Selection Sort Selection Sort operates by first finding the smallest element in the input list, and moving it to the output list. It then finds the next smallest value and does the same. It continues in this way until all the input elements have been selected and placed in the output list in the correct order. Note that every selection requires a search through the input list. Thus the algorithm has a nested loop structure Selection Sort Example

37 Bubble Sort Bubble Sort operates by successively comparing adjacent elements, swapping them if they are out of order. At the end of the first pass, the largest element is in the correct position. A total of n passes are required to sort the entire array. Thus bubble sort also has a nested loop structure Bubble Sort Example

38 Example: Insertion Sort

39 Merge Sort Get one friend to sort the first half Split Set into Two (no real work) Get one friend to sort the second half. 25,31,52,88,98 14,23,30,62,79

40 Merge Sort Merge two sorted lists into one 25,31,52,88,98 14,23,30,62,79 14,23,25,30,31,52,62,79,88,98

41 Analysis of Merge-Sort The height h of the merge-sort tree is O(log n) at each recursive call we divide in half the sequence, The overall amount or work done at the nodes of depth i is O(n) we partition and merge 2 i sequences of size n/2 i we make 2 i+1 recursive calls Thus, the total running time of merge-sort is O(n log n) depth #seqs size 0 1 n T(n) = 2T(n / 2) + O(n) 1 2 n/2 i 2 i n/2 i

42 Heap-Sort Algorithm Build an array-based (max) heap Iteratively call removemax() to extract the keys in descending order Store the keys as they are extracted in the unused tail portion of the array

43 Heap-Sort Running Time The heap can be built bottom-up in O(n) time Extraction of the ith element takes O(log(n - i+1)) time (for downheaping) Thus total run time is T(n) = O(n) + log(n - i + 1) n å i =1 = O(n) + log i n å i =1 O(n) + logn n å i =1 = O(nlogn)

44 Quick-Sort Quick-sort is a divide-andconquer algorithm: Divide: pick a random element x (called a pivot) and partition S into x L elements less than x E elements equal to x x G elements greater than x L E G Recur: Quick-sort L and G Conquer: join L, E and G x

45 The Quick-Sort Algorithm Algorithm QuickSort(S) if S.size() > 1 (L, E, G) = Partition(S) QuickSort(L) QuickSort(G) S = (L, E, G)

46 In-Place Quick-Sort Note: Use the lecture slides here instead of the textbook implementation (Section ) Partition set into two using randomly chosen pivot

47 Maintaining Loop Invariant

48 The In-Place Quick-Sort Algorithm Algorithm QuickSort(A, p, r) if p < r q = Partition(A, p, r) QuickSort(A, p, q - 1) QuickSort(A, q + 1, r)

49 Summary of Comparison Sorts Algorithm Best Case Worst Case Average Case In Place Stable Selection n 2 n 2 Yes Yes Comments Bubble n n 2 Yes Yes Insertion n n 2 Yes Yes Good if often almost sorted Merge n log n n log n No Yes Good for very large datasets that require swapping to disk Heap n log n n log n Yes No Best if guaranteed n log n required Quick n log n n 2 n log n Yes No Usually fastest in practice

50 Comparison Sort: Decision Trees For a 3-element array, there are 6 external nodes. For an n-element array, there are n! external nodes.

51 Comparison Sort To store n! external nodes, a decision tree must have a height of at least é ê logn! ù ú Worst-case time is equal to the height of the binary decision tree. Thus T(n) ÎW( logn! ) wherelogn! = n å log i ³ log ê ë n / 2ú û i =1 Thus T(n) ÎW(nlogn) ê ë n/ 2ú û å i =1 ÎW(nlogn) Thus MergeSort & HeapSort are asymptotically optimal.

52 Linear Sorts? Comparison sorts are very general, but are ( nlog n) Faster sorting may be possible if we can constrain the nature of the input.

53 CountingSort Input: Output: Index: Value v: Location of next record with digit v Algorithm: Go through the records in order putting them where they go.

54 CountingSort Input: Output: 0 1 Index: Value v: Location of next record with digit v Algorithm: Go through the records in order putting them where they go.

55 RadixSort Sort wrt which digit first? The least significant Sort wrt which digit Second? The next least significant Is sorted wrt least sig. 2 digits.

56 RadixSort i+1 Is sorted wrt first i digits. Sort wrt i+1st digit Is sorted wrt first i+1 digits. These are in the correct order because sorted wrt high order digit

57 RadixSort i+1 Is sorted wrt first i digits. Sort wrt i+1st digit Is sorted wrt first i+1 digits. These are in the correct order because was sorted & stable sort left sorted

58 Example 3. Bucket Sort Applicable if input is constrained to finite interval, e.g., [0 1). If input is random and uniformly distributed, expected run time is Θ(n).

59 Bucket Sort

60 Topic 3. Graphs

61 Definitions & Properties Implementations Depth-First Search Topological Sort Breadth-First Search Graphs

62 Properties Property 1 v deg(v) = 2 E Proof: each edge is counted twice Property 2 In an undirected graph with no self-loops and no multiple edges E V ( V - 1)/2 Proof: each vertex has degree at most ( V 1) Q: What is the bound for a digraph? A: E V (V -1) Notation V E deg(v) number of vertices number of edges degree of vertex v Example V = 4 E = 6 deg(v) = 3

63 Main Methods of the (Undirected) Graph ADT Vertices and edges are positions store elements Accessor methods endvertices(e): an array of the two endvertices of e opposite(v, e): the vertex opposite to v on e areadjacent(v, w): true iff v and w are adjacent replace(v, x): replace element at vertex v with x replace(e, x): replace element at edge e with x Update methods insertvertex(o): insert a vertex storing element o insertedge(v, w, o): insert an edge (v,w) storing element o removevertex(v): remove vertex v (and its incident edges) removeedge(e): remove edge e Iterator methods incidentedges(v): edges incident to v vertices(): all vertices in the graph edges(): all edges in the graph

64 Running Time of Graph Algorithms Running time often a function of both V and E. For convenience, we sometimes drop the. in asymptotic notation, e.g. O(V+E).

65 Implementing a Graph (Simplified) Space complexity: Time to find all neighbours of vertex u : Adjacency List ( V + E) (degree( u)) Adjacency Matrix 2 ( V ) ( V ) Time to determine if ( u, v) E : (degree( u)) (1)

66 DFS Example on Undirected Graph A A unexplored being explored A A finished unexplored edge B D E discovery edge back edge C A A B D E B D E C C

67 Example (cont.) A A B D E B D E C C A A B D E B D E C C

68 DFS Algorithm Pattern DFS(G) Precondition: G is a graph Postcondition: all vertices in G have been visited for each vertex u ÎV[G] color[u] = BLACK //initialize vertex for each vertex u ÎV[G] if color[u] = BLACK //as yet unexplored DFS-Visit(u) total work = q(v )

69 DFS Algorithm Pattern DFS-Visit (u) Precondition: vertex u is undiscovered Postcondition: all vertices reachable from u have been processed colour[u] RED for each v ÎAdj[u] //explore edge (u,v) if color[v] = BLACK DFS-Visit(v) colour[u] GRAY Thus running time = q(v + E) (assuming adjacency list structure) total work å = Adj[v] = q(e) v ÎV

70 Other Variants of Depth-First Search The DFS Pattern can also be used to Compute a forest of spanning trees (one for each call to DFSvisit) encoded in a predecessor list π[u] Label edges in the graph according to their role in the search (see textbook) Tree edges, traversed to an undiscovered vertex Forward edges, traversed to a descendent vertex on the current spanning tree Back edges, traversed to an ancestor vertex on the current spanning tree Cross edges, traversed to a vertex that has already been discovered, but is not an ancestor or a descendent

71 DAGs and Topological Ordering A directed acyclic graph (DAG) is a digraph that has no directed cycles A topological ordering of a digraph is a numbering D E v 1,, v n of the vertices such that for every edge (v i, v j ), we have i < j Example: in a task scheduling digraph, a topological ordering is a task sequence that satisfies the precedence constraints Theorem A digraph admits a topological ordering if and only if it is a DAG v 2 v 1 B A B A C D C DAG G v 4 v 5 v 3 E Topological ordering of G

72 b c d e f g a Linear Order h i j k l Alg: DFS Found Not Handled Stack f g e d.. f

73 b c d e f g a Linear Order h i j k l Alg: DFS Found Not Handled Stack When node is popped off stack, insert at front of linearly-ordered to do list. Linear Order:.. f l g e d

74 b c d e f g a Linear Order h i j k l Alg: DFS Found Not Handled Stack g e d Linear Order: l,f

75 BFS Example A A A undiscovered discovered (on Queue) finished unexplored edge L 1 B A C D discovery edge cross edge E F L 0 A L 0 A L 1 B C D L 1 B C D E F E F

76 BFS Example (cont.) L 0 A L 0 A L 1 B C D L 1 B C D E F L 2 E F L 0 A L 0 A L 1 B C D L 1 B C D L 2 E F L 2 E F

77 BFS Example (cont.) L 0 A L 0 A L 1 B C D L 1 B C D L 2 E F L 2 E F L 0 A L 1 B C D L 2 E F

78 Analysis Setting/getting a vertex/edge label takes O(1) time Each vertex is labeled three times once as BLACK (undiscovered) once as RED (discovered, on queue) once as GRAY (finished) Each edge is considered twice (for an undirected graph) Thus BFS runs in O( V + E ) time provided the graph is represented by an adjacency list structure

79 BFS Algorithm with Distances and Predecessors BFS(G,s) Precondition: G is a graph, s is a vertex in G Postcondition: d[u] = shortest distance d[u] and p[u] = predecessor of u on shortest paths from s to each vertex u in G for each vertex u ÎV[G] d[u] p[u] null color[u] = BLACK //initialize vertex colour[s] RED d[s] 0 Q.enqueue(s) while Q ¹ Æ u Q.dequeue() for each v ÎAdj[u] //explore edge (u,v) if color[v] = BLACK colour[v] RED d[v] d[u] + 1 p[v] u colour[u] GRAY Q.enqueue(v)

80 1. Binary Search Trees 2. Sorting 3. Graphs Summary of Topics

Final Exam. CSE 2011 Prof. J. Elder Last Updated: :41 PM

Final Exam. CSE 2011 Prof. J. Elder Last Updated: :41 PM Final Exam Ø Tue, 17 Apr 2012 19:00 22:00 LAS B Ø Closed Book Ø Format similar to midterm Ø Will cover whole course, with emphasis on material after midterm (maps, hashing, binary search trees, sorting,

More information

Final Exam. EECS 2011 Prof. J. Elder - 1 -

Final Exam. EECS 2011 Prof. J. Elder - 1 - Final Exam Ø Wed Apr 11 2pm 5pm Aviva Tennis Centre Ø Closed Book Ø Format similar to midterm Ø Will cover whole course, with emphasis on material after midterm (maps and hash tables, binary search, loop

More information

Comparison Sorts. Chapter 9.4, 12.1, 12.2

Comparison Sorts. Chapter 9.4, 12.1, 12.2 Comparison Sorts Chapter 9.4, 12.1, 12.2 Sorting We have seen the advantage of sorted data representations for a number of applications Sparse vectors Maps Dictionaries Here we consider the problem of

More information

Lecture 10. Elementary Graph Algorithm Minimum Spanning Trees

Lecture 10. Elementary Graph Algorithm Minimum Spanning Trees Lecture 10. Elementary Graph Algorithm Minimum Spanning Trees T. H. Cormen, C. E. Leiserson and R. L. Rivest Introduction to Algorithms, 3rd Edition, MIT Press, 2009 Sungkyunkwan University Hyunseung Choo

More information

Search Trees. Chapter 11

Search Trees. Chapter 11 Search Trees Chapter 6 4 8 9 Outline Binar Search Trees AVL Trees Spla Trees Outline Binar Search Trees AVL Trees Spla Trees Binar Search Trees A binar search tree is a proper binar tree storing ke-value

More information

Minimum Spanning Trees Ch 23 Traversing graphs

Minimum Spanning Trees Ch 23 Traversing graphs Next: Graph Algorithms Graphs Ch 22 Graph representations adjacency list adjacency matrix Minimum Spanning Trees Ch 23 Traversing graphs Breadth-First Search Depth-First Search 11/30/17 CSE 3101 1 Graphs

More information

Elementary Graph Algorithms. Ref: Chapter 22 of the text by Cormen et al. Representing a graph:

Elementary Graph Algorithms. Ref: Chapter 22 of the text by Cormen et al. Representing a graph: Elementary Graph Algorithms Ref: Chapter 22 of the text by Cormen et al. Representing a graph: Graph G(V, E): V set of nodes (vertices); E set of edges. Notation: n = V and m = E. (Vertices are numbered

More information

CSI 604 Elementary Graph Algorithms

CSI 604 Elementary Graph Algorithms CSI 604 Elementary Graph Algorithms Ref: Chapter 22 of the text by Cormen et al. (Second edition) 1 / 25 Graphs: Basic Definitions Undirected Graph G(V, E): V is set of nodes (or vertices) and E is the

More information

Graph Representation

Graph Representation Graph Representation Adjacency list representation of G = (V, E) An array of V lists, one for each vertex in V Each list Adj[u] contains all the vertices v such that there is an edge between u and v Adj[u]

More information

Graphs. Graph G = (V, E) Types of graphs E = O( V 2 ) V = set of vertices E = set of edges (V V)

Graphs. Graph G = (V, E) Types of graphs E = O( V 2 ) V = set of vertices E = set of edges (V V) Graph Algorithms Graphs Graph G = (V, E) V = set of vertices E = set of edges (V V) Types of graphs Undirected: edge (u, v) = (v, u); for all v, (v, v) E (No self loops.) Directed: (u, v) is edge from

More information

Representations of Graphs

Representations of Graphs ELEMENTARY GRAPH ALGORITHMS -- CS-5321 Presentation -- I am Nishit Kapadia Representations of Graphs There are two standard ways: A collection of adjacency lists - they provide a compact way to represent

More information

Basic Graph Algorithms

Basic Graph Algorithms Basic Graph Algorithms 1 Representations of Graphs There are two standard ways to represent a graph G(V, E) where V is the set of vertices and E is the set of edges. adjacency list representation adjacency

More information

Graph: representation and traversal

Graph: representation and traversal Graph: representation and traversal CISC4080, Computer Algorithms CIS, Fordham Univ. Instructor: X. Zhang! Acknowledgement The set of slides have use materials from the following resources Slides for textbook

More information

Design and Analysis of Algorithms

Design and Analysis of Algorithms Design and Analysis of Algorithms CSE 5311 Lecture 18 Graph Algorithm Junzhou Huang, Ph.D. Department of Computer Science and Engineering CSE5311 Design and Analysis of Algorithms 1 Graphs Graph G = (V,

More information

Binary Search Trees > = 2014 Goodrich, Tamassia, Goldwasser. Binary Search Trees 1

Binary Search Trees > = 2014 Goodrich, Tamassia, Goldwasser. Binary Search Trees 1 Binary Search Trees < > = Binary Search Trees 1 Ordered Dictionary (Map) ADT get (k): record with key k put (k,data): add record (k,data) remove (k): delete record with key k smallest(): record with smallest

More information

Elementary Graph Algorithms

Elementary Graph Algorithms Elementary Graph Algorithms Graphs Graph G = (V, E)» V = set of vertices» E = set of edges (V V) Types of graphs» Undirected: edge (u, v) = (v, u); for all v, (v, v) E (No self loops.)» Directed: (u, v)

More information

CS301 - Data Structures Glossary By

CS301 - Data Structures Glossary By CS301 - Data Structures Glossary By Abstract Data Type : A set of data values and associated operations that are precisely specified independent of any particular implementation. Also known as ADT Algorithm

More information

DFS & STRONGLY CONNECTED COMPONENTS

DFS & STRONGLY CONNECTED COMPONENTS DFS & STRONGLY CONNECTED COMPONENTS CS 4407 Search Tree Breadth-First Search (BFS) Depth-First Search (DFS) Depth-First Search (DFS) u d[u]: when u is discovered f[u]: when searching adj of u is finished

More information

Trees and Graphs Shabsi Walfish NYU - Fundamental Algorithms Summer 2006

Trees and Graphs Shabsi Walfish NYU - Fundamental Algorithms Summer 2006 Trees and Graphs Basic Definitions Tree: Any connected, acyclic graph G = (V,E) E = V -1 n-ary Tree: Tree s/t all vertices of degree n+1 A root has degree n Binary Search Tree: A binary tree such that

More information

Chapter 22. Elementary Graph Algorithms

Chapter 22. Elementary Graph Algorithms Graph Algorithms - Spring 2011 Set 7. Lecturer: Huilan Chang Reference: (1) Cormen, Leiserson, Rivest, and Stein, Introduction to Algorithms, 2nd Edition, The MIT Press. (2) Lecture notes from C. Y. Chen

More information

Computer Science & Engineering 423/823 Design and Analysis of Algorithms

Computer Science & Engineering 423/823 Design and Analysis of Algorithms s of s Computer Science & Engineering 423/823 Design and Analysis of Lecture 03 (Chapter 22) Stephen Scott (Adapted from Vinodchandran N. Variyam) 1 / 29 s of s s are abstract data types that are applicable

More information

CSci 231 Final Review

CSci 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 information

CS 341: Algorithms. Douglas R. Stinson. David R. Cheriton School of Computer Science University of Waterloo. February 26, 2019

CS 341: Algorithms. Douglas R. Stinson. David R. Cheriton School of Computer Science University of Waterloo. February 26, 2019 CS 341: Algorithms Douglas R. Stinson David R. Cheriton School of Computer Science University of Waterloo February 26, 2019 D.R. Stinson (SCS) CS 341 February 26, 2019 1 / 296 1 Course Information 2 Introduction

More information

Announcements. HW3 is graded. Average is 81%

Announcements. HW3 is graded. Average is 81% CSC263 Week 9 Announcements HW3 is graded. Average is 81% Announcements Problem Set 4 is due this Tuesday! Due Tuesday (Nov 17) Recap The Graph ADT definition and data structures BFS gives us single-source

More information

COT 6405 Introduction to Theory of Algorithms

COT 6405 Introduction to Theory of Algorithms COT 6405 Introduction to Theory of Algorithms Topic 14. Graph Algorithms 11/7/2016 1 Elementary Graph Algorithms How to represent a graph? Adjacency lists Adjacency matrix How to search a graph? Breadth-first

More information

COMP 251 Winter 2017 Online quizzes with answers

COMP 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 information

Jana Kosecka. Red-Black Trees Graph Algorithms. Many slides here are based on E. Demaine, D. Luebke slides

Jana Kosecka. Red-Black Trees Graph Algorithms. Many slides here are based on E. Demaine, D. Luebke slides Jana Kosecka Red-Black Trees Graph Algorithms Many slides here are based on E. Demaine, D. Luebke slides Binary Search Trees (BSTs) are an important data structure for dynamic sets In addition to satellite

More information

Search Trees - 1 Venkatanatha Sarma Y

Search Trees - 1 Venkatanatha Sarma Y Search Trees - 1 Lecture delivered by: Venkatanatha Sarma Y Assistant Professor MSRSAS-Bangalore 11 Objectives To introduce, discuss and analyse the different ways to realise balanced Binary Search Trees

More information

Graph Algorithms. Definition

Graph Algorithms. Definition Graph Algorithms Many problems in CS can be modeled as graph problems. Algorithms for solving graph problems are fundamental to the field of algorithm design. Definition A graph G = (V, E) consists of

More information

Graph Algorithms: Chapters Part 1: Introductory graph concepts

Graph Algorithms: Chapters Part 1: Introductory graph concepts UMass Lowell Computer Science 91.503 Algorithms Dr. Haim Levkowitz Fall, 2007 Graph Algorithms: Chapters 22-25 Part 1: Introductory graph concepts 1 91.404 Graph Review Elementary Graph Algorithms Minimum

More information

Proof: if not f[u] < d[v], then u still grey while v is being visited. DFS visit(v) will then terminate before DFS visit(u).

Proof: if not f[u] < d[v], then u still grey while v is being visited. DFS visit(v) will then terminate before DFS visit(u). Parenthesis property of DFS discovery and finishing times (Thm 23.6 of CLR): For any two nodes u,v of a directed graph, if d[u] < d[v] (i.e. u discovered before v), either f[v] < f[u] (i.e. visit time

More information

(2,4) Trees. 2/22/2006 (2,4) Trees 1

(2,4) Trees. 2/22/2006 (2,4) Trees 1 (2,4) Trees 9 2 5 7 10 14 2/22/2006 (2,4) Trees 1 Outline and Reading Multi-way search tree ( 10.4.1) Definition Search (2,4) tree ( 10.4.2) Definition Search Insertion Deletion Comparison of dictionary

More information

Course Review for Finals. Cpt S 223 Fall 2008

Course Review for Finals. Cpt S 223 Fall 2008 Course Review for Finals Cpt S 223 Fall 2008 1 Course Overview Introduction to advanced data structures Algorithmic asymptotic analysis Programming data structures Program design based on performance i.e.,

More information

Chapter 2: Basic Data Structures

Chapter 2: Basic Data Structures Chapter 2: Basic Data Structures Basic Data Structures Stacks Queues Vectors, Linked Lists Trees (Including Balanced Trees) Priority Queues and Heaps Dictionaries and Hash Tables Spring 2014 CS 315 2 Two

More information

Taking Stock. IE170: Algorithms in Systems Engineering: Lecture 16. Graph Search Algorithms. Recall BFS

Taking Stock. IE170: Algorithms in Systems Engineering: Lecture 16. Graph Search Algorithms. Recall BFS Taking Stock IE170: Algorithms in Systems Engineering: Lecture 16 Jeff Linderoth Department of Industrial and Systems Engineering Lehigh University February 28, 2007 Last Time The Wonderful World of This

More information

Graph Algorithms. Chapter 22. CPTR 430 Algorithms Graph Algorithms 1

Graph Algorithms. Chapter 22. CPTR 430 Algorithms Graph Algorithms 1 Graph Algorithms Chapter 22 CPTR 430 Algorithms Graph Algorithms Why Study Graph Algorithms? Mathematical graphs seem to be relatively specialized and abstract Why spend so much time and effort on algorithms

More information

Graph representation

Graph representation Graph Algorithms 1 Graph representation Given graph G = (V, E). May be either directed or undirected. Two common ways to represent for algorithms: 1. Adjacency lists. 2. Adjacency matrix. When expressing

More information

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE A6-R3: DATA STRUCTURE THROUGH C LANGUAGE NOTE: 1. There are TWO PARTS in this Module/Paper. PART ONE contains FOUR questions and PART TWO contains FIVE questions. 2. PART ONE is to be answered in the TEAR-OFF

More information

Introduction to Algorithms. Lecture 11

Introduction to Algorithms. Lecture 11 Introduction to Algorithms Lecture 11 Last Time Optimization Problems Greedy Algorithms Graph Representation & Algorithms Minimum Spanning Tree Prim s Algorithm Kruskal s Algorithm 2 Today s Topics Shortest

More information

Computer Science & Engineering 423/823 Design and Analysis of Algorithms

Computer Science & Engineering 423/823 Design and Analysis of Algorithms Computer Science & Engineering 423/823 Design and Analysis of Algorithms Lecture 04 Elementary Graph Algorithms (Chapter 22) Stephen Scott (Adapted from Vinodchandran N. Variyam) sscott@cse.unl.edu Introduction

More information

Scribes: Romil Verma, Juliana Cook (2015), Virginia Williams, Date: May 1, 2017 and Seth Hildick-Smith (2016), G. Valiant (2017), M.

Scribes: Romil Verma, Juliana Cook (2015), Virginia Williams, Date: May 1, 2017 and Seth Hildick-Smith (2016), G. Valiant (2017), M. Lecture 9 Graphs Scribes: Romil Verma, Juliana Cook (2015), Virginia Williams, Date: May 1, 2017 and Seth Hildick-Smith (2016), G. Valiant (2017), M. Wootters (2017) 1 Graphs A graph is a set of vertices

More information

Unit 6 Chapter 15 EXAMPLES OF COMPLEXITY CALCULATION

Unit 6 Chapter 15 EXAMPLES OF COMPLEXITY CALCULATION DESIGN AND ANALYSIS OF ALGORITHMS Unit 6 Chapter 15 EXAMPLES OF COMPLEXITY CALCULATION http://milanvachhani.blogspot.in EXAMPLES FROM THE SORTING WORLD Sorting provides a good set of examples for analyzing

More information

UNIT IV -NON-LINEAR DATA STRUCTURES 4.1 Trees TREE: A tree is a finite set of one or more nodes such that there is a specially designated node called the Root, and zero or more non empty sub trees T1,

More information

Lecture Summary CSC 263H. August 5, 2016

Lecture 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 information

21# 33# 90# 91# 34# # 39# # # 31# 98# 0# 1# 2# 3# 4# 5# 6# 7# 8# 9# 10# #

21# 33# 90# 91# 34# # 39# # # 31# 98# 0# 1# 2# 3# 4# 5# 6# 7# 8# 9# 10# # 1. Prove that n log n n is Ω(n). York University EECS 11Z Winter 1 Problem Set 3 Instructor: James Elder Solutions log n n. Thus n log n n n n n log n n Ω(n).. Show that n is Ω (n log n). We seek a c >,

More information

Selection, Bubble, Insertion, Merge, Heap, Quick Bucket, Radix

Selection, Bubble, Insertion, Merge, Heap, Quick Bucket, Radix Spring 2010 Review Topics Big O Notation Heaps Sorting Selection, Bubble, Insertion, Merge, Heap, Quick Bucket, Radix Hashtables Tree Balancing: AVL trees and DSW algorithm Graphs: Basic terminology and

More information

Outlines: Graphs Part-2

Outlines: Graphs Part-2 Elementary Graph Algorithms PART-2 1 Outlines: Graphs Part-2 Graph Search Methods Breadth-First Search (BFS): BFS Algorithm BFS Example BFS Time Complexity Output of BFS: Shortest Path Breath-First Tree

More information

Algorithm Design and Analysis

Algorithm Design and Analysis Algorithm Design and Analysis LECTURE 7 Greedy Graph Algorithms Topological sort Shortest paths Adam Smith The (Algorithm) Design Process 1. Work out the answer for some examples. Look for a general principle

More information

& ( D. " mnp ' ( ) n 3. n 2. ( ) C. " n

& ( 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 information

CS61BL. Lecture 5: Graphs Sorting

CS61BL. Lecture 5: Graphs Sorting CS61BL Lecture 5: Graphs Sorting Graphs Graphs Edge Vertex Graphs (Undirected) Graphs (Directed) Graphs (Multigraph) Graphs (Acyclic) Graphs (Cyclic) Graphs (Connected) Graphs (Disconnected) Graphs (Unweighted)

More information

Data Structures and Algorithms. Chapter 7. Graphs

Data Structures and Algorithms. Chapter 7. Graphs 1 Data Structures and Algorithms Chapter 7 Werner Nutt 2 Acknowledgments The course follows the book Introduction to Algorithms, by Cormen, Leiserson, Rivest and Stein, MIT Press [CLRST]. Many examples

More information

Graph Theory. Many problems are mapped to graphs. Problems. traffic VLSI circuits social network communication networks web pages relationship

Graph Theory. Many problems are mapped to graphs. Problems. traffic VLSI circuits social network communication networks web pages relationship Graph Graph Usage I want to visit all the known famous places starting from Seoul ending in Seoul Knowledge: distances, costs Find the optimal(distance or cost) path Graph Theory Many problems are mapped

More information

CSE373: Data Structures & Algorithms Lecture 28: Final review and class wrap-up. Nicki Dell Spring 2014

CSE373: Data Structures & Algorithms Lecture 28: Final review and class wrap-up. Nicki Dell Spring 2014 CSE373: Data Structures & Algorithms Lecture 28: Final review and class wrap-up Nicki Dell Spring 2014 Final Exam As also indicated on the web page: Next Tuesday, 2:30-4:20 in this room Cumulative but

More information

Direct Addressing Hash table: Collision resolution how handle collisions Hash Functions:

Direct Addressing Hash table: Collision resolution how handle collisions Hash Functions: Direct Addressing - key is index into array => O(1) lookup Hash table: -hash function maps key to index in table -if universe of keys > # table entries then hash functions collision are guaranteed => need

More information

CISC 320 Introduction to Algorithms Fall Lecture 15 Depth First Search

CISC 320 Introduction to Algorithms Fall Lecture 15 Depth First Search IS 320 Introduction to lgorithms all 2014 Lecture 15 epth irst Search 1 Traversing raphs Systematic search of every edge and vertex of graph (directed or undirected) fficiency: each edge is visited no

More information

AP Computer Science 4325

AP Computer Science 4325 4325 Instructional Unit Algorithm Design Techniques -divide-and-conquer The students will be -Decide whether an algorithm -classroom discussion -backtracking able to classify uses divide-and-conquer, -worksheets

More information

csci 210: Data Structures Graph Traversals

csci 210: Data Structures Graph Traversals csci 210: Data Structures Graph Traversals 1 Depth-first search (DFS) G can be directed or undirected DFS(v) mark v visited for all adjacent edges (v,w) of v do if w is not visited parent(w) = v (v,w)

More information

Presentation for use with the textbook, Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, Merge Sort & Quick Sort

Presentation for use with the textbook, Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, Merge Sort & Quick Sort Presentation for use with the textbook, Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 2015 Merge Sort & Quick Sort 1 Divide-and-Conquer Divide-and conquer is a general algorithm

More information

Graph Algorithms. Andreas Klappenecker. [based on slides by Prof. Welch]

Graph Algorithms. Andreas Klappenecker. [based on slides by Prof. Welch] Graph Algorithms Andreas Klappenecker [based on slides by Prof. Welch] 1 Directed Graphs Let V be a finite set and E a binary relation on V, that is, E VxV. Then the pair G=(V,E) is called a directed graph.

More information

Lecture 9 Graph Traversal

Lecture 9 Graph Traversal Lecture 9 Graph Traversal Euiseong Seo (euiseong@skku.edu) SWE00: Principles in Programming Spring 0 Euiseong Seo (euiseong@skku.edu) Need for Graphs One of unifying themes of computer science Closely

More information

Lecture 7. Transform-and-Conquer

Lecture 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

Part VI Graph algorithms. Chapter 22 Elementary Graph Algorithms Chapter 23 Minimum Spanning Trees Chapter 24 Single-source Shortest Paths

Part VI Graph algorithms. Chapter 22 Elementary Graph Algorithms Chapter 23 Minimum Spanning Trees Chapter 24 Single-source Shortest Paths Part VI Graph algorithms Chapter 22 Elementary Graph Algorithms Chapter 23 Minimum Spanning Trees Chapter 24 Single-source Shortest Paths 1 Chapter 22 Elementary Graph Algorithms Representations of graphs

More information

W4231: Analysis of Algorithms

W4231: Analysis of Algorithms W4231: Analysis of Algorithms 10/21/1999 Definitions for graphs Breadth First Search and Depth First Search Topological Sort. Graphs AgraphG is given by a set of vertices V and a set of edges E. Normally

More information

Sorting and Selection

Sorting and Selection Sorting and Selection Introduction Divide and Conquer Merge-Sort Quick-Sort Radix-Sort Bucket-Sort 10-1 Introduction Assuming we have a sequence S storing a list of keyelement entries. The key of the element

More information

(2,4) Trees Goodrich, Tamassia (2,4) Trees 1

(2,4) Trees Goodrich, Tamassia (2,4) Trees 1 (2,4) Trees 9 2 5 7 10 14 2004 Goodrich, Tamassia (2,4) Trees 1 Multi-Way Search Tree A multi-way search tree is an ordered tree such that Each internal node has at least two children and stores d -1 key-element

More information

Lecture 3: Graphs and flows

Lecture 3: Graphs and flows Chapter 3 Lecture 3: Graphs and flows Graphs: a useful combinatorial structure. Definitions: graph, directed and undirected graph, edge as ordered pair, path, cycle, connected graph, strongly connected

More information

Tutorial. Question There are no forward edges. 4. For each back edge u, v, we have 0 d[v] d[u].

Tutorial. Question There are no forward edges. 4. For each back edge u, v, we have 0 d[v] d[u]. Tutorial Question 1 A depth-first forest classifies the edges of a graph into tree, back, forward, and cross edges. A breadth-first tree can also be used to classify the edges reachable from the source

More information

DATA STRUCTURES AND ALGORITHMS

DATA STRUCTURES AND ALGORITHMS DATA STRUCTURES AND ALGORITHMS For COMPUTER SCIENCE DATA STRUCTURES &. ALGORITHMS SYLLABUS Programming and Data Structures: Programming in C. Recursion. Arrays, stacks, queues, linked lists, trees, binary

More information

Graph Algorithms Using Depth First Search

Graph Algorithms Using Depth First Search Graph Algorithms Using Depth First Search Analysis of Algorithms Week 8, Lecture 1 Prepared by John Reif, Ph.D. Distinguished Professor of Computer Science Duke University Graph Algorithms Using Depth

More information

CS521 \ Notes for the Final Exam

CS521 \ Notes for the Final Exam CS521 \ Notes for final exam 1 Ariel Stolerman Asymptotic Notations: CS521 \ Notes for the Final Exam Notation Definition Limit Big-O ( ) Small-o ( ) Big- ( ) Small- ( ) Big- ( ) Notes: ( ) ( ) ( ) ( )

More information

csci 210: Data Structures Graph Traversals

csci 210: Data Structures Graph Traversals csci 210: Data Structures Graph Traversals Graph traversal (BFS and DFS) G can be undirected or directed We think about coloring each vertex WHITE before we start GRAY after we visit a vertex but before

More information

Taking Stock. IE170: Algorithms in Systems Engineering: Lecture 17. Depth-First Search. DFS (Initialize and Go) Last Time Depth-First Search

Taking Stock. IE170: Algorithms in Systems Engineering: Lecture 17. Depth-First Search. DFS (Initialize and Go) Last Time Depth-First Search Taking Stock IE170: Algorithms in Systems Engineering: Lecture 17 Jeff Linderoth Department of Industrial and Systems Engineering Lehigh University March 2, 2007 Last Time Depth-First Search This Time:

More information

Treaps. 1 Binary Search Trees (BSTs) CSE341T/CSE549T 11/05/2014. Lecture 19

Treaps. 1 Binary Search Trees (BSTs) CSE341T/CSE549T 11/05/2014. Lecture 19 CSE34T/CSE549T /05/04 Lecture 9 Treaps Binary Search Trees (BSTs) Search trees are tree-based data structures that can be used to store and search for items that satisfy a total order. There are many types

More information

Algorithms and Data Structures (INF1) Lecture 15/15 Hua Lu

Algorithms and Data Structures (INF1) Lecture 15/15 Hua Lu Algorithms and Data Structures (INF1) Lecture 15/15 Hua Lu Department of Computer Science Aalborg University Fall 2007 This Lecture Minimum spanning trees Definitions Kruskal s algorithm Prim s algorithm

More information

Data Structure. IBPS SO (IT- Officer) Exam 2017

Data Structure. IBPS SO (IT- Officer) Exam 2017 Data Structure IBPS SO (IT- Officer) Exam 2017 Data Structure: In computer science, a data structure is a way of storing and organizing data in a computer s memory so that it can be used efficiently. Data

More information

Data Structures Question Bank Multiple Choice

Data Structures Question Bank Multiple Choice Section 1. Fundamentals: Complexity, Algorthm Analysis 1. An algorithm solves A single problem or function Multiple problems or functions Has a single programming language implementation 2. A solution

More information

22.3 Depth First Search

22.3 Depth First Search 22.3 Depth First Search Depth-First Search(DFS) always visits a neighbour of the most recently visited vertex with an unvisited neighbour. This means the search moves forward when possible, and only backtracks

More information

Graphs. CSE 2320 Algorithms and Data Structures Alexandra Stefan and Vassilis Athitsos University of Texas at Arlington

Graphs. CSE 2320 Algorithms and Data Structures Alexandra Stefan and Vassilis Athitsos University of Texas at Arlington Graphs CSE 2320 Algorithms and Data Structures Alexandra Stefan and Vassilis Athitsos University of Texas at Arlington 1 Representation Adjacency matrix??adjacency lists?? Review Graphs (from CSE 2315)

More information

Fundamentals of Data Structure

Fundamentals of Data Structure Fundamentals of Data Structure Set-1 1. Which if the following is/are the levels of implementation of data structure A) Abstract level B) Application level C) Implementation level D) All of the above 2.

More information

Trees. (Trees) Data Structures and Programming Spring / 28

Trees. (Trees) Data Structures and Programming Spring / 28 Trees (Trees) Data Structures and Programming Spring 2018 1 / 28 Trees A tree is a collection of nodes, which can be empty (recursive definition) If not empty, a tree consists of a distinguished node r

More information

Solutions to relevant spring 2000 exam problems

Solutions to relevant spring 2000 exam problems Problem 2, exam Here s Prim s algorithm, modified slightly to use C syntax. MSTPrim (G, w, r): Q = V[G]; for (each u Q) { key[u] = ; key[r] = 0; π[r] = 0; while (Q not empty) { u = ExtractMin (Q); for

More information

Taking Stock. Last Time Flows. This Time Review! 1 Characterize the structure of an optimal solution

Taking Stock. Last Time Flows. This Time Review! 1 Characterize the structure of an optimal solution Taking Stock IE170: Algorithms in Systems Engineering: Lecture 26 Jeff Linderoth Last Time Department of Industrial and Systems Engineering Lehigh University April 2, 2007 This Time Review! Jeff Linderoth

More information

1) What is the primary purpose of template functions? 2) Suppose bag is a template class, what is the syntax for declaring a bag b of integers?

1) What is the primary purpose of template functions? 2) Suppose bag is a template class, what is the syntax for declaring a bag b of integers? Review for Final (Chapter 6 13, 15) 6. Template functions & classes 1) What is the primary purpose of template functions? A. To allow a single function to be used with varying types of arguments B. To

More information

The ADT priority queue Orders its items by a priority value The first item removed is the one having the highest priority value

The ADT priority queue Orders its items by a priority value The first item removed is the one having the highest priority value The ADT priority queue Orders its items by a priority value The first item removed is the one having the highest priority value 1 Possible implementations Sorted linear implementations o Appropriate if

More information

CS Elementary Graph Algorithms

CS Elementary Graph Algorithms CS43-09 Elementary Graph Algorithms Outline Representation of Graphs Instructor: Fei Li Room 443 ST II Office hours: Tue. & Thur. 1:30pm - 2:30pm or by appointments lifei@cs.gmu.edu with subject: CS43

More information

CS Elementary Graph Algorithms

CS Elementary Graph Algorithms CS483-09 Elementary Graph Algorithms Instructor: Fei Li Room 443 ST II Office hours: Tue. & Thur. 1:30pm - 2:30pm or by appointments lifei@cs.gmu.edu with subject: CS483 http://www.cs.gmu.edu/ lifei/teaching/cs483_fall07/

More information

CS2223: Algorithms Sorting Algorithms, Heap Sort, Linear-time sort, Median and Order Statistics

CS2223: Algorithms Sorting Algorithms, Heap Sort, Linear-time sort, Median and Order Statistics CS2223: Algorithms Sorting Algorithms, Heap Sort, Linear-time sort, Median and Order Statistics 1 Sorting 1.1 Problem Statement You are given a sequence of n numbers < a 1, a 2,..., a n >. You need to

More information

Sorting. Outline. Sorting with a priority queue Selection-sort Insertion-sort Heap Sort Quick Sort

Sorting. Outline. Sorting with a priority queue Selection-sort Insertion-sort Heap Sort Quick Sort Sorting Hiroaki Kobayashi 1 Outline Sorting with a priority queue Selection-sort Insertion-sort Heap Sort Quick Sort Merge Sort Lower Bound on Comparison-Based Sorting Bucket Sort and Radix Sort Hiroaki

More information

DIVIDE AND CONQUER ALGORITHMS ANALYSIS WITH RECURRENCE EQUATIONS

DIVIDE AND CONQUER ALGORITHMS ANALYSIS WITH RECURRENCE EQUATIONS CHAPTER 11 SORTING ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA AND MOUNT (WILEY 2004) AND SLIDES FROM NANCY M. AMATO AND

More information

CSC Design and Analysis of Algorithms. Lecture 7. Transform and Conquer I Algorithm Design Technique. Transform and Conquer

CSC Design and Analysis of Algorithms. Lecture 7. Transform and Conquer I Algorithm Design Technique. Transform and Conquer // CSC - Design and Analysis of Algorithms Lecture 7 Transform and Conquer I Algorithm Design Technique Transform and Conquer This group of techniques solves a problem by a transformation to a simpler/more

More information

( ) ( ) C. " 1 n. ( ) $ f n. ( ) B. " log( n! ) ( ) and that you already know ( ) ( ) " % g( n) ( ) " #&

( ) ( ) 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

Graphs ORD SFO LAX DFW. Data structures and Algorithms

Graphs ORD SFO LAX DFW. Data structures and Algorithms SFO 143 ORD 337 1743 02 Graphs LAX 1233 DFW Data structures and Algorithms Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++ Goodrich, Tamassia and

More information

1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1

1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1 Asymptotics, Recurrence and Basic Algorithms 1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1 1. O(logn) 2. O(n) 3. O(nlogn) 4. O(n 2 ) 5. O(2 n ) 2. [1 pt] What is the solution

More information

logn D. Θ C. Θ n 2 ( ) ( ) f n B. nlogn Ο n2 n 2 D. Ο & % ( C. Θ # ( D. Θ n ( ) Ω f ( n)

logn 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 information

Algorithm Design and Analysis

Algorithm Design and Analysis Algorithm Design and Analysis LECTURE 3 Data Structures Graphs Traversals Strongly connected components Sofya Raskhodnikova L3.1 Measuring Running Time Focus on scalability: parameterize the running time

More information

CS Data Structures and Algorithm Analysis

CS Data Structures and Algorithm Analysis CS 483 - Data Structures and Algorithm Analysis Lecture VI: Chapter 5, part 2; Chapter 6, part 1 R. Paul Wiegand George Mason University, Department of Computer Science March 8, 2006 Outline 1 Topological

More information

Undirected Graphs. DSA - lecture 6 - T.U.Cluj-Napoca - M. Joldos 1

Undirected Graphs. DSA - lecture 6 - T.U.Cluj-Napoca - M. Joldos 1 Undirected Graphs Terminology. Free Trees. Representations. Minimum Spanning Trees (algorithms: Prim, Kruskal). Graph Traversals (dfs, bfs). Articulation points & Biconnected Components. Graph Matching

More information

Unit 2: Algorithmic Graph Theory

Unit 2: Algorithmic Graph Theory Unit 2: Algorithmic Graph Theory Course contents: Introduction to graph theory Basic graph algorithms Reading Chapter 3 Reference: Cormen, Leiserson, and Rivest, Introduction to Algorithms, 2 nd Ed., McGraw

More information

Bioinformatics Programming. EE, NCKU Tien-Hao Chang (Darby Chang)

Bioinformatics Programming. EE, NCKU Tien-Hao Chang (Darby Chang) Bioinformatics Programming EE, NCKU Tien-Hao Chang (Darby Chang) 1 Tree 2 A Tree Structure A tree structure means that the data are organized so that items of information are related by branches 3 Definition

More information

COMP251: Algorithms and Data Structures. Jérôme Waldispühl School of Computer Science McGill University

COMP251: Algorithms and Data Structures. Jérôme Waldispühl School of Computer Science McGill University COMP251: Algorithms and Data Structures Jérôme Waldispühl School of Computer Science McGill University About Me Jérôme Waldispühl Associate Professor of Computer Science I am conducting research in Bioinformatics

More information