Monotonic Stack: Conference Room Visibility

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson
Download our mobile app to listen on the go
Get App

Questions and Answers

In the context of the assignment, what is the primary goal of using a monotonically decreasing stack?

  • To efficiently determine the number of people in each column with an unobstructed view of the speaker. (correct)
  • To store the heights of all audience members.
  • To sort the audience members by height in ascending order.
  • To calculate the average height of the audience members.

What is the significance of the 'BEGIN' and 'END' strings in the input file?

  • 'BEGIN' and 'END' denote the start and end of each column's height data.
  • 'BEGIN' and 'END' indicate the start and end of the seating arrangement data. (correct)
  • 'BEGIN' marks the row where the celebrity speaker is positioned, and 'END' is the last row of the audience.
  • 'BEGIN' represents the tallest person in the audience, and 'END' represents the shortest.

If a monotonic stack is implemented such that o == 'i', what behavior does the stack exhibit when pushing elements?

  • The stack allows duplicate values and orders elements randomly.
  • The stack is monotonically increasing; it discards values larger than the value being pushed.
  • The stack is monotonically increasing; it discards values smaller than the value being pushed. (correct)
  • The stack is monotonically decreasing; it discards values smaller than the value being pushed.

Why does the assignment restrict the use of non-primitive data structures like vectors or lists, aside from the monotonic stack?

<p>To ensure students implement their own data structure for the monotonic stack, reinforcing understanding of its underlying mechanisms. (B)</p> Signup and view all the answers

In terms of code citation, what is the correct procedure for including a small snippet of code from an external source?

<p>Wrap the copied code in comments denoting the start and end of the borrowed code, along with a link or name of the source. (C)</p> Signup and view all the answers

What is the penalty for submitting code that does not compile as specified in the assignment guidelines?

<p>An automatic 50% deduction. (B)</p> Signup and view all the answers

What should the README file contain in addition to identifying information and a list of source files?

<p>A description of any known compile or runtime errors, code limitations, or deviations from the assignment specification. (C)</p> Signup and view all the answers

Why is it important for the SpeakerView class to be as Object-Oriented (OO) as possible?

<p>An elegant OO solution will receive more credit than procedural spaghetti code. (C)</p> Signup and view all the answers

How does the program determine if a person in a particular seat has an unobstructed view of the speaker?

<p>By using a monotonically decreasing stack to ensure each person is taller than everyone in front of them in the same column. (A)</p> Signup and view all the answers

What is the expected method for compiling the code for this assignment??

<p>Using <code>g++</code> with appropriate flags within the course docker container. (B)</p> Signup and view all the answers

Flashcards

Monotonic Stack

Elements appear in monotonically increasing or decreasing order from the bottom to the top.

Monotonic Stack's Push Function

A LIFO data structure that ensures values remain in monotonically increasing or decreasing order.

SpeakerView Class

A class to analyze a text file of heights to determine how many people can see a speaker.

Assignment Goal

Determine how many people in each column have an unobstructed view of the speaker.

Signup and view all the flashcards

Study Notes

  • Programming Assignment 3 focuses on determining how many people have an unobstructed view of a speaker in a conference room setup
  • The conference room has chairs arranged in an N x P rectangle and event planners want to ensure shorter audience members can see the speaker, even with taller people in front
  • Help is requested to determine candidate seat assignments, provided in a text file with N lines, each having P entries representing the heights of people assigned to seats

Problem Solving with Stacks

  • A monotonic stack is crucial for solving the problem. It is a stack where elements are either monotonically increasing or decreasing from bottom to top
  • Duplicate values are not allowed
  • The "push" function differs from traditional stacks by ensuring values remain in the correct order. In an increasing stack, values larger than the new value are popped before pushing
  • Other stack operations remain the same

Implementation Details

  • A templated monotonic stack must be built and called MonoStack. It is based on array-based stack
  • The constructor takes an initial stack size and a character o as parameters
  • When o is 'i', the stack is monotonically increasing, 'd' indicates decreasing
  • The implementation should handle error conditions appropriately for stack methods

"One Way Only"

  • "Monotonic" means that the stack must maintain a consistent increasing or decreasing order from bottom to top

Program Requirements

  • SpeakerView Class: A SpeakerView class building is required. It takes a plain text file with N+2 lines.
  • The first line is “BEGIN,” the last line is “END,” and the N lines in between consist of P doubles (heights) separated by spaces
  • The program employs a monotonically decreasing stack to count visible people in each column and their heights
  • The output should be descriptive and displayed to the terminal

Main File

  • A main.cpp must be built that takes the input file as a command line argument and computes the output using the SpeakerView class

Restrictions

  • Non-primitive data structures (vectors, lists, etc.) cannot be used, apart from your own monotonic stack implementation
  • The assignment must be completed individually using VSCode, ensuring the code runs correctly with g++ using a course docker container

Code Integrity

  • External C++ IO operations can be used, but must be cited in a README file
  • All code must be original

Submission Details

  • The assignment is due on the specified day and time on Canvas
  • Submit all commented code as a zip file named LastName_FirstInitial_A3.zip

Grading Criteria

  • Grades are based on correctness, following guidelines, and code quality, including meaningful comments
  • An elegant, object-oriented solution will receive more credit
  • C++ standard style guide must be followed (refer to the course page on Canvas)
  • Code not following specifications will receive a 25% deduction and code not compiling results in a 50% deduction

Readme File Requirements

  • A README file must accompany all source code
  • The README file should include your full name, student ID, Chapman email, course number and section, and assignment number

Additional Information in Readme

  • A list of all source files submitted
  • Any known compile or runtime errors, code limitations, or deviations from the specification
  • A list of references used
  • Instructions for running your assignment (compiling with g++ *.cpp -o A1.exe and running with ./A1.exe input.txt output.html)

In-Code Citations

  • Small, isolated lines of code from external sources are allowed with appropriate citations
  • Copied code must be wrapped in comments indicating the source, including the link/name of the source
  • All source files should start with a header comment containing full name, student ID, Chapman email, course number and section, and assignment number, each on a new line

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Related Documents

More Like This

Understanding Monotonic Sequences
12 questions
Monotonic Sequence Quiz
12 questions
Khảo sát hàm số lớp 10
8 questions
Use Quizgecko on...
Browser
Browser