College of Computing and Informatics Pg. 03 Question Three Assignment 2 Deadline:

College of Computing and Informatics

Pg. 03

Question Three

Assignment 2

Deadline: Thursday 18/11/2021 @ 23:59

[Total Mark for this Assignment is 5]

Assignment 2

Deadline: Thursday 18/11/2021 @ 23:59

[Total Mark for this Assignment is 5]

Computer Programming – II

CS141

Computer Programming – II

CS141

Instructions:

You must submit two separate copies (one Word file and one PDF file) using the Assignment Template on Blackboard via the allocated folder. These files must not be in compressed format.

It is your responsibility to check and make sure that you have uploaded both the correct files.

Zero mark will be given if you try to bypass the SafeAssign (e.g. misspell words, remove spaces between words, hide characters, use different character sets or languages other than English or any kind of manipulation).

Email submission will not be accepted.

You are advised to make your work clear and well-presented. This includes filling your information on the cover page.

You must use this template, failing which will result in zero mark.

You MUST show all your work, and text must not be converted into an image, unless specified otherwise by the question.

Late submission will result in ZERO mark.

The work should be your own, copying from students or other resources will result in ZERO mark.

Use Times New Roman font for all your answers.

Instructions:

You must submit two separate copies (one Word file and one PDF file) using the Assignment Template on Blackboard via the allocated folder. These files must not be in compressed format.

It is your responsibility to check and make sure that you have uploaded both the correct files.

Zero mark will be given if you try to bypass the SafeAssign (e.g. misspell words, remove spaces between words, hide characters, use different character sets or languages other than English or any kind of manipulation).

Email submission will not be accepted.

You are advised to make your work clear and well-presented. This includes filling your information on the cover page.

You must use this template, failing which will result in zero mark.

You MUST show all your work, and text must not be converted into an image, unless specified otherwise by the question.

Late submission will result in ZERO mark.

The work should be your own, copying from students or other resources will result in ZERO mark.

Use Times New Roman font for all your answers.

Student Details:

Name: ###

CRN: ###

ID: ###

Student Details:

Name: ###

CRN: ###

ID: ###

2 Marks

2 Marks

Learning Outcome(s): LO5

Evaluate data structures for efficient data representation and organization with demonstrable results.

Learning Outcome(s): LO5

Evaluate data structures for efficient data representation and organization with demonstrable results.Question One

Write a Java program to create two stacks and pop the top elements from the two stacks and then do the followings:

Add the top two elements and push the result into a new stack named stack3

Subtract the top two elements and push the result into stack3

Multiply the top two elements and push the result into stack3

Divide the top two elements and push the result into stack3

Find the remainder of the top two elements and push the result into stack3

Sample run:

stack1 elements[6, 5, 10]

stack2 elements[2, 4, 8]

stack3 elements[18, 2, 80, 1, 2]

Answer:

1 Mark

1 Mark

Learning Outcome(s): LO1

Describe basic and advanced data structures such as linked lists, stacks, and queues.

Learning Outcome(s): LO1

Describe basic and advanced data structures such as linked lists, stacks, and queues.Question Two

Show the result of inserting 10, 12, 5, 4, 20, 8, and 7 one at a time, into an initially empty binary heap (minheap).

Answer:

2 Marks

2 Marks

Learning Outcome(s): LO4

Demonstrate implemented solution with appropriate data structure and algorithm for the assigned problem.

Learning Outcome(s): LO4

Demonstrate implemented solution with appropriate data structure and algorithm for the assigned problem.Question Three

Write a Java program that prints all the leaf nodes of a binary tree. Use the following binary tree as a sample input.

100

50

20

60

90

300

150

70

100

50

20

60

90

300

150

70

Output sample:

The Leaf nodes: 20, 90, 300

Answer: