BE ISE 3 rd Semester

Similar documents
A set of nodes (or vertices) with a single starting point

BINARY SEARCH TREES. Problem Solving with Computers-II

Trees. Introduction & Terminology. February 05, 2018 Cinda Heeren / Geoffrey Tien 1

Introduction to Binary Trees

CS302 - Data Structures using C++

BINARY SEARCH TREES (CONTD) Problem Solving with Computers-II

Model Solution for QP CODE : ( 3 Hours )

6-TREE. Tree: Directed Tree: A directed tree is an acyclic digraph which has one node called the root node

Chapter 20: Binary Trees

Binary Trees. Examples:

Tree traversals. Review: recursion Tree traversals. October 05, 2017 Cinda Heeren / Geoffrey Tien 1

3137 Data Structures and Algorithms in C++

Ashish Gupta, Data JUET, Guna

Multi-Way Search Tree

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

Binary Trees. Height 1

DC104 DATA STRUCTURE JUNE Q.2 a. If you are using C language to implement the heterogeneous linked list, what pointer type will you use?

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

Data Structure. Chapter 5 Trees (Part II) Angela Chih-Wei Tang. National Central University Jhongli, Taiwan

UNIT III TREES. A tree is a non-linear data structure that is used to represents hierarchical relationships between individual data items.

8. Write an example for expression tree. [A/M 10] (A+B)*((C-D)/(E^F))

Binary Trees, Binary Search Trees

CS24 Week 8 Lecture 1

CS350: Data Structures Tree Traversal

March 20/2003 Jayakanth Srinivasan,

Binary Trees. College of Computing & Information Technology King Abdulaziz University. CPCS-204 Data Structures I

MLR Institute of Technology

Trees CONTENTS. Hours: 8. Marks: 12. Anuradha Bhatia 1

CS171 Final Practice Exam

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

CSI33 Data Structures

CS171 Final Practice Exam

We have the pointers reference the next node in an inorder traversal; called threads

Abstract Data Structures IB Computer Science. Content developed by Dartford Grammar School Computer Science Department

Section 5.5. Left subtree The left subtree of a vertex V on a binary tree is the graph formed by the left child L of V, the descendents

Binary Trees

DATA STRUCTURES LABORATORY

Trees. Dr. Ronaldo Menezes Hugo Serrano Ronaldo Menezes, Florida Tech

CSCI-401 Examlet #5. Name: Class: Date: True/False Indicate whether the sentence or statement is true or false.

CS 106X Lecture 18: Trees

CS 231 Data Structures and Algorithms Fall Recursion and Binary Trees Lecture 21 October 24, Prof. Zadia Codabux

ECE Spring 2018 Problem Set #0 Due: 1/30/18

Programming II (CS300)


Search Trees. Data and File Structures Laboratory. DFS Lab (ISI) Search Trees 1 / 17

Binary Search Trees. See Section 11.1 of the text.

Trees. Truong Tuan Anh CSE-HCMUT

Revision Statement while return growth rate asymptotic notation complexity Compare algorithms Linear search Binary search Preconditions: sorted,

TREES. Trees - Introduction

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)

Discussion 2C Notes (Week 8, February 25) TA: Brian Choi Section Webpage:

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE

Solution for Data Structure

a graph is a data structure made up of nodes in graph theory the links are normally called edges

Lec 17 April 8. Topics: binary Trees expression trees. (Chapter 5 of text)

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?

! Tree: set of nodes and directed edges. ! Parent: source node of directed edge. ! Child: terminal node of directed edge

INF2220: algorithms and data structures Series 1

Chapter 8. Binary Search Trees. Fall 2013 Yanjun Li CISC Trees. Owner Jake. Waitress Waiter Cook Helper Joyce Chris Max Len

Data Structure - Binary Tree 1 -

Data Structure Lecture#10: Binary Trees (Chapter 5) U Kang Seoul National University

Trees : Part 1. Section 4.1. Theory and Terminology. A Tree? A Tree? Theory and Terminology. Theory and Terminology

Lecture 11: Multiway and (2,4) Trees. Courtesy to Goodrich, Tamassia and Olga Veksler

Trees and Graphs Shabsi Walfish NYU - Fundamental Algorithms Summer 2006

Trees (part 2) CSE 2320 Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION

Associate Professor Dr. Raed Ibraheem Hamed

CS 315 Data Structures mid-term 2

Binary Trees and Binary Search Trees

CSC122A, Spring 2005 Computer Science II Final Exam

! Tree: set of nodes and directed edges. ! Parent: source node of directed edge. ! Child: terminal node of directed edge

BST Implementation. Data Structures. Lecture 4 Binary search trees (BST) Dr. Mahmoud Attia Sakr University of Ain Shams

Chapter 5. Binary Trees

a) State the need of data structure. Write the operations performed using data structures.

Principles of Computer Science

Tree. A path is a connected sequence of edges. A tree topology is acyclic there is no loop.

Why Do We Need Trees?

Tree: non-recursive definition. Trees, Binary Search Trees, and Heaps. Tree: recursive definition. Tree: example.

Trees Algorhyme by Radia Perlman

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

DATA STRUCTURES AND ALGORITHMS. Hierarchical data structures: AVL tree, Bayer tree, Heap

COSC 2007 Data Structures II Final Exam. Part 1: multiple choice (1 mark each, total 30 marks, circle the correct answer)

Elementary Graph Algorithms CSE 6331

BBM 201 Data structures

2-3 Tree. Outline B-TREE. catch(...){ printf( "Assignment::SolveProblem() AAAA!"); } ADD SLIDES ON DISJOINT SETS

Informatik II Tutorial 2. Subho Shankar Basu

2-3 and Trees. COL 106 Shweta Agrawal, Amit Kumar, Dr. Ilyas Cicekli

DC54 DATA STRUCTURES DEC 2014

Data Structure and Algorithm Homework #3

Advanced Java Concepts Unit 5: Trees. Notes and Exercises

銘傳大學九十二學年度轉學生招生考試 七月二十六日第三節 資料結構試題

Lecture 6: Analysis of Algorithms (CS )

CE 221 Data Structures and Algorithms

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

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)

APJ ABDUL KALAM TECHNOLOGICAL UNIVERSITY THIRD SEMESTER B.TECH DEGREE EXAMINATION, JULY 2017 CS205: DATA STRUCTURES (CS, IT)

Friday, March 30. Last time we were talking about traversal of a rooted ordered tree, having defined preorder traversal. We will continue from there.

Trees. Estruturas de Dados / Programação 2 Árvores. Márcio Ribeiro twitter.com/marciomribeiro. Introduc)on. Hierarchical structure

Binary Search Trees. What is a Binary Search Tree?

R13. II B. Tech I Semester Supplementary Examinations, May/June DATA STRUCTURES (Com. to ECE, CSE, EIE, IT, ECC)

Transcription:

Scheme of valuvation 1 What is a Binary tree? State its properties? How it is represented using array and linked list, give example. binary tree is a tree data structure in which each node has at most two children, which are referred to as the left child and the right child. 1) The maximum number of nodes at level l of a binary tree is 2 l-1. 2) Maximum number of nodes in a binary tree of height h is 2 h 1. Array and linked list representation 2 Describe the Binary search tree with an example. Write the recursive function to search for a key value in binary search tree. Example with explanation struct node* search(struct node* root, int key) // Base Cases: root is null or key is present at root if (root == NULL root->key == key) return root; 2+2+2+2 4+4 3 4 // Key is greater than root's key if (root->key < key) return search(root->right, key); // Key is smaller than root's key return search(root->left, key); Write the functions to traverse a given tree using (i) inorder (ii) Postorder (iii)preorder. algorithm Inorder(tree) 1. Traverse the left subtree, i.e., call Inorder(left-subtree) 2. Visit the root. 3. Traverse the right subtree, i.e., call Inorder(right-subtree) Algorithm Preorder(tree) 1. Visit the root. 2. Traverse the left subtree, i.e., call Preorder(left-subtree) 3. Traverse the right subtree, i.e., call Preorder(right-subtree) Algorithm Postorder(tree) 1. Traverse the left subtree, i.e., call Postorder(left-subtree) 2. Traverse the right subtree, i.e., call Postorder(right-subtree) 3. Visit the root. example Write a function in c to delete a node from a given Binary search tree considering all the cases. Given a binary search tree and a key, this function deletes the key and returns the new root */ struct node* deletenode(struct node* root, int key) // base case if (root == NULL) return root; // If the key to be deleted is smaller than the root's key, // then it lies in left subtree if (key < root->key) root->left = deletenode(root->left, key); 2+2+2+2

// If the key to be deleted is greater than the root's key, // then it lies in right subtree else if (key > root->key) root->right = deletenode(root->right, key); // if key is same as root's key, then This is the node // to be deleted else // node with only one child or no child if (root->left == NULL) struct node *temp = root->right; free(root); return temp; else if (root->right == NULL) struct node *temp = root->left; free(root); return temp; // node with two children: Get the inorder successor (smallest // in the right subtree) struct node* temp = minvaluenode(root->right); // Copy the inorder successor's content to this node root->key = temp->key; // Delete the inorder successor root->right = deletenode(root->right, temp->key); return root; 5 Write a node structure for the linked representation of Polynomial. Write a function to add 2 Polynomials represented using Linked list. struct Node int coeff; int pow; struct Node *next; ; 2+6 void polyadd(struct Node *poly1, struct Node *poly2, struct Node *poly) while(poly1->next && poly2->next) // If power of 1st polynomial is greater then 2nd, then store 1st as it is // and move its pointer if(poly1->pow > poly2->pow) poly->coeff = poly1->coeff;

6 7 // If power of 2nd polynomial is greater then 1st, then store 2nd as it is // and move its pointer else if(poly1->pow < poly2->pow) poly->pow = poly2->pow; poly->coeff = poly2->coeff; // If power of both polynomial numbers is same then add their coefficients else poly->coeff = poly1->coeff+poly2->coeff; // Dynamically create new node poly->next = (struct Node *)malloc(sizeof(struct Node)); poly = poly->next; poly->next = NULL; while(poly1->next poly2->next) if(poly1->next) poly->coeff = poly1->coeff; if(poly2->next) poly->pow = poly2->pow; poly->coeff = poly2->coeff; poly->next = (struct Node *)malloc(sizeof(struct Node)); poly = poly->next; poly->next = NULL; What is Depth First Search?.Write a program to print all the nodes reachable from a vertex using dfs. DFS algorithm is to traverse the graph in such a way that it tries to go far from the root node. Stack is used in the implementation of the depth first search. void dfs(int v) int i; visited[v]=1; for(i=1;i<=n;i++) if(a[v][i] == 1&& visited[i] == 0 ) 2+6

printf("%d ", i); dfs(i); 9 10.What is graph? Give the matrix and adjacent list representation of graph? Graph: A graph is a pictorial representation of a set of objects where some pairs of objects are connected by links. The interconnected objects are represented by points termed as vertices, and the links that connect the vertices are called edges. 2 ways of representation 1.Adjacency list 2.Adjacency Matrix explanation with example. Write an algorithm for insertion sort.also trace the algorithm for the data 30, 20, 10, 40, 50, 60, 70. def insertionsort(alist): for index in range(1,len(alist)): currentvalue = alist[index] position = index while position>0 and alist[position-1]>currentvalue: alist[position]=alist[position-1] position = position-1 alist[position]=currentvalue alist = [54,26,93,17,77,31,44,55,20] insertionsort(alist) print(alist) Briefly explain the basic operations that can be performed on a file. Explain indexed Sequential file organization. File operations Explanation for indexed sequential with example What is hashing? Explain the different collision resolution techniques with example? Definition Linear probing&chaining explanation 2+3+3 4+4 2+3+3