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

Save this PDF as:

Size: px
Start display at page:

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

## Transcription

1 . 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 of elements of V. It is also convenient to write a graph as G=(V,). Notice that definition of graph implies that to every edge of a graph G, we can associate a pair of nodes of the graph. If an edge X Є is thus associated with a pair of nodes (U,V) where U, V Є V then we says that edge x connect U and V.. djacent Nodes ny two nodes which are connected by an edge in a graph are called adjacent node.. irected & Undirected dge In a graph G=(V,) an edge which is directed from one end to another end is called a directed edge, while the edge which has no specific direction is called undirected edge.. irected graph (igraph) graph in which every edge is directed is called directed graph or digraph.. Undirected graph graph in which every edge is undirected is called directed graph or digraph.. Mixed Graph If some of the edges are directed and some are undirected in graph then the graph is called mixed graph. 7. Loop (Sling) n edge of a graph which joins a node to itself is called a loop (sling). 8. Multigraph ny graph which contains some parallel edges is called multigraph. 9. Weighted Graph graph in which weights are assigned to every edge is called weighted graph. 0. Isolated Node In a graph a node which is not adjacent to any other node is called isolated node. Prof. Pradyumansinh Jadeja (987988) 070 ata & ile Structure

2 . Null Graph graph containing only isolated nodes are called null graph. In other words set of edges in null graph is empty.. Path of Graph Let G=(V, ) be a simple digraph such that the terminal node of any edge in the sequence is the initial node of the edge, if any appearing next in the sequence defined as path of the graph.. Length of Path The number of edges appearing in the sequence of the path is called length of path.. egree of vertex The no of edges which have V as their terminal node is call as indegree of node V The no of edges which have V as their initial node is call as outdegree of node V Sum of indegree and outdegree of node V is called its Total egree or egree of vertex.. Simple Path (dge Simple) path in a diagraph in which the edges are distinct is called simple path or edge simple.. lementary Path (Node Simple) path in which all the nodes through which it traverses are distinct is called elementary path. 7. ycle (ircuit) path which originates and ends in the same node is called cycle (circuit). 8. irected directed tree is an acyclic digraph which has one node called its root with in degree 0, while all other nodes have in degree. very directed tree must have at least one node. n isolated node is also a directed tree. 9. Terminal Node (Leaf Node) In a directed tree, any node which has out degree 0 is called terminal node or left node. 0. Level of Node The level of any node is the length of its path from the root.. Ordered In a directed tree an ordering of the nodes at each level is prescribed then such a tree is called ordered tree. Prof. Pradyumansinh Jadeja (987988) 070 ata & ile Structure

3 . orest If we delete the root and its edges connecting the nodes at level, we obtain a set of disjoint tree. set of disjoint tree is a forest.. M ary If in a directed tree the out degree of every node is less than or equal to m then tree is called an m ary tree.. ull or omplete M ary If the out degree of each and every node is exactly equal to m or 0 and their number of nodes at level i is m (i ) then the tree is called a full or complex m ary tree.. Positional M ary If we consider m ary trees in which the m children of any node are assumed to have m distinct positions, if such positions are taken into account, then tree is called positional m ary tree.. Height of the tree The height of a tree is the length of the path from the root to the deepest node in the tree. 7. inary tree If in a directed tree the out degree of every node is less than or equal to then tree is called binary tree. 8. Strictly binary tree strictly binary tree (sometimes proper binary tree or tree or full binary tree) is a tree in which every node other than the leaves has two children. 9. omplete binary tree If the out degree of each and every node is exactly equal to or 0 and their number of nodes at level i is (i ) then the tree is called a full or complete binary tree. 0. Sibling Siblings are nodes that share the same parent node.. inary search tree binary search tree is a binary tree in which each node possessed a key that satisfy the following conditions. ll key (if any) in the left sub tree of the root precedes the key in the root.. The key in the root precedes all key (if any) in the right sub tree.. The left and right sub tree sub trees of the root are again search trees. Prof. Pradyumansinh Jadeja (987988) 070 ata & ile Structure

4 . Height alanced inary tree (VL ) tree is called VL (height balance binary tree), if each node possesses one of the following properties. node is called left heavy if the longest path in its left sub tree is one longer then the longest path of its right sub tree.. node is called right heavy if the longest path in the right sub tree is one longer than path in its left sub tree.. node is called balanced, if the longest path in both the right and left sub tree are equal.. xplain the Preorder, Inorder and Postorder traversal techniques of the binary tree with suitable example. The most common operations performed on tree structure is that of traversal. This is a procedure by which each node in the tree is processed exactly once in a systematic manner. There are three ways of traversing a binary tree. Preorder Preorder traversal of a binary tree is defined as follow o Process the root node o Traverse the left subtree in preorder o Traverse the right subtree in preorder If particular subtree is empty (i.e., node has no left or right descendant) the traversal is performed by doing nothing, In other words, a null subtree is considered to be fully traversed when it is encountered. Preorder traversal : G Inorder traversal : G Postorder traversal : G G onverse Preorder traversal : onverse Inorder traversal : G G ig.. onverse Postorder traversal : G The preorder traversal of a tree (ig..) is given by G Prof. Pradyumansinh Jadeja (987988) 070 ata & ile Structure

5 Inorder The Inorder traversal of a binary tree is given by following steps, o Traverse the left subtree in Inorder o Process the root node o Traverse the right subtree in Inorder The Inorder traversal of a tree (ig..) is given by G Postorder The postorder traversal is given by o Traverse the left subtree in postorder o Traverse the right subtree in postorder o Process the root node The Postorder traversal of a tree (ig..) is given by G onverse If we interchange left and right words in the preceding definitions, we obtain three new traversal orders which are called o onverse Preorder ( G ) o onverse Inorder (G ) o onverse Postorder (G ). Write the algorithm of Preorder, Inorder and Postorder traversal techniques of the binary tree. Procedure : RPRORR(T) Given a binary tree whose root node address is given by pointer variable T and whose node structure is same as described below. This procedure traverse the tree in preorder, in a recursive manner. Prof. Pradyumansinh Jadeja (987988) 070 ata & ile Structure

6 LPTR T RPTR. [heck for empty ] If T = NULL then write ( mpty ) return else write (T(T)). [Process the Left Subtree] If LPTR (T) NULL then RPRORR (LPTR (T)). [Process the Right Subtree] If RPTR (T) NULL then RPRORR (RPTR (T)). [inished] return Procedure : RINORR(T) Given a binary tree whose root node address is given by pointer variable T and whose node structure is same as described below. This procedure traverse the tree in inorder, in a recursive manner.. [heck for empty ] If T = NULL then write ( mpty ) return. [Process the Left Subtree] If LPTR (T) NULL then RINORR (LPTR (T)). [Process the root node] write (T(T)). [Process the Right Subtree] If RPTR (T) NULL then RINORR (RPTR (T)). [inished] return Prof. Pradyumansinh Jadeja (987988) 070 ata & ile Structure

7 Procedure : RPOSTORR(T) Given a binary tree whose root node address is given by pointer variable T and whose node structure is same as described below. This procedure traverse the tree in postorder, in a recursive manner.. [heck for empty ] If T = NULL then write ( mpty ) return. [Process the Left Subtree] If LPTR (T) NULL then RPOSTORR (LPTR (T)). [Process the Right Subtree] If RPTR (T) NULL then RPOSTORR (RPTR (T)). [Process the root node] write (T(T)). [inished] return. Give traversal order of following tree into Inorder, Preorder and Postorder. Inorder: Preorder: Post order: 7 Prof. Pradyumansinh Jadeja (987988) 070 ata & ile Structure

8 . onstruct a tree for the given Inorder and Postorder traversals Inorder : G H I Postorder : G H I G H I G H I G H I 8 Prof. Pradyumansinh Jadeja (987988) 070 ata & ile Structure

9 Postorder : H G I Inorder : G H I G H I G H I G H I G I H 9 Prof. Pradyumansinh Jadeja (987988) 070 ata & ile Structure

10 . onstruct a tree for the given Inorder and Preorder traversals Preorder : G Q K P R H Inorder : Q K G P H R G Q K P H R G P Q K R H G P Q K R H G P Q R K H 0 Prof. Pradyumansinh Jadeja (987988) 070 ata & ile Structure

11 7. reate a binary search tree for the following data : 0,,7,,0,0,80,90,, onstruct binary search tree for the following data and find its Inorder, Preorder and Postorder traversal 0,,,,,,,,78,, 0 78 Preorder : 0,,,,,,,,,, 78 Inorder :,,, 0,,,,,,, 78 Postorder :,,,,, 78,,,,, 0 Prof. Pradyumansinh Jadeja (987988) 070 ata & ile Structure

13 Insertion into and deletion from threaded binary tree are more time consuming because both thread and structural link must be maintained. inary Inorder Traversal G G ully In threaded binary tree of given binary tree H G Prof. Pradyumansinh Jadeja (987988) 070 ata & ile Structure

14 0. raw a right in threaded binary tree for the given tree Right In threaded binary tree of given binary tree H H G Prof. Pradyumansinh Jadeja (987988) 070 ata & ile Structure

15 . What is the meaning of height balanced tree? How rebalancing is done in height balanced tree. tree is called VL (height balance binary tree), if each node possesses one of the following properties. node is called left heavy if the longest path in its left sub tree is one longer then the longest path of its right sub tree.. node is called right heavy if the longest path in the right sub tree is one longer than path in its left sub tree.. node is called balanced, if the longest path in both the right and left sub tree are equal. If tree becomes unbalanced by inserting any node, then based on position of insertion, we need to rotate the unbalanced node. Rotation is the process to make tree balanced ) Insertion into Left sub tree of nodes Left child Single Right Rotation ) Insertion into Right sub tree of node s Left child Left Right Rotation ) Insertion into Left sub tree of node s Right child Right Left Rotation ) Insertion into Right sub tree of node s Right child Single Left Rotation ) Insertion into Left sub tree of nodes Left child Single Right Rotation If node becomes unbalanced after insertion of new node at Left sub tree of nodes Left child, then we need to perform Single Right Rotation for unbalanced node. Right Rotation a. etach leaf child s right sub tree b. onsider leaf child to be the new parent c. ttach old parent onto right of new parent d. ttach old leaf child s old right sub tree as leaf sub tree of new right child ritical Node J K K Z Right Rotation X J X Y N Y Z N Prof. Pradyumansinh Jadeja (987988) 070 ata & ile Structure

16 ritical Node 7 7 Steps of Right Rotation ) Insertion into Right sub tree of node s Left child Left Right Rotation If node becomes unbalanced after insertion of new node at Right sub tree of node s Left child, then we need to perform Left Right Rotation for unbalanced node. Leaf rotation of leaf child followed by right rotation of parent J J Y X K Y Z Left Rotation of K K Y n Z Right Rotation of J K X n Z J n X ) Insertion into Left sub tree of node s Right child Right Left Rotation If node becomes unbalanced after insertion of new node at Left sub tree of node s Right child, then we need to perform Right Left Rotation for unbalanced node. Single right rotation of right child followed by left rotation of parent Prof. Pradyumansinh Jadeja (987988) 070 ata & ile Structure

17 X Unbalanced node X Y T Y Z T Right Rotation of Z T T Y Z Left Rotation of X X Z T T T T T T T T ) Insertion into Right sub tree of node s Right child Single Left Rotation If node becomes unbalanced after insertion of new node at Right sub tree of nodes Right child, then we need to perform Single Left Rotation for unbalanced node. Left Rotation a. etach right child s leaf sub tree b. onsider right child to be new parent c. ttach old parent onto left of new parent d. ttach old right child s old left sub tree as right sub tree of new left child X Unbalanced node Y T Y Leaf Rotation of X X T T T T T n n xample 0 Unbalanced node Prof. Pradyumansinh Jadeja (987988) 070 ata & ile Structure

18 . onstruct VL Search tree by inserting following elements in order of their occurrence,,,,, Insert Insert : Insert : Right Insert : Rotate Insert : Righ Insert : Rotate Right Rotate ssignment: efine height of the binary tree. efine height balanced tree with its advantages. onstruct a height balanced binary tree (VL tree) for the following data,0,,,88,0,,,, onstruct the VL search tree by inserting the following elements in the order of their occurrence.,,,,, 0, 98, 8 8 Prof. Pradyumansinh Jadeja (987988) 070 ata & ile Structure

19 . What are the advantages of Multiway search tree in disc access? onstruct tree of order for the following data,7,,,,,0,,,0,,,,,8,9,, Insert: Insert: Insert: 7 Insert: Insert:,,, 7,,, 7,,, 7, Overflow, 7, Insert: Insert: Insert:,, 7,,, 7, 0,,, 7, 0,, Insert: 9 0 Insert: 0,,,, 7, 0,,, Overflow,, 7, 0,,, 7, 0,, 0 Insert: Insert:,,, 7, 0,,, 0,,,,, 7, 0,,, 0, Overflow,, 7, 0, 0,, 9 Prof. Pradyumansinh Jadeja (987988) 070 ata & ile Structure

20 Insert:,,,,,,, 7, 0, 0,,, 7, 0, 0, Overflow Insert: 8, 9,,, 7, 0,, 8, 9, 0, Insert:,, 7, 0,, 8, 9, 0,, Overflow,, 0,, 7, 0,, 8, 9, ssignment: onstruct mutiway search tree for the following data of order for 00, 0, 0,, 0, 00, 70,, 7, 0, 0,, 0,, 80, 90, 00, 0 Prof. Pradyumansinh Jadeja (987988) 070 ata & ile Structure

21 . What is tree? tree is a type of data structure, where every node with children has either two children or three children. very non leaf is a node or a node. ll leaves are at the same level (the bottom level) ll data are kept in sorted order very non leaf node will contain or fields. What is graph? How it can be represented using adjacency matrix, what is path matrix? How path matrix can be found out using adjacency matrix. 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 of elements of V. It is also convenient to write a graph as G=(V,). Notice that definition of graph implies that to every edge of a graph G, we can associate a pair of nodes of the graph. If an edge X Є is thus associated with a pair of nodes (U,V) where U, V Є V then we says that edge x connect U and V. djacency matrix Let G = (V, ) be a simple diagraph in which V = {v, v,., v n } and the nodes are assumed to be ordered from v to v n. n n x n matrix whose elements are a ij are given by, a ij = 0 is called adjacency matrix of the graph G. ny element of the adjacency matrix is either 0 or. or a given graph G =m (V, ), an adjacency matrix depends upon the ordering of the elements of V. or different ordering of the elements of V we get different adjacency matrices. V V V V V V V V V 0 0 V V 0 V digraph and its adjacency matrix Prof. Pradyumansinh Jadeja (987988) 070 ata & ile Structure

22 We can extend the idea of matrix representation to multigraph sand weighted graphs. In the case of multigraph or weighted graph we write a ji = w, where a ij denotes either the multiplicity it the weight of the edge. Path matrix n entry of in the ith row and jth column of shows the existence of an edge (v i, v j ), that is a path of length from v i to v j. Let denote the elements of by a () ij. Then Therefore a () ij is equal to the number of different paths of exactly length from v i to v j. Similarly element in i th row and j th column of gives number of paths of exactly length from v i to v j. = = = ifferent path matrices. Which are the basic traversing techniques of the Graph? Write the algorithm of them. Most graph problems involve traversal of a graph. Traversal of a graph means visit each node exactly once. Two commonly used graphs traversal techniques are. epth irst Search (S). readth irst Search (S) epth irst Search (S) It is like preorder traversal of tree. Traversal can start from any vertex vi Vi is visited and then all vertices adjacent to vi are traversed recursively using S Prof. Pradyumansinh Jadeja (987988) 070 ata & ile Structure

23 S (G, ) is given by 7 a) Visit () b) S (G, ) S (G, ) S (G, ) S (G, ) 8 S traversal of given graph is:,,,, 8, 7,, Graph G Since graph can have cycles, we must avoid re visiting a node. To do this when we visit a vertex V, we marks it visited as visited should not be selected for traversal. Procedure : S (vertecx V) This procedure traverse the graph G in S manner. V is a starting vertex to be explored. S is a Stack, visited[] is an array which tells you whether particular vertex is visited or not. W is a adjacent node of vertex V. PUSH and POP are functions to insert and remove from stack respectively.. [Initialize TOP and Visited] visited[] 0 TOP 0. [Push vertex into stack] PUSH (V). [Repeat while stack is not empty] Repeat step while stack is not empty v POP() if visited[v] is 0 then visited [v] for all W adjacent to v if visited [v] is 0 then PUSH (W) end for end if Prof. Pradyumansinh Jadeja (987988) 070 ata & ile Structure

25 7. What is spanning tree? Spanning tree of a graph is an undirected tree consisting of only those edges necessary to connect all the nodes in the original graph spanning tree has the properties that o or any pair of nodes there exists only one path between them o Insertion of any edge to a spanning tree forms a unique cycle The particular Spanning for a graph depends on the criteria used to generate it. If S search is use, those edges traversed by the algorithm forms the edges of tree, referred to as epth irst Spanning. If S Search is used, the spanning tree is formed from those edges traversed during the search, producing readth irst Search Spanning tree. V0 V V V V V V V7 V0 V0 V V V V V V V V V V V V V7 S Spanning V7 S Spanning Prof. Pradyumansinh Jadeja (987988) 070 ata & ile Structure

26 8. onsider the graph shown in ig ind depth first and breadth first traversals of this graph starting at S : S : Prof. Pradyumansinh Jadeja (987988) 070 ata & ile Structure

27 9. efine spanning tree and minimum spanning tree. ind the minimum spanning tree of the graph shown in ig. 7 Using Prim s lgorithm: Let X be the set of nodes explored, initially X = { } Step : Taking minimum weight edge of all djacent edges of X = { } X = {, } Step : Taking minimum weight edge of all djacent edges of X = {, } X = {,, } 7 Step : Taking minimum weight edge of all djacent edges of X = {,, } Step : Taking minimum weight edge of all djacent edges of X = {,,, } X = {,,, } X = {,,,, } ll nodes of graph are there with set X, so we obtained minimum spanning tree of cost: = 0 7 Prof. Pradyumansinh Jadeja (987988) 070 ata & ile Structure

28 7 Using Kruskal s lgorithm Step : Taking min edge (,) Step : Taking next min edge (,) Step : Taking next min edge (,) Step : Taking next min edge (,) Step : Taking next min edge (,) it forms cycle so do not consider Step : Taking next min edge (,) it forms cycle so do not consider Step 7: Taking next min edge (,) it forms cycle so do not consider Step 8: Taking next min edge (,) it forms cycle so do not consider Step 9: Taking next min edge (,) it forms cycle so do not consider ll edges of graph has been visited, so we obtained minimum spanning tree of cost: = 0 0. Give example and applications of directed and undirected graphs. ind the adjacency matrix for the graph shown in ig. djacency matrix for the given graph Prof. Pradyumansinh Jadeja (987988) 070 ata & ile Structure

29 pplications of graph: lectronic ircuits o Printed ircuit oard o Integrated ircuit Transportation networks o Highway networks Modeling a road network with vertexes as towns and edge costs as distances. o Water Supply networks Modeling a water supply network. cost might relate to current or a function of capacity and length. s water flows in only direction, from higher to lower pressure connections or downhill, such a network is inherently an acyclic directed graph. o light network Minimizing the cost and time taken for air travel when direct flights don't exist between starting and ending airports. omputer networks o Local rea Network o Internet ynamically modeling the status of a set of routes by which traffic might be directed over the Internet. o Web Using a directed graph to map the links between pages within a website and to analyze ease of navigation between different parts of the site. atabases o ntity Relationship iagram 9 Prof. Pradyumansinh Jadeja (987988) 070 ata & ile Structure

30 0 Prof. Pradyumansinh Jadeja (987988) 070 ata & ile Structure. pply ijkstra s algorithm to find shortest path between vertex and vertex for the graph shown in ig. 7 7 Step : Traverse all adjacent node of 0 7 Step : Traverse all adjacent node of 0 7 Step : Traverse all adjacent node of 0 7 Step : Traverse all adjacent node of Step : Traverse all adjacent node of 0 7 Shortest path from node to is : as shown in step Length of path is 7

### Solid Modeling Techniques

ML70 LTUR Solid Modeling Techniques onstructive Solid eometry (S) omputational Solid eometry Primitive based: It is based on the notion that a physical object can be divided into a set of primitives basic

### 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

### 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

### 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:

### 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

### 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

### 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

### 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

### 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

### root node level: internal node edge leaf node CS@VT Data Structures & Algorithms 2000-2009 McQuain

inary Trees 1 A binary tree is either empty, or it consists of a node called the root together with two binary trees called the left subtree and the right subtree of the root, which are disjoint from each

### 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.

### 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).

### 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

### 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,

### 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

### 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

### 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

### DATA STRUCTURES USING C

DATA STRUCTURES USING C QUESTION BANK UNIT I 1. Define data. 2. Define Entity. 3. Define information. 4. Define Array. 5. Define data structure. 6. Give any two applications of data structures. 7. Give

### Ordered Lists and Binary Trees

Data Structures and Algorithms Ordered Lists and Binary Trees Chris Brooks Department of Computer Science University of San Francisco Department of Computer Science University of San Francisco p.1/62 6-0:

### CSCI Trees. Mark Redekopp David Kempe

1 CSCI 104 2-3 Trees Mark Redekopp David Kempe 2 Properties, Insertion and Removal BINARY SEARCH TREES 3 Binary Search Tree Binary search tree = binary tree where all nodes meet the property that: All

### 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

### 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

### 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

### Trees. Definition: A tree is a connected undirected graph with no simple circuits. Example: Which of these graphs are trees?

Section 11.1 Trees Definition: A tree is a connected undirected graph with no simple circuits. Example: Which of these graphs are trees? Solution: G 1 and G 2 are trees both are connected and have no simple

### TREE BASIC TERMINOLOGIES

TREE Trees are very flexible, versatile and powerful non-liner data structure that can be used to represent data items possessing hierarchical relationship between the grand father and his children and

### Binary Search Trees CMPSC 122

Binary Search Trees CMPSC 122 Note: This notes packet has significant overlap with the first set of trees notes I do in CMPSC 360, but goes into much greater depth on turning BSTs into pseudocode than

### 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

### 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

### Trees & Binary Search Trees

CMSC 132: Object-Oriented Programming II Trees & Binary Search Trees Department of Computer Science University of Maryland, College Park Trees Trees are hierarchical data structures One-to-many relationship

### 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

### 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 LECTURE 4: TREES

GRAPH THEORY LECTURE 4: TREES Abstract. 3.1 presents some standard characterizations and properties of trees. 3.2 presents several different types of trees. 3.7 develops a counting method based on a bijection

### Module 2. Problem Solving using Search- (Single agent search) Version 2 CSE IIT, Kharagpur

Module 2 Problem Solving using Search- (Single agent search) Version 2 S IIT, Kharagpur Lesson 4 Uninformed Search Version 2 S IIT, Kharagpur 2.4 Search Searching through a state space involves the following:

### 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

### 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

### Analysis of Algorithms I: Binary Search Trees

Analysis of Algorithms I: Binary Search Trees Xi Chen Columbia University Hash table: A data structure that maintains a subset of keys from a universe set U = {0, 1,..., p 1} and supports all three dictionary

### Data Structure with C

Subject: Data Structure with C Topic : Tree Tree A tree is a set of nodes that either:is empty or has a designated node, called the root, from which hierarchically descend zero or more subtrees, which

### Data Structures and Algorithms

Data Structures and Algorithms CS245-2016S-06 Binary Search Trees David Galles Department of Computer Science University of San Francisco 06-0: Ordered List ADT Operations: Insert an element in the list

### Binary Search Trees (BST)

Binary Search Trees (BST) 1. Hierarchical data structure with a single reference to node 2. Each node has at most two child nodes (a left and a right child) 3. Nodes are organized by the Binary Search

### 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.

### 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

### 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

### Algorithms and Data Structures

Algorithms and Data Structures Part 2: Data Structures PD Dr. rer. nat. habil. Ralf-Peter Mundani Computation in Engineering (CiE) Summer Term 2016 Overview general linked lists stacks queues trees 2 2

### Binary Trees and Huffman Encoding Binary Search Trees

Binary Trees and Huffman Encoding Binary Search Trees Computer Science E119 Harvard Extension School Fall 2012 David G. Sullivan, Ph.D. Motivation: Maintaining a Sorted Collection of Data A data dictionary

### 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

### 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

### 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

### 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

### 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

### 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

### Binary Search Trees. A Generic Tree. Binary Trees. Nodes in a binary search tree ( B-S-T) are of the form. P parent. Key. Satellite data L R

Binary Search Trees A Generic Tree Nodes in a binary search tree ( B-S-T) are of the form P parent Key A Satellite data L R B C D E F G H I J The B-S-T has a root node which is the only node whose parent

### 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

### MAX = 5 Current = 0 'This will declare an array with 5 elements. Inserting a Value onto the Stack (Push) -----------------------------------------

=============================================================================================================================== DATA STRUCTURE PSEUDO-CODE EXAMPLES (c) Mubashir N. Mir - www.mubashirnabi.com

### Previous Lectures. B-Trees. External storage. Two types of memory. B-trees. Main principles

B-Trees Algorithms and data structures for external memory as opposed to the main memory B-Trees Previous Lectures Height balanced binary search trees: AVL trees, red-black trees. Multiway search trees:

### Data Structures. Level 6 C30151. www.fetac.ie. Module Descriptor

The Further Education and Training Awards Council (FETAC) was set up as a statutory body on 11 June 2001 by the Minister for Education and Science. Under the Qualifications (Education & Training) Act,

### The origins of graph theory are humble, even frivolous. Biggs, E. K. Lloyd, and R. J. Wilson)

Chapter 11 Graph Theory The origins of graph theory are humble, even frivolous. Biggs, E. K. Lloyd, and R. J. Wilson) (N. Let us start with a formal definition of what is a graph. Definition 72. A graph

### B-Trees. Algorithms and data structures for external memory as opposed to the main memory B-Trees. B -trees

B-Trees Algorithms and data structures for external memory as opposed to the main memory B-Trees Previous Lectures Height balanced binary search trees: AVL trees, red-black trees. Multiway search trees:

### 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

### Learning Outcomes. COMP202 Complexity of Algorithms. Binary Search Trees and Other Search Trees

Learning Outcomes COMP202 Complexity of Algorithms Binary Search Trees and Other Search Trees [See relevant sections in chapters 2 and 3 in Goodrich and Tamassia.] At the conclusion of this set of lecture

### Overview of Data Structures

UNIT 3 Concrete Data Types Classification of Data Structures Concrete vs. Abstract Data Structures Most Important Concrete Data Structures Arrays Records Linked Lists Binary Trees Overview of Data Structures

### 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

### Trees LOGO STYLE GUIDE Schools within the University 1 19

Trees 1 Example Tree 2 A Generic Tree 3 Tree ADT n Tree definition q A tree is a set of nodes which may be empty q If not empty, then there is a distinguished node r, called root and zero or more non-empty

### 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

### Stacks, Queues & Trees. The Stack Interface. The Stack Interface. Prof. Dr. Harald Gall. Institut für Informatik Universität Zürich

Stacks, Queues & Trees Prof. Dr. Harald Gall Institut für Informatik Universität Zürich http://seal.ifi.uzh.ch The Stack Interface!! Stack!! Data structure holding several items.!! New items added to the

### 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

### 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

### 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.

### Graph Theory and Topology Design

raph Theory and Topology esign avid Tipper ssociate Professor raduate Telecommunications and Networking Program University of Pittsburgh tipper@tele.pitt.edu Slides http://www.sis.pitt.edu/~dtipper/0.html

### Symbol Tables. Introduction

Symbol Tables Introduction A compiler needs to collect and use information about the names appearing in the source program. This information is entered into a data structure called a symbol table. The

### INTERNATIONAL JOURNAL OF PURE AND APPLIED RESEARCH IN ENGINEERING AND TECHNOLOGY

INTERNATIONAL JOURNAL OF PURE AND APPLIED RESEARCH IN ENGINEERING AND TECHNOLOGY A PATH FOR HORIZING YOUR INNOVATIVE WORK A REVIEW ON THE USAGE OF OLD AND NEW DATA STRUCTURE ARRAYS, LINKED LIST, STACK,

### 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

### 10CS35: Data Structures Using C

CS35: Data Structures Using C QUESTION BANK REVIEW OF STRUCTURES AND POINTERS, INTRODUCTION TO SPECIAL FEATURES OF C OBJECTIVE: Learn : Usage of structures, unions - a conventional tool for handling a

### A binary search tree is a binary tree with a special property called the BST-property, which is given as follows:

Chapter 12: Binary Search Trees A binary search tree is a binary tree with a special property called the BST-property, which is given as follows: For all nodes x and y, if y belongs to the left subtree

### 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

### Chapter 14 The Binary Search Tree

Chapter 14 The Binary Search Tree In Chapter 5 we discussed the binary search algorithm, which depends on a sorted vector. Although the binary search, being in O(lg(n)), is very efficient, inserting a

### Parallelization: Binary Tree Traversal

By Aaron Weeden and Patrick Royal Shodor Education Foundation, Inc. August 2012 Introduction: According to Moore s law, the number of transistors on a computer chip doubles roughly every two years. First

### 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

### 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

### The scenario: Initial state Target (Goal) states A set of intermediate states A set of operations that move the agent from one state to another.

CmSc310 Artificial Intelligence Solving Problems by Searching - Uninformed Search 1. Introduction All AI tasks involve searching. General idea: You know where you are (initial state) and where you want

### Homework Exam 1, Geometric Algorithms, 2016

Homework Exam 1, Geometric Algorithms, 2016 1. (3 points) Let P be a convex polyhedron in 3-dimensional space. The boundary of P is represented as a DCEL, storing the incidence relationships between the

### 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

### Questions 1 through 25 are worth 2 points each. Choose one best answer for each.

Questions 1 through 25 are worth 2 points each. Choose one best answer for each. 1. For the singly linked list implementation of the queue, where are the enqueues and dequeues performed? c a. Enqueue in

### Trees. Tree Definitions: Let T = (V, E, r) be a tree. The size of a tree denotes the number of nodes of the tree.

Trees After lists (including stacks and queues) and hash tables, trees represent one of the most widely used data structures. On one hand trees can be used to represent objects that are recursive in nature

### CHAPTER 2 GRAPHS F G C D

page 1 of Section 2.1 HPTR 2 GRPHS STION 1 INTROUTION basic terminology graph is a set of finitely many points called vertices which may be connected by edges. igs 1 3 show three assorted graphs. v1 v2

### 2.1 You need to know how graphs and networks can be used to create mathematical

fter completing this chapter you should: 1 know how graphs and networks can be used to create mathematical models 2 know some basic terminology used in graph theory 3 know some special types of graph 4

### 1. The memory address of the first element of an array is called A. floor address B. foundation addressc. first address D.

1. The memory address of the first element of an array is called A. floor address B. foundation addressc. first address D. base address 2. The memory address of fifth element of an array can be calculated

### Balanced Binary Trees

Reminders about Trees Balanced Binary Trees With pictures by John Morris (ciips.ee.uwa.edu.au/~morris) A binary tree is a tree with exactly two sub-trees for each node, called the left and right sub-trees.

### 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

### 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

### Data Structures UNIT III. Model Question Answer

Data Structures UNIT III Model Question Answer Q.1. Define Stack? What are the different primitive operations on Stack? Ans: Stack: A stack is a linear structure in which items may be added or removed

### Graphs. Graph G=(V,E): representation

Graphs G = (V,E) V the vertices of the graph {v 1, v 2,..., v n } E the edges; E a subset of V x V A cost function cij is the cost/ weight of the edge (v i, v j ) Graph G=(V,E): representation 1. Adjacency

V. Adamchik 1 Graph Theory Victor Adamchik Fall of 2005 Plan 1. Basic Vocabulary 2. Regular graph 3. Connectivity 4. Representing Graphs Introduction A.Aho and J.Ulman acknowledge that Fundamentally, computer

### 1.204 Lecture 6. Data structures: stacks, queues, trees, dictionaries. Data structures

1.204 Lecture 6 Data structures: stacks, queues, trees, dictionaries Data structures Correct and efficient representation of data and applicable rules Stack: last in, first out discipline Queue: first

### Multiway Search Tree (MST)

Multiway Search Tree (MST) Generalization of BSTs Suitable for disk MST of order n: Each node has n or fewer sub-trees S1 S2. Sm, m n Each node has n-1 or fewer keys K1 Κ2 Κm-1 : m-1 keys in ascending

### 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

### 1. Digital Logic Circuits

1 Digital Logic ircuits 1. Digital Logic ircuits Many scientific, industrial and commercial advances have been made possible by the advent of computers. Digital Logic ircuits form the basis of any digital

### 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