Anda di halaman 1dari 3

COMP 2140 Data Structures and Algorithms Assignment 1

Due Date:
The assignment is due at 11:59 PM (Winnipeg time), May 24, 2016 (Tuesday)

Skill Examined:

Review of programming concepts


Stacks and queues

Hand-In Instructions:

Submit one zip file containing one pdf file and .java files
You must use the following structure for the zip file name: FamilyName_First-
Name_A1_Vx.zip, substituting your own family name and first name for the respective parts
and using for x the version number of your file. For example, the second version of a
submission from student Mohammad Hasan should be saved as
Hasan_Mohammad_A1_V2.zip.
The pdf file should contain your answers for problem 1, 2 and 3
One .java file must contain all the source code that you wrote for the problem 4
Another java file should contain all the source code that you wrote for the problem 5
Please do not submit class files or output files with your submission
Make sure you submit the required file through the course web site (Login to UM Learn,
then click on Assessments. Go to Dropbox/Assignments and use Assignment 1 link to
submit the assignment)

Please remember that you must upload a signed Blanket Honesty Declaration in UM
Learn before you submit your first assignment. See the course web site for details.

Problem 1 [2 marks].
The two most important operations on the Stack ADT are push and pop. push adds a new item to
the top of the stack and pop removes and return the item from the top of the stack. Now, consider
an initially empty stack and find the final output for the following sequence of stack operations:

push(1);
push(4);
push(2);
pop();
pop();
push(2);
push(4);
push(7);
pop();

Page 1 of 3
COMP 2140 Data Structures and Algorithms Assignment 1

pop();
push(3);
push(4);
pop();
push(5);
pop();

Problem 2 [2 marks].
The enqueue operation on the Queue ADT adds a new item to the back of the queue where the
dequeue operation removes and returns the item from the front of the queue. Now consider an
initially empty queue and find the final output for the following sequence of queue operations:

enqueue(7);
enqueue(9);
enqueue(1);
dequeue();
enqueue(8);
dequeue();
dequeue();
enqueue(6);
enqueue(3);
dequeue();
enqueue(2);
enqueue(1);
dequeue();

Problem 3 [1+2 Marks].


What is the main difference between Queue and Priority Queue? Specify four real-world
applications that benefit from Queue and Deque (two applications for each of them).

Problem 4 [5 Marks].
The sample Stack implementation in Unit 2 (under the UM Learn course materials) has a fixed limit
on the maximum number of items that can be stored (up to maxSize) and the program shows
message (i.e., Stack full) while the stack is full. Now modify the Unit 2 sample stack
implementation to (i) make more space available by resizing the stack when necessary and (ii)
show the sum of values stored in the stack at any time.

Page 2 of 3
COMP 2140 Data Structures and Algorithms Assignment 1

Problem 5 [8 Marks].
Write a program in Java to determine whether a string of characters entered from the keyboard is a
palindrome, i.e. the string reads the same both forwards and backwards. The program should store
user input into both a stack and a queue of characters. After all the characters are entered, compare
the contents of the stack and queue using pop and dequeuer operations. If the contents are the
same, the string reads the same forwards and backwards, thus it is a palindrome. If a mismatch is
found, the string is not a palindrome.

Note:

(i) The program should ignore the case of letters (i.e. a and A are the same) when comparing

(ii) It should also ignore blanks and punctuation

Page 3 of 3

Anda mungkin juga menyukai