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

  • 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
  • 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

    CS 220 – Programming w/ Data Structures: You have missed one assignment and one quiz. Your instructor has extended your assignment due date to this Sunday, April 10. Your instructor has also let you to take your Quiz # 2 during his office hours during this week. Let me know if you need additional support to study for this quiz. Your grade to date in this class is 30.2/37 81.62% B.…

    • 354 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    Comp 220

    • 1463 Words
    • 6 Pages

    Pointers also have the requirement that the pointer type must be of the same data type as the variable, or the data that it points to or holds the address of. The power of pointers also hints at the potential complexity of their use, which is why this lab is focused almost entirely on several different aspects and uses of pointers. The lab also introduces pointer arrays and pointers to pointers.…

    • 1463 Words
    • 6 Pages
    Good 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
  • 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
  • Good Essays

    The Windows operating systems use a tree form of data structure rather the linked list. Each node of the tree is known as Virtual Address Descriptors (VAD) having a range of memory addresses. It is the responsibility of the VAD to mark each and every node as reserved for thread’s stack, free or committed.…

    • 670 Words
    • 3 Pages
    Good Essays