Data Structures and Algorithms Lab Exercises, Thesis of Data Mining

Implement a complex ADT and algorithm in an executable programming language to solve a well defined problem.

Typology: Thesis

2015/2016

Uploaded on 11/06/2021

hai-nguyen-14
hai-nguyen-14 🇻🇳

4.4

(7)

5 documents

1 / 16

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Exercise #1
1. Download and install Java Development Kit 17.0.1
2. Set your Java environment path
3. Use Notepad/TextEdit to create a single Main.java file
containing single public static void main(String[] args)
method within the Main class to print “Welcome to ADS
course!” to the screen
4. Compile and run your code
5. Now, install your favourite IDE (e.g. Visual Studio Code)
and try to compile and run your code inside your IDE again
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Data Structures and Algorithms Lab Exercises and more Thesis Data Mining in PDF only on Docsity!

Exercise

1. Download and install Java Development Kit 17.0.

2. Set your Java environment path

3. Use Notepad/TextEdit to create a single Main.java file

containing single public static void main(String[] args)

method within the Main class to print “Welcome to ADS

course!” to the screen

4. Compile and run your code

5. Now, install your favourite IDE (e.g. Visual Studio Code)

and try to compile and run your code inside your IDE again

https://www.oracle.com/java/technologies/downloads/#jdk

7-windows

JDK

IDE (Visual

Studio Code)

1. Create an ArrayList interface java file:

public interface ArrayList {
boolean add (E element)
boolean add (int index, E element);
E get (int index);
E set (int index, E element);
E remove (int index);
int size ();
int indexOf (E element);
boolean contains (E element);
boolean isEmpty ();

2. Following the instructions in “2_Lab2 Data-

Structures-Linear-Data-Structures-Lab.doc” to

create an ADS List class , which implements

the above ArrayList interface.

3. Test your ADT with these codes in your

Main.java file

var l1 = new ADSList();
l1.add( 0 , 2 );
l1.add( 1 , 4 );
l1.add( 2 , 8 );
l1.add( 3 , 16 );
l1.set( 2 , 32 );
l1.remove( 0 );
System.out.println("ArrayList");
System.out.println("Size: "+l1.size());
System.out.println("Index of 32: "+l1.index
Of( 32 ));
System.out.println("Contains 16: "+l1.conta
ins( 16 ));

Excercise

1. Create a Node class java file

public class Node {

E element;

Node next;

Node previous;

public Node(E value) {

this.element = value;

2. Create a Stack interface java file in the

same folder

public interface Stack {

void push (E element);

E pop();

E peek();

int size();

boolean isEmpty();

3. Following the instructions in “2_Lab2 Data-

Structures-Linear-Data-Structures-Lab.doc” to

create an ADSStack class , which

implements the above Stack interface.

4. Test your ADT with these codes in your

Main.java file

var s1 = new ADSStack();

s1.push( 10 );

s1.push( 20 );

s1.push( 30 );

System.out.println("Stack");

System.out.println("Peek: "+s1.peek(

System.out.println("Pop: "+s1.pop())

System.out.println("Size after pop:

"+s1.size());

Excercise

CMS Key

SUBJECT COURSE DETAIL Class Lecturer CMS Link

Enrollme

nt Key

Data Structures &

Algorithms

GCD0807A

vinhtnx https://cms.greenwich.e

du.vn/course/view.php?i

d=

aZirj

Data Structures &

Algorithms

GCD0807B

vinhtnx https://cms.greenwich.e

du.vn/course/view.php?i

d=

aZirj

1. Create a LinkedList interface java file:

public interface LinkedList { void addFirst (E element); void addLast (E element); E removeFirst(); E removeLast(); E getFirst(); E getLast(); int size(); boolean isEmpty(); }

2. Following the instructions in “2_Lab2 Data-

Structures-Linear-Data-Structures-Lab.doc” to

create an ADSLinkedList class , which

implements the above LinkedList interface.

3. Test your ADT with these codes in your

Main.java file

var ll1 = new ADSLinkedList(); ll1.addFirst( 1 ); ll1.addFirst( 3 ); ll1.addFirst( 5 ); ll1.addLast( 7 ); ll1.addLast( 9 ); ll1.removeFirst(); ll1.removeLast(); System.out.println("Linked List"); System.out.println("Size: "+ll1.size()); System.out.println("First: "+ll1.getFirst ()); System.out.println("Last: "+ll1.getLast() );

Excercise

1. Create a LinkedList interface java file:

public interface LinkedList { void addFirst (E element); void addLast (E element); E removeFirst(); E removeLast(); E getFirst(); E getLast(); int size(); boolean isEmpty(); }

2. Download and complete the

ADSLinkedList class java file from CMS.

3. Test your ADT with these codes in your

Main.java file

var ll2 = new ADSLinkedList(); System.out.println("Is Empty?: "+ll2.isEmpty ()); System.out.println("First: "+ll2.getFirst()) ; ll2.addFirst( 100 ); ll2.addFirst( 500 ); ll2.addLast(ll2.removeFirst()); System.out.println("Last: "+ll2.getLast());

Excercise

Class Key

GCD0807A aZirj

GCD0807B aZirj

1. Following the instructions in the guidance to create the following functions:

  • (^) static int sum(int[] array, int index) {}
  • (^) static long factorial(int num) {}
  • (^) static void printFigure(int n) {}
  • (^) static void generateVector(int index, int[] vector) {}

2. Test your functions with these codes in your Main.java file

int[] array1 = { 1 , 2 , 3 , 4 };

int[] array2 = {- 1 , 0 , 1 };

System.out.println("Sum of array1 = "+sum(array1, 0 ));

System.out.println("Sum of array2 = "+sum(array2, 0 ));

System.out.println("Factorial of 10 = "+factorial( 10 ));

printFigure( 5 );

int[] vector = { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 };

generateVector( 0 , vector);

Exercise

  1. Following the instructions in the guidance to implement a labyrinth class Labyrinth{ static int height = 0 ; static int width = 0 ; static char[][] labyrinth; static List path = new ArrayList<>(); public static void main(String args[]){ if (args.length > 2 ) { height = Integer.parseInt(args[ 0 ]); width = Integer.parseInt(args[ 1 ]); labyrinth = new char[height][width]; for (int i = 0 ; i < height; i++) { for (int j = 0 ; j < width ; j++) { labyrinth[i][j] = args[i+ 2 ].charAt(j); } } findPaths( 0 , 0 , ' '); } } static void findPaths(int row, int col, char direction) { //Your codes here } }
  2. Test your labyrinth java Labyrinth 3 3 --- -*- --e

Exercise

Find the complexities of the algorithms in

17_Lab 4 - Algorithm Analysis_Student:

Exercise

No Program Complexity