Assignment 4 Trees and Heaps

Similar documents
Binary Trees

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

Trees. Q: Why study trees? A: Many advance ADTs are implemented using tree-based data structures.

Binary Trees, Binary Search Trees

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

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

Trees. Tree Structure Binary Tree Tree Traversals

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

Associate Professor Dr. Raed Ibraheem Hamed

March 20/2003 Jayakanth Srinivasan,

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

Tree Structures. A hierarchical data structure whose point of entry is the root node

Programming II (CS300)

Trees and Tree Traversals. Binary Trees. COMP 210: Object-Oriented Programming Lecture Notes 8. Based on notes by Logan Mayfield

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

Trees. CSE 373 Data Structures

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

Trees. Truong Tuan Anh CSE-HCMUT

Uses for Trees About Trees Binary Trees. Trees. Seth Long. January 31, 2010

Algorithms in Systems Engineering ISE 172. Lecture 16. Dr. Ted Ralphs

Binary search trees. Binary search trees are data structures based on binary trees that support operations on dynamic sets.

CS3114 (Fall 2013) PROGRAMMING ASSIGNMENT #2 Due Tuesday, October 11:00 PM for 100 points Due Monday, October 11:00 PM for 10 point bonus

1. Stack overflow & underflow 2. Implementation: partially filled array & linked list 3. Applications: reverse string, backtracking

Programming II (CS300)

Trees. Trees. CSE 2011 Winter 2007

Data Structures and Algorithms for Engineers

CSE 230 Intermediate Programming in C and C++ Binary Tree

CE 221 Data Structures and Algorithms

COSC 2011 Section N. Trees: Terminology and Basic Properties

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?

Binary Trees. Directed, Rooted Tree. Terminology. Trees. Binary Trees. Possible Implementation 4/18/2013

Chapter 4 Trees. Theorem A graph G has a spanning tree if and only if G is connected.

BBM 201 Data structures

CS 280 Problem Set 10 Solutions Due May 3, Part A

Computer Science 210 Data Structures Siena College Fall Topic Notes: Trees

Chapter 20: Binary Trees

Data Structures. Binary Trees. Root Level = 0. number of leaves:?? leaves Depth (Maximum level of the tree) leaves or nodes. Level=1.

Analysis of Algorithms

Also, recursive methods are usually declared private, and require a public non-recursive method to initiate them.

Trees 11/15/16. Chapter 11. Terminology. Terminology. Terminology. Terminology. Terminology

Computational Optimization ISE 407. Lecture 16. Dr. Ted Ralphs

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

Data Structures and Algorithms

Programming II (CS300)

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

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

Part 1: Written Questions (60 marks):

7.1 Introduction. A (free) tree T is A simple graph such that for every pair of vertices v and w there is a unique path from v to w

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

Binary search trees 3. Binary search trees. Binary search trees 2. Reading: Cormen et al, Sections 12.1 to 12.3

CS301 - Data Structures Glossary By

CSC/MAT-220: Lab 6. Due: 11/26/2018

Todays Lecture. Assignment 2 deadline: You have 5 Calendar days to complete.

Trees (Part 1, Theoretical) CSE 2320 Algorithms and Data Structures University of Texas at Arlington

Data Structures - Binary Trees and Operations on Binary Trees

CSE 143 Final Exam Part 1 - August 18, 2011, 9:40 am

Writeup for first project of CMSC 420: Data Structures Section 0102, Summer Theme: Threaded AVL Trees

binary tree empty root subtrees Node Children Edge Parent Ancestor Descendant Path Depth Height Level Leaf Node Internal Node Subtree

Sample Exam 1 Questions

CS2110 Assignment 3 Inheritance and Trees, Summer 2008

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

Lecture 26. Introduction to Trees. Trees

Binary Tree. Preview. Binary Tree. Binary Tree. Binary Search Tree 10/2/2017. Binary Tree

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

Trees. A tree is a directed graph with the property

Chapter 11.!!!!Trees! 2011 Pearson Addison-Wesley. All rights reserved 11 A-1

Chapter 11.!!!!Trees! 2011 Pearson Addison-Wesley. All rights reserved 11 A-1

Definitions A A tree is an abstract t data type. Topic 17. "A tree may grow a. its leaves will return to its roots." Properties of Trees

Lecture Notes 16 - Trees CSS 501 Data Structures and Object-Oriented Programming Professor Clark F. Olson

Introduction to Computers and Programming. Concept Question

UNIVERSITY OF MASSACHUSETTS LOWELL Department of Electrical and Computer Engineering. Program 8 EECE.3220 Data Structures Fall 2017

Binary Trees Fall 2018 Margaret Reid-Miller

9/29/2016. Chapter 4 Trees. Introduction. Terminology. Terminology. Terminology. Terminology

Lecture 6: Analysis of Algorithms (CS )

COMP : Trees. COMP20012 Trees 219

MLR Institute of Technology

Solution to CSE 250 Final Exam

Why Do We Need Trees?

INF2220: algorithms and data structures Series 1

n 2 ( ) ( ) Ο f ( n) ( ) Ω B. n logn Ο

TREES. Trees - Introduction

Runtime Environments I. Basilio B. Fraguela

CSE2331/5331. Topic 6: Binary Search Tree. Data structure Operations CSE 2331/5331

Garbage Collection: recycling unused memory

Binary Trees Due Sunday March 16, 2014

Binary Search Trees Part Two

Successor/Predecessor Rules in Binary Trees

CSE 250 Final Exam. Fall 2013 Time: 3 hours. Dec 11, No electronic devices of any kind. You can open your textbook and notes

Data Structures Question Bank Multiple Choice

Principles of Computer Science

TREES Lecture 10 CS2110 Spring2014

TREES Lecture 12 CS2110 Fall 2016

CSI33 Data Structures

CSE 100 Advanced Data Structures

Design and Analysis of Algorithms Lecture- 9: Binary Search Trees

Compuer Science 62 Assignment 10

Data Structure and Algorithm Homework #3 Due: 2:20pm, Tuesday, April 9, 2013 TA === Homework submission instructions ===

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

Introduction. for large input, even access time may be prohibitive we need data structures that exhibit times closer to O(log N) binary search tree

Transcription:

Objectives Assignment 4 Trees and Heaps Release Date Due Date 3/15/2018 3/27/2018 To learn how to implement various types of trees, heaps, and traversals. Introduction You have just accepted a brand new software engineering internship on the Death Star. Grand Moff Tarkin wants a database of all living things in the universe. Luckily, you re just an intern, so you only have to code a small part of the prototype. Your job will be to implement various forms of tree data structures and various related algorithms. You will create a binary search tree, balanced min and max heaps, and algorithms related to them. Problem Specification Note: In this assignment you are NOT allowed to use Java s (or other languages ) default heap/tree/etc. utilities. This assignment will have six main parts: Part A: Reading data Part B: Array-based min heap Part C: Explicit height balanced max heap Part D: Binary search tree Part E: Generate test data Part F: Extra credit challenges Overview 1) Your program should be set up to receive two command line arguments. These two arguments will specify two input files for your program. Both input files will match the format of starwars.txt. The two arguments will represent the following: A data file with names to store. A data file with names to search for. (We will be testing your program with our own test files. Make sure your program can handle input files of any length.) 2) Your program will store the data from the first file into various data structures and then read the data from the second file and search for each name in it in your previously built structures. For duplicates, report the first hit. 1

Part A: Reading data 1) Your program should read two command line arguments specifying data files to read. The format of these data files will be that of starwars.txt. 2) Read the data from the first specified input file and store it in an array for later use. This array will be referred to as the "first array" in these instructions. 3) Read the data from the second specified input file and store it in another array for later use. This array will be referred to as the "second array" in these instructions. Part B: Array-based min heap 3) Create an implicit (array-based) min heap. 4) Insert all of the names in the first array into your heap. Report the average time it takes to insert a name. 5) Print out the contents of the heap via a preorder traversal. 6) Print the minimum and maximum values stored in the heap and output the time taken to find each. 7) Search your heap for each name from the second array. If the name is found, report the following: The index of the heap's internal array where the name was found. The depth of the node represented by the index. (The root node has a depth of 0). The size of the subtree where the name was found. Size is defined as the number of nodes. 8) Make sure to also account for when names are not found. 9) For duplicates, report the first hit. 10) Report the average time spent searching for a name. Part C: Explicit height balanced max heap 1) Create an explicit (node-based) max heap. You might need to create a node class to go with it. 2) The max heap should be height balanced. In a height balanced tree, the following holds true for all nodes: H L - H R 1. (where H L and H R are the heights of a node s left and right subtrees, respectively.) 3) Again, insert all of the names in the first array into your heap and report the average time it takes to insert a name. 4) Print out the contents of the heap with a postorder traversal. 5) Again, print the minimum and maximum values stored in the heap and output the time taken to find each. 6) Again, search for each name from the second array and report: The depth of the node. (The root node has a depth of 0). The size of the subtree where the name was found. 7) Again, make sure to account for when names are not found. 8) For duplicates, report the first hit. 9) Again, report the average time spent searching for a name. Part D: Binary search tree 1) Create a binary search tree class. Again, this will be of an explicit representation. 2) Again, insert all of the names in the first array into your search tree and report the average time it takes to do so. 3) Print out the contents of the tree with an inorder traversal. 4) Again, print the minimum and maximum values stored in the tree and output the time taken to find each. 5) Again, search for each name from the second array and report: The depth of the node. (The root node has a depth of 0). The size of the subtree where the name was found. 6) Make sure to account for when names are not found. For duplicates, report the first hit. 7) Again, report the average time spent searching for a name. 2

Part E: Generate test data 1) After generating output for your first run, generate a random number n. Use this value to pick out n random strings from your first array (there can be duplicates) and create your all your trees using the selected strings. 2) Repeat this part for the following values of n. (You can generate for other values of n as well.) n = 10 n = 100 n = 500 Print out your value of n before printing out the test case. Part F: Challenges (Extra credit) The diameter of this tree is 7. From node 4/7 to node 13. 1) In each of your heap/tree classes, include a method to determine the diameter of the heap/tree. The diameter of a heap/tree is equal to the number of nodes on the longest path between any two nodes without repeating a node. (+5) 2) In each of your heap/tree classes, include a method to find the Lowest Common Ancestor of two nodes. The Lowest Common Ancestor (LCA) of two nodes is the lowest (i.e. deepest) node that has both nodes as descendants, where we define each node to be a descendant of itself as well. (+5) The LCA of 4 and 7 is 6. The LCA of 7 and 13 is 8. The LCA of 1 and 3 is 3. If you do any of these challenges, please indicate that you've done so in your readme file. 3

Sample output Min heap: Preorder traversal: C-3PO, OBI-WAN, R2-D2, LUKE Found at index 2. Found at index 1. Found at index 0. Found at index 3. Max heap: Postorder traversal: LUKE, OBI-WAN, C-3PO, R2-D2 The following output is from using the starwars_tiny.txt file for both inputs Binary search tree: Inorder traversal: C-3PO, LUKE, OBI-WAN, R2-D2 4

Submission Requirements Output Requirements All your output should be printed to the console as well as a text file. Code Documentation You must include documentation for your code. This means that you should include detailed information on the usage of your program as a whole, as well as each function/class within it. This can be accomplished via Javadoc or you can hand-type the documentation. This includes how to compile and run your program. Analysis Report Write a brief report (submitted as a.pdf file) on your observations of comparing theoretical vs empirically observed time complexities. This report should include: A brief description of problem statement(s). Algorithm descriptions (if these are standard, commonly known algorithms, then just mention their names along with customization to your specific solution(s), otherwise give the pseudo-code of your algorithms. Theoretically derived complexities of the algorithms used in your code Table(s) of the observed times. Plots comparing the measured times vs. bigger input files. (As n grows, how do your measured times grow?) Plots comparing theoretical vs. empirical along with your observations (e.g. do theoretical agree with your implementation, why? Why not?). Coding Conventions and Programming Standards You must adhere to all conventions in the CS 3310 Java coding standard. This includes the use of white spaces for readability and the use of comments to explain the meaning of various methods and attributes. Be sure to follow the conventions for naming files, classes, variables, method parameters and methods. Read the material linked from our class web-pages (in case you can t recall programming styles and conventions from your CS1 and CS2 courses). Assignment Submission Generate a.zip file that contains all your files, including: Signed Plagiarism Declaration Source code files The original data input files Your sample output files Documentation of your code Your analysis report Don t forget to follow the naming convention specified for submitting assignments. 5