Document Algorithm and Data stucture, Thesis of Algorithms and Programming

nothing but simple and also nothing

Typology: Thesis

2021/2022

Uploaded on 10/05/2022

otis-3
otis-3 🇻🇳

1 document

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Page 1 of 4
Lab: Trees Representation and Traversal
(BFS, DFS)
Write Java code for solving the tasks on the following pages. Code should compile under the Java 8 and above
standards you can write and locally test your solution with the Java 13 standard, however Judge will run the
submission with Java 10 JRE. Avoid submissions with features included after Java 10 release doing otherwise will
result in compile time error.
Any code files that are part of the task are provided as Skeleton. In the beginning import the project skeleton, do
not change any of the interfaces or classes provided. You are free to add additional logic in form of methods in both
interfaces and implementations you are not allowed to delete or remove any of the code provided. Do not change
the names of the files as they are part of the tests logic. Do not change the packages or move any of the files
provided inside the skeleton if you have to add new file add it in the same package of usage.
Please follow the exact instructions on uploading the solutions for each task. Submit as .zip archive the files
contained inside "...\src\main\java" folder this should work for all tasks regardless of current DS implementation.
In order for the solution to compile the tests successfully the project must have single Main.java file containing
single public static void main(String[] args) method even empty one within the Main class.
Some of the problem will have simple Benchmark tests inside the skeleton. You can try to run those with different
values and different implementations in order to observe behaviour. However keep in mind that the result comes
only as numbers and this data may be misleading in some situations. Also the tests are not started from the
command prompt which may influence the accuracy of the results. Those tests are only added as an example of
different data structures performance on their common operations.
The Benchmark tool we are using is JMH (Java Microbenchmark Harness) and that is Java harness for building,
running, and analyzing, nano/micro/milli/macro benchmarks written in Java and other languages targeting, the
JVM.
Additional information can be found here: JMH and also there are other examples over the internet.
Important: when importing the skeleton select import project and then select from maven module, this way any
following dependencies will be automatically resolved. The project has NO default version of JDK so after the
import you may (depends on some configurations) need to specify the SDK, you can download JDK 13 from HERE.
Your task is to implement the ADS AbstractTree<E> inside the Tree<E> class provided. You have to implement all
the methods in order to solve the problems below each problem is a single task, however you are free to add more
methods with any access modifier you want.
pf3
pf4

Partial preview of the text

Download Document Algorithm and Data stucture and more Thesis Algorithms and Programming in PDF only on Docsity!

Lab: Trees Representation and Traversal

(BFS, DFS)

Write Java code for solving the tasks on the following pages. Code should compile under the Java 8 and above standards you can write and locally test your solution with the Java 13 standard, however Judge will run the submission with Java 10 JRE. Avoid submissions with features included after Java 10 release doing otherwise will result in compile time error. Any code files that are part of the task are provided as Skeleton. In the beginning import the project skeleton, do not change any of the interfaces or classes provided. You are free to add additional logic in form of methods in both interfaces and implementations you are not allowed to delete or remove any of the code provided. Do not change the names of the files as they are part of the tests logic. Do not change the packages or move any of the files provided inside the skeleton if you have to add new file add it in the same package of usage. Please follow the exact instructions on uploading the solutions for each task. Submit as .zip archive the files contained inside "...\src\main\java" folder this should work for all tasks regardless of current DS implementation. In order for the solution to compile the tests successfully the project must have single Main.java file containing single public static void main(String[] args) method even empty one within the Main class. Some of the problem will have simple Benchmark tests inside the skeleton. You can try to run those with different values and different implementations in order to observe behaviour. However keep in mind that the result comes only as numbers and this data may be misleading in some situations. Also the tests are not started from the command prompt which may influence the accuracy of the results. Those tests are only added as an example of different data structures performance on their common operations. The Benchmark tool we are using is JMH (Java Microbenchmark Harness) and that is Java harness for building, running, and analyzing, nano/micro/milli/macro benchmarks written in Java and other languages targeting, the JVM. Additional information can be found here: JMH and also there are other examples over the internet. Important: when importing the skeleton select import project and then select from maven module, this way any following dependencies will be automatically resolved. The project has NO default version of JDK so after the import you may (depends on some configurations) need to specify the SDK, you can download JDK 13 from HERE. Your task is to implement the ADS AbstractTree inside the Tree class provided. You have to implement all the methods in order to solve the problems below each problem is a single task, however you are free to add more methods with any access modifier you want.

1. Create Tree

Implement the Tree class's constructor to set the correct key and to be able to build full tree by accepting all the children for each node. Also make sure to create the proper fields.

Solution:

2. BFS Traversal

Implement the Tree class's public List orderBfs () method which should traverse the elements in order of each level sequentially be careful the order of output matters.

Solution:

Remove( )

6. Swap Nodes

This time you have to find a Tree nodes with a specified keys and swap them. Now this problem is a bit harder. But you have all the knowledge required. So what you have to do is swap two nodes alongside their descendants. Keep in mind that swapping should also arrange the references inside the nodes in a proper way. Think about the edge cases what will happen if we attempt to swap the root with a leaf. Or in this order one of the middle nodes with a leaf etc… For this task the tests will traverse the nodes in BFS order. Note: if there are no nodes simply return an empty List.

Example:

Initial Tree Operation Result Tree Swap(19,

"The first principle is that you must not fool yourself and you are the easiest person to fool." ― Richard Feynman