# DATA STRUCTURES NOTES FOR THE FINAL EXAM SUMMER 2002 Michael Knopf

Save this PDF as:

Size: px
Start display at page:

Download "DATA STRUCTURES NOTES FOR THE FINAL EXAM SUMMER 2002 Michael Knopf mknopf@ufl.edu"

## Transcription

2 Linked adjacency lists: each adjacency list is a chain, there are 2e node in an undirected graph and e node in a directed graph (please see page 10 for an example) Array adjacency lists: each adjacency list is an array, the number of elements is 2e in an undirected graph and e in a directed graph Graph search methods: a vertex u is reachable from vertex b iff there is a path from u to b o A search method starts at a given vertex v and visits/labels/marks every vertex that is reachable from v o Many graph problems are solved using search methods Breadth-first search: (Pseudocode and the actual code are found on page 8) Visit the start vertex and use a FIFO queue Repeatedly remove a vertex from the queue, visit its unvisited adjacent vertices putting the newly visited vertices into the queue, when the queue is empty the search terminates All vertices that are reachable from the start vertex (including the start vertex) are visited Depth-first search: Has the same complexity as breadth-first search Has the same properties with respect to path finding, connected components, and spanning trees Edges used to reach unvisited vertices define a depth-first spanning tree when the graph is connected There are problems were each method performs better than the other The code for depth-first search is given below: Page 2 public int newdfs(int thev, int thek) if( thek <= 0 thek > vertices()) //no vertex to return return 0; else //initialize static variables count = 0; targetcount = thek; label = new boolean[vertices() + 1]; //the default value is false return newdfs(thev); //making the call to the static method newdfs(thev) /** the private method that does the actual depth-first traversal */ private static int newdfs(int v) //return vertex if found //reached a new vertex count++; if (count == targetcount) return v: //we found the vertex we were looking for else //we need to reach more vertices label[v] = true; Iterator iv = iterator(v); while(iv.hasnext()) //visit an adjacent vertex of v int u = ((EdgeNode.iv.next()).vertex; if(!label[u]) //u is a new vertex int w = newdfs(u); if(w>0) //the target vertex has been found return w;

5 1 If (S1!= S2) union(s1, S2); Prim s method: Start with a 1-vertex tree and grow it into an n-vertex tree by repeatedly adding a vertex and an edge (if we have a choice then add the least costly edge) (See page 10 for an example). This method is the fastest Sollin s method: Start with an n-vertex forest. Each component selects a least-cost edge to connect to another component. Eliminate duplicate selections and possible cycles. This process is repeated until there is only 1 component left. Example given below This one is chosen first: because it has the least cost 2 8 This one is last This one is 3rd 7 This is chosen 2 nd Page 5 Edge rejection greedy strategy: Starting with a connected graph, repeatedly find a cycle and eliminate the highest cost edge on this cycle, stop when no cycle remains Considering the edges in descending order of cost, eliminate an edge provided this leaves behind a connected graph. o Divide and conquer: a large instance is solved as follows Divide the large instance into smaller instances (performance is best when the smaller instances that result from the divide step are approximately the same size) Solve the smaller instances somehow, such as continuing to break them into smaller instances until there is only one element per instance. For Example: Please see the diagram below: imagine a tree where the root is the original problem and consists of 10 integers in random order, we wish to sort these integers into decreasing order. We first break up the root into sub-trees that contain portions of the root, now we break up these sub-trees into even smaller groups of integers until we finally reach the leaves, which have only single integer. At this time we compare two leaves and sort them accordingly. Array [2, 4, 1, 19, 22, 33, 42, 61, 8, 7] 2, 4, 1, 19, 22, 33, 42, 61, 8, 7 2, 4, 1, 19, 22 33, 42, 61, 8, 7 [4, 2, 1] Now compare 2, 4, 1 19, 22 33, 42, 61 8, 7 [4, 2] to [1] and store in the root 2, , [4, 2] is larger than 2 so we store [4, 2] in the root Now that we have broken the problem down into much smaller problems we compare the leaves and place them into their root in the proper order. After the divide and conquer merge sort terminates the array would be as follows: Array [61, 42, 33, 22, 19, 8, 7, 2, 2, 1] Combine the results of the smaller instances to obtain the results of the larger instance The working of a recursive divide-and-conquer algorithm can be described as a tree a recursion tree The algorithm moves down the recursion tree dividing large instances into smaller ones The leaves represent small instances The recursive algorithm moves back up the tree combining the results from the sub-trees o Natural merge sort: ƒ The initially sorted segments are the naturally occurring sorted segments in the input

6 The segment boundaries are found by evaluating the items in the input with the criteria of a[i] > a[i+1] for Example: If the input array had the following values: [8, 9, 10, 2, 5, 7, 9, 11, 13, 15, 6, 12, 14] then we would have 3 natural segments which are 8, 9, 10 because 10 > 2 but 2 is not > 5 2, 5, 7, 9, 11, 13, 15 again 15 > 6 but 6 is not > 12 6, 12, 14 The benefit of the natural merge sort is that it can reduce the number of passes that need to be taken with other methods, in the above situation we would only have to passes; the first to merge 8, 9, 10 with 2, 5, 7, 9, 11, 13, 15 which results in 2, 5, 7, 8, 9, 10, 11, 13, 15 and the second pass to merge the result with the last segment of 6, 12, 14 which results in the sorted array [2, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] o Quick sort: Small instances are when n<=1 where n is an element (remember that every instance this small is considered already sorted) ƒ To sort the large instances select a pivot element from the n elements ƒ Partition the n elements into 3 groups (left, middle, and right) where the middle group contains only the pivot elements, all the left groups elements are smaller than or equal to the middle groups elements, and the right groups elements are larger than or equal to the middle groups elements. The middle group only contains one element, the pivot point. ƒ Use recursion to sort the left and right groups ƒ The answer is the sorted left group, followed by the middle group, followed by the right group ƒ REMEMBER the pivot is the leftmost element in the list to be sorted, so it would be position zero in an array, or we could randomly select a pivot point, or the median-of-three rule. If we randomly choose our pivot point or we use the median-ofthree rule we do not need to change our quick sort code, we simply swap the positions of the pivot point and position zero in the array. ƒ The median-of three rule: for this rule the pivot is chosen to be the median of the three elements a[leftend], a[(leftend+ rightend)/2], a[rightend]. For Example if these elements have keys 5, 9, 7, then a[rightend] is used as the value of pivot because 5 <= 7 <=9 (in other words ask yourself what is the key in a[0], a[a.length-1], and a[(a.length-1)/2]. Which ever key is the middle value is chosen as the pivot point). Once the pivot has been chosen simply swap its position with the first position in the array and then proceed from this point as if we were using the leftmost element rule (see example below). ƒ Example: using a leftmost element pivot point strategy: we have an array containing the following elements: [6, 2, 8, 5, 11, 10, 4, 1, 9, 7, 3] we chose the first element = 6 as the pivot point. We then compare all other array positions with 6, if they are < = 6 then they are placed into the left segment, if they are > = 6 they are placed in the right segment. The left and right segments are then sorted recursively in exactly the same manner. So the array [2, 5, 4, 1, 3] = left segment [8, 11, 10, 9, 7] = right segment and [6] = the middle segment. Next we sort both the left and right segments recursively, so sorting the left segment results in [2] being chosen as the pivot point, [1] = left segment, [5, 4, 3] = right segment and the process continues. This can be done using 2 arrays (array A and B) that are of the same size, where the left segment of array A is stored in the left half of the array B and the right segment of array A is stored in the right half of array B, and the pivot point being stored in the very middle. When the recursion finally terminates we have a sorted array done in O(n log n) which is just awesome compared to O(n 2 ). ƒ We can also do in-place swaping instead of using 2 arrays (see the example below). After determining the pivot point we find the leftmost element (called bigelement) that is larger then the pivot, and the smallest rightmost element (called smallelement) that is smaller then the pivot, then swap there array positions (provided that the larger element is to the left of the smaller one). When the recursion terminates we swap the pivot with the last smallelement ƒ Example: in-place swaping: let the color = the pivot point, the color = the bigelement, and the color = the smallelement. We have the following array: [3, 4, 9, 1, 16, 11, 23, 8] 3 = pivot, 4 = bigelement, and 1 = smallelement. We perform the swap and the array looks as follows: [3, 1, 9, 4, 16, 11, 23, 8] Now we do it again: 9 = bigelement, 4 = smallelement, and the pivot doesn t change, so the swap yields the following: [3, 1, 4, 9, 16, 11, 23, 8] Now we do it again: 9 = bigelement, 1 = smallelement, whoop s! bigelement is NOT to the left of smallelement so the recursion terminates, we swap the pivot = 3 and smallelement = 1 which yields the following: [1, 3, 4, 9, 16, 11, 23, 8] and then we return the (somewhat) sorted array to its caller. As you can see once the final array is returned it will be sorted (in increasing order, but could just as easily be in decreasing order). Page 6 Things to study further: Know the code to test a graph for a bipartite structure (the code is given on the next page) a question involving bipartite graphs may be on the exam Know how to create an adjacency matrix (for both weighted, un-weighted, directed, and un-directed) from a given graph and vise versa.

10 A complete digraph digraph bipartite graph complete graph A digraph is strongly connected iff it contains a directed path from i to j and from j to i for every pair of distinct vertices i and j Page The weighted graph above is used in the next 3 examples Example: kruskal s method: construct a min cost spanning tree (we end up with n 1 edges) We start with an n vertex forest, consider edges in ascending order of cost and don t create cycles This one is chosen first because is has the least cost = 1 (ties are broken arbitrarily) This one is chosen next because is has the 2nd least cost = This one is chosen 5th its cost = 3 This one is chosen 7th its cost = 5 This one is chosen 4th its cost = 3 This one is chosen 3 rd its cost = 2 This one is chosen 6th its cost = 4 Example: Prim s method: construct a min cost spanning tree (assuming we were instructed to start at vertex # 1) Example: linked adjacency representation: each adjacency list is a chain; there are 2e node in an undirected graph and e node in a directed graph. Each object is represented as an array of chains where each chain is of type Chain

11 Weight of edge Vertex (node) number

### Social Media Mining. Graph Essentials

Graph Essentials Graph Basics Measures Graph and Essentials Metrics 2 2 Nodes and Edges A network is a graph nodes, actors, or vertices (plural of vertex) Connections, edges or ties Edge Node Measures

### CSE 326, Data Structures. Sample Final Exam. Problem Max Points Score 1 14 (2x7) 2 18 (3x6) 3 4 4 7 5 9 6 16 7 8 8 4 9 8 10 4 Total 92.

Name: Email ID: CSE 326, Data Structures Section: Sample Final Exam Instructions: The exam is closed book, closed notes. Unless otherwise stated, N denotes the number of elements in the data structure

### CMSC 451: Graph Properties, DFS, BFS, etc.

CMSC 451: Graph Properties, DFS, BFS, etc. Slides By: Carl Kingsford Department of Computer Science University of Maryland, College Park Based on Chapter 3 of Algorithm Design by Kleinberg & Tardos. Graphs

### 2. (a) Explain the strassen s matrix multiplication. (b) Write deletion algorithm, of Binary search tree. [8+8]

Code No: R05220502 Set No. 1 1. (a) Describe the performance analysis in detail. (b) Show that f 1 (n)+f 2 (n) = 0(max(g 1 (n), g 2 (n)) where f 1 (n) = 0(g 1 (n)) and f 2 (n) = 0(g 2 (n)). [8+8] 2. (a)

### GRAPH THEORY and APPLICATIONS. Trees

GRAPH THEORY and APPLICATIONS Trees Properties Tree: a connected graph with no cycle (acyclic) Forest: a graph with no cycle Paths are trees. Star: A tree consisting of one vertex adjacent to all the others.

### Theorem A graph T is a tree if, and only if, every two distinct vertices of T are joined by a unique path.

Chapter 3 Trees Section 3. Fundamental Properties of Trees Suppose your city is planning to construct a rapid rail system. They want to construct the most economical system possible that will meet the

### Long questions answer Advanced Mathematics for Computer Application If P= , find BT. 19. If B = 1 0, find 2B and -3B.

Unit-1: Matrix Algebra Short questions answer 1. What is Matrix? 2. Define the following terms : a) Elements matrix b) Row matrix c) Column matrix d) Diagonal matrix e) Scalar matrix f) Unit matrix OR

### IE 680 Special Topics in Production Systems: Networks, Routing and Logistics*

IE 680 Special Topics in Production Systems: Networks, Routing and Logistics* Rakesh Nagi Department of Industrial Engineering University at Buffalo (SUNY) *Lecture notes from Network Flows by Ahuja, Magnanti

### 12 Abstract Data Types

12 Abstract Data Types 12.1 Source: Foundations of Computer Science Cengage Learning Objectives After studying this chapter, the student should be able to: Define the concept of an abstract data type (ADT).

### Exam study sheet for CS2711. List of topics

Exam study sheet for CS2711 Here is the list of topics you need to know for the final exam. For each data structure listed below, make sure you can do the following: 1. Give an example of this data structure

### 1. Sorting (assuming sorting into ascending order) a) BUBBLE SORT

DECISION 1 Revision Notes 1. Sorting (assuming sorting into ascending order) a) BUBBLE SORT Make sure you show comparisons clearly and label each pass First Pass 8 4 3 6 1 4 8 3 6 1 4 3 8 6 1 4 3 6 8 1

### Graph. Consider a graph, G in Fig Then the vertex V and edge E can be represented as:

Graph A graph G consist of 1. Set of vertices V (called nodes), (V = {v1, v2, v3, v4...}) and 2. Set of edges E (i.e., E {e1, e2, e3...cm} A graph can be represents as G = (V, E), where V is a finite and

### Lecture Notes on Spanning Trees

Lecture Notes on Spanning Trees 15-122: Principles of Imperative Computation Frank Pfenning Lecture 26 April 26, 2011 1 Introduction In this lecture we introduce graphs. Graphs provide a uniform model

### Euclidean Minimum Spanning Trees Based on Well Separated Pair Decompositions Chaojun Li. Advised by: Dave Mount. May 22, 2014

Euclidean Minimum Spanning Trees Based on Well Separated Pair Decompositions Chaojun Li Advised by: Dave Mount May 22, 2014 1 INTRODUCTION In this report we consider the implementation of an efficient

### Dynamic Programming. Applies when the following Principle of Optimality

Dynamic Programming Applies when the following Principle of Optimality holds: In an optimal sequence of decisions or choices, each subsequence must be optimal. Translation: There s a recursive solution.

### 2.3 Scheduling jobs on identical parallel machines

2.3 Scheduling jobs on identical parallel machines There are jobs to be processed, and there are identical machines (running in parallel) to which each job may be assigned Each job = 1,,, must be processed

### 1 2-3 Trees: The Basics

CS10: Data Structures and Object-Oriented Design (Fall 2013) November 1, 2013: 2-3 Trees: Inserting and Deleting Scribes: CS 10 Teaching Team Lecture Summary In this class, we investigated 2-3 Trees in

### Homework MA 725 Spring, 2012 C. Huneke SELECTED ANSWERS

Homework MA 725 Spring, 2012 C. Huneke SELECTED ANSWERS 1.1.25 Prove that the Petersen graph has no cycle of length 7. Solution: There are 10 vertices in the Petersen graph G. Assume there is a cycle C

### Data Structures and Algorithms Written Examination

Data Structures and Algorithms Written Examination 22 February 2013 FIRST NAME STUDENT NUMBER LAST NAME SIGNATURE Instructions for students: Write First Name, Last Name, Student Number and Signature where

### Sample Questions Csci 1112 A. Bellaachia

Sample Questions Csci 1112 A. Bellaachia Important Series : o S( N) 1 2 N N i N(1 N) / 2 i 1 o Sum of squares: N 2 N( N 1)(2N 1) N i for large N i 1 6 o Sum of exponents: N k 1 k N i for large N and k

### The Union-Find Problem Kruskal s algorithm for finding an MST presented us with a problem in data-structure design. As we looked at each edge,

The Union-Find Problem Kruskal s algorithm for finding an MST presented us with a problem in data-structure design. As we looked at each edge, cheapest first, we had to determine whether its two endpoints

### Part 2: Community Detection

Chapter 8: Graph Data Part 2: Community Detection Based on Leskovec, Rajaraman, Ullman 2014: Mining of Massive Datasets Big Data Management and Analytics Outline Community Detection - Social networks -

### Converting a Number from Decimal to Binary

Converting a Number from Decimal to Binary Convert nonnegative integer in decimal format (base 10) into equivalent binary number (base 2) Rightmost bit of x Remainder of x after division by two Recursive

### COT5405 Analysis of Algorithms Homework 3 Solutions

COT0 Analysis of Algorithms Homework 3 Solutions. Prove or give a counter example: (a) In the textbook, we have two routines for graph traversal - DFS(G) and BFS(G,s) - where G is a graph and s is any

### Merge Sort. 2004 Goodrich, Tamassia. Merge Sort 1

Merge Sort 7 2 9 4 2 4 7 9 7 2 2 7 9 4 4 9 7 7 2 2 9 9 4 4 Merge Sort 1 Divide-and-Conquer Divide-and conquer is a general algorithm design paradigm: Divide: divide the input data S in two disjoint subsets

### Home Page. Data Structures. Title Page. Page 1 of 24. Go Back. Full Screen. Close. Quit

Data Structures Page 1 of 24 A.1. Arrays (Vectors) n-element vector start address + ielementsize 0 +1 +2 +3 +4... +n-1 start address continuous memory block static, if size is known at compile time dynamic,

### Homework 15 Solutions

PROBLEM ONE (Trees) Homework 15 Solutions 1. Recall the definition of a tree: a tree is a connected, undirected graph which has no cycles. Which of the following definitions are equivalent to this definition

### Krishna Institute of Engineering & Technology, Ghaziabad Department of Computer Application MCA-213 : DATA STRUCTURES USING C

Tutorial#1 Q 1:- Explain the terms data, elementary item, entity, primary key, domain, attribute and information? Also give examples in support of your answer? Q 2:- What is a Data Type? Differentiate

### 5. A full binary tree with n leaves contains [A] n nodes. [B] log n 2 nodes. [C] 2n 1 nodes. [D] n 2 nodes.

1. The advantage of.. is that they solve the problem if sequential storage representation. But disadvantage in that is they are sequential lists. [A] Lists [B] Linked Lists [A] Trees [A] Queues 2. The

### International Journal of Software and Web Sciences (IJSWS) www.iasir.net

International Association of Scientific Innovation and Research (IASIR) (An Association Unifying the Sciences, Engineering, and Applied Research) ISSN (Print): 2279-0063 ISSN (Online): 2279-0071 International

### Chapter 2 Paths and Searching

Chapter 2 Paths and Searching Section 2.1 Distance Almost every day you face a problem: You must leave your home and go to school. If you are like me, you are usually a little late, so you want to take

### Graph Algorithms. Ananth Grama, Anshul Gupta, George Karypis, and Vipin Kumar

Graph Algorithms Ananth Grama, Anshul Gupta, George Karypis, and Vipin Kumar To accompany the text Introduction to Parallel Computing, Addison Wesley, 3. Topic Overview Definitions and Representation Minimum

### Chapter There are non-isomorphic rooted trees with four vertices. Ans: 4.

Use the following to answer questions 1-26: In the questions below fill in the blanks. Chapter 10 1. If T is a tree with 999 vertices, then T has edges. 998. 2. There are non-isomorphic trees with four

### CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team

CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team Lecture Summary In this lecture, we learned about the ADT Priority Queue. A

### CMPT 280 Intermediate Data Structures and Algorithms

The University of Saskatchewan Saskatoon, Canada Department of Computer Science CMPT 280 Intermediate Data Structures and Algorithms 1 Purpose Assignment 5 Date Due: February 23, 2010, 10:00pm The purpose

### A. V. Gerbessiotis CS Spring 2014 PS 3 Mar 24, 2014 No points

A. V. Gerbessiotis CS 610-102 Spring 2014 PS 3 Mar 24, 2014 No points Problem 1. Suppose that we insert n keys into a hash table of size m using open addressing and uniform hashing. Let p(n, m) be the

### Data Structure [Question Bank]

Unit I (Analysis of Algorithms) 1. What are algorithms and how they are useful? 2. Describe the factor on best algorithms depends on? 3. Differentiate: Correct & Incorrect Algorithms? 4. Write short note:

### Binary Heaps * * * * * * * / / \ / \ / \ / \ / \ * * * * * * * * * * * / / \ / \ / / \ / \ * * * * * * * * * *

Binary Heaps A binary heap is another data structure. It implements a priority queue. Priority Queue has the following operations: isempty add (with priority) remove (highest priority) peek (at highest

### CS2 Algorithms and Data Structures Note 11. Breadth-First Search and Shortest Paths

CS2 Algorithms and Data Structures Note 11 Breadth-First Search and Shortest Paths In this last lecture of the CS2 Algorithms and Data Structures thread we will consider the problem of computing distances

### CMPS 102 Solutions to Homework 1

CMPS 0 Solutions to Homework Lindsay Brown, lbrown@soe.ucsc.edu September 9, 005 Problem..- p. 3 For inputs of size n insertion sort runs in 8n steps, while merge sort runs in 64n lg n steps. For which

### Approximation Algorithms

Approximation Algorithms or: How I Learned to Stop Worrying and Deal with NP-Completeness Ong Jit Sheng, Jonathan (A0073924B) March, 2012 Overview Key Results (I) General techniques: Greedy algorithms

### Definition. E.g. : Attempting to represent a transport link data with a tree structure:

The ADT Graph Recall the ADT binary tree: a tree structure used mainly to represent 1 to 2 relations, i.e. each item has at most two immediate successors. Limitations of tree structures: an item in a tree

### Lesson 3. Algebraic graph theory. Sergio Barbarossa. Rome - February 2010

Lesson 3 Algebraic graph theory Sergio Barbarossa Basic notions Definition: A directed graph (or digraph) composed by a set of vertices and a set of edges We adopt the convention that the information flows

### Graphs and Network Flows IE411 Lecture 1

Graphs and Network Flows IE411 Lecture 1 Dr. Ted Ralphs IE411 Lecture 1 1 References for Today s Lecture Required reading Sections 17.1, 19.1 References AMO Chapter 1 and Section 2.1 and 2.2 IE411 Lecture

### Chapter 4. Trees. 4.1 Basics

Chapter 4 Trees 4.1 Basics A tree is a connected graph with no cycles. A forest is a collection of trees. A vertex of degree one, particularly in a tree, is called a leaf. Trees arise in a variety of applications.

### Solutions to Exercises 8

Discrete Mathematics Lent 2009 MA210 Solutions to Exercises 8 (1) Suppose that G is a graph in which every vertex has degree at least k, where k 1, and in which every cycle contains at least 4 vertices.

### Binary Heap Algorithms

CS Data Structures and Algorithms Lecture Slides Wednesday, April 5, 2009 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks CHAPPELLG@member.ams.org 2005 2009 Glenn G. Chappell

### Algorithms and data structures

Algorithms and data structures This course will examine various data structures for storing and accessing information together with relationships between the items being stored, and algorithms for efficiently

### Solutions to Homework 6

Solutions to Homework 6 Debasish Das EECS Department, Northwestern University ddas@northwestern.edu 1 Problem 5.24 We want to find light spanning trees with certain special properties. Given is one example

### CS268: Geometric Algorithms Handout #5 Design and Analysis Original Handout #15 Stanford University Tuesday, 25 February 1992

CS268: Geometric Algorithms Handout #5 Design and Analysis Original Handout #15 Stanford University Tuesday, 25 February 1992 Original Lecture #6: 28 January 1991 Topics: Triangulating Simple Polygons

### Graph definition Degree, in, out degree, oriented graph. Complete, regular, bipartite graph. Graph representation, connectivity, adjacency.

Mária Markošová Graph definition Degree, in, out degree, oriented graph. Complete, regular, bipartite graph. Graph representation, connectivity, adjacency. Isomorphism of graphs. Paths, cycles, trials.

### AS-2261 M.Sc.(First Semester) Examination-2013 Paper -fourth Subject-Data structure with algorithm

AS-2261 M.Sc.(First Semester) Examination-2013 Paper -fourth Subject-Data structure with algorithm Time: Three Hours] [Maximum Marks: 60 Note Attempts all the questions. All carry equal marks Section A

### Divide-and-Conquer. Three main steps : 1. divide; 2. conquer; 3. merge.

Divide-and-Conquer Three main steps : 1. divide; 2. conquer; 3. merge. 1 Let I denote the (sub)problem instance and S be its solution. The divide-and-conquer strategy can be described as follows. Procedure

### Introduction to Algorithms Review information for Prelim 1 CS 4820, Spring 2010 Distributed Wednesday, February 24

Introduction to Algorithms Review information for Prelim 1 CS 4820, Spring 2010 Distributed Wednesday, February 24 The final exam will cover seven topics. 1. greedy algorithms 2. divide-and-conquer algorithms

### Any two nodes which are connected by an edge in a graph are called adjacent node.

. iscuss following. Graph graph G consist of a non empty set V called the set of nodes (points, vertices) of the graph, a set which is the set of edges and a mapping from the set of edges to a set of pairs

### Trees and Fundamental Circuits

Trees and Fundamental Circuits Tree A connected graph without any circuits. o must have at least one vertex. o definition implies that it must be a simple graph. o only finite trees are being considered

### Quiz 2 Solutions. Solution: False. Need stable sort.

Introduction to Algorithms April 13, 2011 Massachusetts Institute of Technology 6.006 Spring 2011 Professors Erik Demaine, Piotr Indyk, and Manolis Kellis Quiz 2 Solutions Problem 1. True or false [24

### Analysis of Algorithms, I

Analysis of Algorithms, I CSOR W4231.002 Eleni Drinea Computer Science Department Columbia University Thursday, February 26, 2015 Outline 1 Recap 2 Representing graphs 3 Breadth-first search (BFS) 4 Applications

### COS 226 Algorithms and Data Structures Fall Final

COS 22 Algorithms and Data Structures Fall 200 Final This test has 4 questions worth a total of 00 points. You have 80 minutes. The exam is closed book, except that you are allowed to use a one page cheatsheet

### 5.1 Bipartite Matching

CS787: Advanced Algorithms Lecture 5: Applications of Network Flow In the last lecture, we looked at the problem of finding the maximum flow in a graph, and how it can be efficiently solved using the Ford-Fulkerson

### Minimum Spanning Trees

Minimum Spanning Trees Algorithms and 18.304 Presentation Outline 1 Graph Terminology Minimum Spanning Trees 2 3 Outline Graph Terminology Minimum Spanning Trees 1 Graph Terminology Minimum Spanning Trees

### Tufts University, Spring 2005 Michael Horn, Julie Weber (2004) Voronoi Diagrams

Comp 163: Computational Geometry Professor Diane Souvaine Tufts University, Spring 2005 Michael Horn, Julie Weber (2004) Voronoi Diagrams 1 Voronoi Diagrams 1 Consider the following problem. To determine

### Graph Algorithms using Map-Reduce

Graph Algorithms using Map-Reduce Graphs are ubiquitous in modern society. Some examples: The hyperlink structure of the web 1/7 Graph Algorithms using Map-Reduce Graphs are ubiquitous in modern society.

### 1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++

Answer the following 1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++ 2) Which data structure is needed to convert infix notations to postfix notations? Stack 3) The

### The relationship of a trees to a graph is very important in solving many problems in Maths and Computer Science

Trees Mathematically speaking trees are a special class of a graph. The relationship of a trees to a graph is very important in solving many problems in Maths and Computer Science However, in computer

### Cpt S 223. School of EECS, WSU

The Shortest Path Problem 1 Shortest-Path Algorithms Find the shortest path from point A to point B Shortest in time, distance, cost, Numerous applications Map navigation Flight itineraries Circuit wiring

### DATA ANALYSIS II. Matrix Algorithms

DATA ANALYSIS II Matrix Algorithms Similarity Matrix Given a dataset D = {x i }, i=1,..,n consisting of n points in R d, let A denote the n n symmetric similarity matrix between the points, given as where

### Discrete Mathematics & Mathematical Reasoning Chapter 10: Graphs

Discrete Mathematics & Mathematical Reasoning Chapter 10: Graphs Kousha Etessami U. of Edinburgh, UK Kousha Etessami (U. of Edinburgh, UK) Discrete Mathematics (Chapter 6) 1 / 13 Overview Graphs and Graph

### 6.042/18.062J Mathematics for Computer Science October 3, 2006 Tom Leighton and Ronitt Rubinfeld. Graph Theory III

6.04/8.06J Mathematics for Computer Science October 3, 006 Tom Leighton and Ronitt Rubinfeld Lecture Notes Graph Theory III Draft: please check back in a couple of days for a modified version of these

### Linear Programming. March 14, 2014

Linear Programming March 1, 01 Parts of this introduction to linear programming were adapted from Chapter 9 of Introduction to Algorithms, Second Edition, by Cormen, Leiserson, Rivest and Stein [1]. 1

### PES Institute of Technology-BSC QUESTION BANK

PES Institute of Technology-BSC Faculty: Mrs. R.Bharathi CS35: Data Structures Using C QUESTION BANK UNIT I -BASIC CONCEPTS 1. What is an ADT? Briefly explain the categories that classify the functions

### Min-cost flow problems and network simplex algorithm

Min-cost flow problems and network simplex algorithm The particular structure of some LP problems can be sometimes used for the design of solution techniques more efficient than the simplex algorithm.

### Network (Tree) Topology Inference Based on Prüfer Sequence

Network (Tree) Topology Inference Based on Prüfer Sequence C. Vanniarajan and Kamala Krithivasan Department of Computer Science and Engineering Indian Institute of Technology Madras Chennai 600036 vanniarajanc@hcl.in,

### CompSci-61B, Data Structures Final Exam

Your Name: CompSci-61B, Data Structures Final Exam Your 8-digit Student ID: Your CS61B Class Account Login: This is a final test for mastery of the material covered in our labs, lectures, and readings.

### Mathematics for Algorithm and System Analysis

Mathematics for Algorithm and System Analysis for students of computer and computational science Edward A. Bender S. Gill Williamson c Edward A. Bender & S. Gill Williamson 2005. All rights reserved. Preface

### State Space Problem Definition

Blind Search State Space Problem Definition One widely used way to describe problems is by listing or describing all possible states. Solving a problem means moving through the state space from a start

### CSE 5311 Homework 2 Solution

CSE 5311 Homework 2 Solution Problem 6.2-6 Show that the worst-case running time of MAX-HEAPIFY on a heap of size n is Ω(lg n). (Hint: For a heap with n nodes, give node values that cause MAX- HEAPIFY

### Why? A central concept in Computer Science. Algorithms are ubiquitous.

Analysis of Algorithms: A Brief Introduction Why? A central concept in Computer Science. Algorithms are ubiquitous. Using the Internet (sending email, transferring files, use of search engines, online

### COLORED GRAPHS AND THEIR PROPERTIES

COLORED GRAPHS AND THEIR PROPERTIES BEN STEVENS 1. Introduction This paper is concerned with the upper bound on the chromatic number for graphs of maximum vertex degree under three different sets of coloring

### Warshall s Algorithm: Transitive Closure

CS 0 Theory of Algorithms / CS 68 Algorithms in Bioinformaticsi Dynamic Programming Part II. Warshall s Algorithm: Transitive Closure Computes the transitive closure of a relation (Alternatively: all paths

### Forests and Trees: A forest is a graph with no cycles, a tree is a connected forest.

2 Trees What is a tree? Forests and Trees: A forest is a graph with no cycles, a tree is a connected forest. Theorem 2.1 If G is a forest, then comp(g) = V (G) E(G). Proof: We proceed by induction on E(G).

### Sample Problems in Discrete Mathematics

Sample Problems in Discrete Mathematics This handout lists some sample problems that you should be able to solve as a pre-requisite to Computer Algorithms Try to solve all of them You should also read

### 1 Basic Definitions and Concepts in Graph Theory

CME 305: Discrete Mathematics and Algorithms 1 Basic Definitions and Concepts in Graph Theory A graph G(V, E) is a set V of vertices and a set E of edges. In an undirected graph, an edge is an unordered

### A binary search tree or BST is a binary tree that is either empty or in which the data element of each node has a key, and:

Binary Search Trees 1 The general binary tree shown in the previous chapter is not terribly useful in practice. The chief use of binary trees is for providing rapid access to data (indexing, if you will)

### Memoization/Dynamic Programming. The String reconstruction problem. CS125 Lecture 5 Fall 2016

CS125 Lecture 5 Fall 2016 Memoization/Dynamic Programming Today s lecture discusses memoization, which is a method for speeding up algorithms based on recursion, by using additional memory to remember

### Scheduling Shop Scheduling. Tim Nieberg

Scheduling Shop Scheduling Tim Nieberg Shop models: General Introduction Remark: Consider non preemptive problems with regular objectives Notation Shop Problems: m machines, n jobs 1,..., n operations

### Algorithm Design and Analysis Homework #6 Due: 1pm, Monday, January 9, === Homework submission instructions ===

Algorithm Design and Analysis Homework #6 Due: 1pm, Monday, January 9, 2012 === Homework submission instructions === Submit the answers for writing problems (including your programming report) through

### UNIVERSITI MALAYSIA SARAWAK KOTA SAMARAHAN SARAWAK PSD2023 ALGORITHM & DATA STRUCTURE

STUDENT IDENTIFICATION NO UNIVERSITI MALAYSIA SARAWAK 94300 KOTA SAMARAHAN SARAWAK FAKULTI SAINS KOMPUTER & TEKNOLOGI MAKLUMAT (Faculty of Computer Science & Information Technology) Diploma in Multimedia

### Multi-Way Search Trees (B Trees)

Multi-Way Search Trees (B Trees) Multiway Search Trees An m-way search tree is a tree in which, for some integer m called the order of the tree, each node has at most m children. If n

### 4 Basics of Trees. Petr Hliněný, FI MU Brno 1 FI: MA010: Trees and Forests

4 Basics of Trees Trees, actually acyclic connected simple graphs, are among the simplest graph classes. Despite their simplicity, they still have rich structure and many useful application, such as in

### CMPSCI611: Approximating MAX-CUT Lecture 20

CMPSCI611: Approximating MAX-CUT Lecture 20 For the next two lectures we ll be seeing examples of approximation algorithms for interesting NP-hard problems. Today we consider MAX-CUT, which we proved to

### Jade Yu Cheng ICS 311 Homework 10 Oct 7, 2008

Jade Yu Cheng ICS 311 Homework 10 Oct 7, 2008 Question for lecture 13 Problem 23-3 on p. 577 Bottleneck spanning tree A bottleneck spanning tree of an undirected graph is a spanning tree of whose largest

### Symbol Tables. IE 496 Lecture 13

Symbol Tables IE 496 Lecture 13 Reading for This Lecture Horowitz and Sahni, Chapter 2 Symbol Tables and Dictionaries A symbol table is a data structure for storing a list of items, each with a key and

### ECE 250 Data Structures and Algorithms MIDTERM EXAMINATION 2008-10-23/5:15-6:45 REC-200, EVI-350, RCH-106, HH-139

ECE 250 Data Structures and Algorithms MIDTERM EXAMINATION 2008-10-23/5:15-6:45 REC-200, EVI-350, RCH-106, HH-139 Instructions: No aides. Turn off all electronic media and store them under your desk. If

### Binary Search. Search for x in a sorted array A.

Divide and Conquer A general paradigm for algorithm design; inspired by emperors and colonizers. Three-step process: 1. Divide the problem into smaller problems. 2. Conquer by solving these problems. 3.

### Lecture 7: Approximation via Randomized Rounding

Lecture 7: Approximation via Randomized Rounding Often LPs return a fractional solution where the solution x, which is supposed to be in {0, } n, is in [0, ] n instead. There is a generic way of obtaining

### Planar Graph and Trees

Dr. Nahid Sultana December 16, 2012 Tree Spanning Trees Minimum Spanning Trees Maps and Regions Eulers Formula Nonplanar graph Dual Maps and the Four Color Theorem Tree Spanning Trees Minimum Spanning

### ITEC2620 Introduction to Data Structures

ITEC2620 Introduction to Data Structures Lecture 8b Search Trees Traversals Typical covered as graph traversals in data structures courses I ve never seen a graph traversal in practice! AI background Tree