Preview

C++ Algorithm

Good Essays
Open Document
Open Document
1077 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
C++ Algorithm
c++ 1. (10 points) Consider the usual algorithm to convert a fully parenthesized infix expression to a postfix expression. Suppose that you have read 10 input characters during a conversion and that the stack now contains these symbols:

| | | + | | ( | bottom |___*___|

Now, suppose that you read and process the 11th symbol of the input. Draw the stack for the case where the 11th symbol is:

A. A number:

B. A left parenthesis:

C. A right parenthesis:

D. A minus sign:

E. A division sign but change the algorithm to the general case (not fully parenthesized):

2. (4 points) Entries in a stack are "ordered". What is the meaning of this statement?

A. There is a first entry, a second entry, and so on.

B. A collection of Stacks can be sorted.

C. Stack entries may be compared with the compareTo method.

D. The entries must be stored in a linked list.
3. (4 points) Which of the following stack operations could result in stack underflow? A peek B. pop C. push D. Two or more of the above answers.

4. (4 points) Suppose we have an array implementation of the stack class, with twelve items in the stack stored at data[0] through data[11]. The CAPACITY is 42. Where does the push method place the new entry in the array? A. data[0] B. data[1] C. data[11] D. data[12]

5. (4 points) What is the postfix expression for the following infix: (a + b*(c - a) - d) A. d b c a - * a + - B. a b c a d - - * + C. a b c a - * + d - D. None of the above.

6. (4 points) In the array version of the Stack class, which operations require linear time for their worst-case behavior? A. is_empty B. peek C. pop D. push when the stack is below capacity

You May Also Find These Documents Helpful

  • Good Essays

    Nt1420 Unit 6

    • 1145 Words
    • 5 Pages

    INSTRUCTIONS: 1. THERE ARE SIX (6) QUESTIONS IN THIS PAPER. 2. ANSWER FIVE (5) QUESTIONS ONLY. Question 1 Arrays are used when storing a large number of values. You are required to create an array named a and answer the following questions regarding array manipulation. a. Write a method fillRandom(int[] a, int min, int max), fill the array a with a random integer value. (Note: Math.random() returns a double in the range of 0.0 and 1.0, therefore it is cast to an integer number, between the minimum and maximum value). [6 marks] b. Write the Bubble sort method to sort array a into descending order. [10 marks] c. In the quicksort, an algorithm an element is chosen from the unsorted list. This element is called the…

    • 1145 Words
    • 5 Pages
    Good Essays
  • Good Essays

    Exercise 1: Review of array-based lists Create a project using the classes in the DocSharing area labeled “User-defined array list." Compile it, run it, and review the code that is given carefully. This code tests the ArrayList class provided in the lecture.…

    • 714 Words
    • 3 Pages
    Good Essays
  • Satisfactory Essays

    4.) Write assignment statements that perform the following operations with the variables a, b, and c:…

    • 453 Words
    • 3 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Pt1420 Unit 7 Study Guide

    • 582 Words
    • 3 Pages

    21. Write a program that prompts the user to enter two unsigned numbers 0 to FFFFh and their sum in hex on the next line.…

    • 582 Words
    • 3 Pages
    Satisfactory Essays
  • Satisfactory Essays

    The output of this program shows the original word, the reversed word, and the stripped word. Also, the program indicates whether or not the string is a palindrome.…

    • 204 Words
    • 1 Page
    Satisfactory Essays
  • Satisfactory Essays

    unit 3

    • 313 Words
    • 2 Pages

    3. Write assignment statements that perform the following operations with the variables a, b, and c.…

    • 313 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Maths Order of Operation

    • 291 Words
    • 2 Pages

    In mathematics , the order of operation also known as precedence rule is a rule used to clarify which procedures should be performed first in a given mathematical expression. When there is more than one operation involved in a mathematical problem, it must be solved by using the correct order of operations.…

    • 291 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    Proserpina was terrified as she entered Pluto’s world. Everything was so dark and cold, and she felt very lonely. She missed her mother terribly and all she kept thinking is how she disobeyed her mother and what would’ve happened if she would’ve just listened. As she rode beside Pluto in his chariot she looked around. Everything was grey. The trees had no leaves, and the sky had no color. It was a complete wasteland. The entire world looked like it had caught on fire, yet it was so cold. She noticed a small river and asked Pluto about it. Pluto told her that if she drinks from it then she would forget everything. Proserpina was not happy about this, she swore to never drink from it no matter how thirsty she was. She also noticed that Pluto…

    • 1773 Words
    • 8 Pages
    Good Essays
  • Satisfactory Essays

    On July 11, 1804, what was said to be the most prominent duel occurred. The duel between Aaron Burr and Alexander Hamilton was remarkable as it corresponded to the young, emergent nation because it illustrated the bloodshed that politicians would go through for their political reputation. Joseph J. Ellis spent an entire chapter discussing this conspicuous event for that very reason. Ellis purposely made this chapter the first chapter because he wished to provide evidence that supports his thesis and also catches the reader's attention.…

    • 312 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    Input will consist of a series of lines, each line containing one string. Each string will consist of up to 30 lower case letters, not necessarily distinct.…

    • 525 Words
    • 3 Pages
    Good Essays
  • Satisfactory Essays

    The expression 1 To 5 in the Case 1 To 5 clause specifies the range of numbers from ____.…

    • 595 Words
    • 3 Pages
    Satisfactory Essays
  • Powerful Essays

    Cen 254 Data Structure

    • 924 Words
    • 4 Pages

    keys 30, 40, 24, 58, 48, 26, 11, 13 (in this order). Draw the tree after each…

    • 924 Words
    • 4 Pages
    Powerful Essays
  • Satisfactory Essays

    Homework CH 1 Java

    • 723 Words
    • 5 Pages

    2. Languages that let you use a vocabulary of descriptive terms, such as read, write, or…

    • 723 Words
    • 5 Pages
    Satisfactory Essays
  • Good Essays

    Onetop Master

    • 439 Words
    • 2 Pages

    The method with the declaration public static int aMethod(double d) has a method type of ___________.…

    • 439 Words
    • 2 Pages
    Good Essays
  • Good Essays

    Parallel Arrays

    • 427 Words
    • 2 Pages

    Compared to arrays, linked data structures allow more flexibility in organizing the data and in allocating space for it. With arrays, we must choose a size for our array once and for all; this can be a potential waste of memory. A linked…

    • 427 Words
    • 2 Pages
    Good Essays