COMP2336_Assignmet_2

.docx

School

Prairie View A&M University *

*We aren’t endorsed by this school

Course

2336

Subject

Computer Science

Date

Dec 6, 2023

Type

docx

Pages

4

Uploaded by martaesia1216

Assignment 2 COMP 2336 – Data Structures and Algorithms Fall 2023 Dr. Noushin Ghaffari Important notes: Due Date: 10/11/23, 10:00 AM  Deliverable: Option 1: A Microsoft Word document or a PDF file submitted on PVAMU Canvas Option 2: all the answers can be typed on Canvas editor directly All the questions are from the textbook and instructor lectures. The answers are in the book, slides or were mentioned in the class. Individual assignment: no team work is allowed. Follow all the university rules from the student handbook regarding plagiarism and honesty. Wishing you the best! Use this assignment as a great way to review class material one more time and utilize them in your work. 1. Indicate whether a stack would be a suitable data structure for each of the following applications. Elaborate your answer. (8 points) a) A program to evaluate arithmetic expressions according to the specific order of operators Yes, a stack is suitable because stacks are usually used for assessing arithmetic methods, and a stack helps keep track of the particular order. b) A bank simulation of its teller operation to see how waiting times would be affected by adding another teller No, a stack would not be suitable because this application deals with First In, First Out, which are queues. Stacks handle Last In, First Out. c) A program to receive data that are to be saved and processed in the reverse order Yes, a stack is suitable because as this application is being pushed in, when the application is being processed in reverse order, it will pop out. d) An address book to be maintained Maybe a stack could be suitable depending on what the address book is being maintained on. If a stack were being used to track recently added addresses, then a stack would be appropriate. 2. (Multiple choice (4 points)) The statements stack.Push(item1 + 1); stack.Pop(item1 + 1);
in the client program a) would cause a syntax error at compile time. b) would cause a run-time error c) would be legal, but would violate the encapsulation of the stack d) would be perfectly legal and appropriate. 3. Show what is written by the following segments of code, given that item1, item2, and item3 are int variables. Show step by step what would be stored in each variable after each line of the code. (18 points) Hint: the code for question is already provided. You need to trace the code and show the outputs in each step. Basically show the stack contents in different stages, after each push and pop and print operation. You can use pen and pencil and then scan your answers or just use a table in word for example. a) Answers on the next page
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help