Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

help me answer the following questions please 1. Stack (LIFO) & its application

ID: 3682894 • Letter: H

Question

help me answer the following questions please

1. Stack (LIFO) & its application

1. Stack overflow & underflow

2. Implementation: partially filled array & linked list

3. Applications: reverse string, backtracking Exercises:

1) Which of the following applications may use a stack?

A. parentheses balancing program.

B. Keeping track of local variables at run time.

C. Syntax analyzer for a compiler.

D. All of the above.

2) Consider the usual algorithm for determining whether a sequence of parentheses is balanced. What is the maximum number of parentheses that will appear on the stack AT ANY ONE TIME when the algorithm analyzes: (()(())(())) ?

A. 1

B. 2

C. 3

D. 4

E. 5 or more

3) In the linked list implementation of the stack class, where does the push member function place the new entry on the linked list?

A. At the head

B. At the tail

C. After all other entries that are greater than the new entry.

D. After all other entries that are smaller than the new entry.

2. Queue (FIFO) & its application

1. Application: buffer data

2. Implementation: partially filled circular array & linked list

Exercises:

1) One difference between a queue and a stack is:

A. Queues require dynamic memory, but stacks do not.

B. Stacks require dynamic memory, but queues do not.

C. Queues use two ends of the structure; stacks use only one.

D. Stacks use two ends of the structure, queues use only one.

2) In the linked list implementation of the queue class, where does the push member function place the new entry on the linked list?

A. At the head

B. At the tail

C. After all other entries that are greater than the new entry.

D. After all other entries that are smaller than the new entry.

3) If data is a circular array of CAPACITY elements, and last is an index into that array, what is the formula for the index after last?

A. (last % 1) + CAPACITY

B. last % (1 + CAPACITY)

C. (last + 1) % CAPACITY

D. last + (1 % CAPACITY)

3. Recursion

1. Base case & recursive case

2. Infinite recursion

Exercises:

1) What is the importance of the stopping case in recursive functions?

2) Implement the following function. Do not use any local variables or loops.

void pattern(unsigned int n)

// Precondition: n > 0;

// Postcondition: The output consists of lines of integers.

The first line is the number n. The next line is the number 2n. The next line is the number 4n, and so on until y ou reach a number that is larger than 4242. This list of numbers is then repeated backward until you get back to n.

/* Example output with n = 840:

840

1680

3360

6720

6720

3360

1680

840

*/

3) Consider the following function:

void super_write_vertical(int number)

// Postcondition: The digits of the number have been written, stacked vertically. If number is negative, then a negative sign appears on top. Library facilities used: iostream.h, math.h

{

if (number < 0)

{

cout << '-' << endl; super_write_vertical(abs(number));

}

else if (number < 10)

cout << number << endl;

else

{

super_write_vertical(number/10);

cout << number % 10 << endl;

}

}

What values of number are directly handled by the stopping case?

A. number < 0

B. number < 10

C. number >= 0 && number < 10

D. number > 10

4) Consider this function declaration:

void quiz(int i)

{

if (i > 1)

{

quiz(i / 2);

quiz(i / 2);

} cout << "*";

}

How many asterisks are printed by the function call quiz(5)?

A. 3

B. 4

C. 7

D. 8

E. Some other number

Explanation / Answer

1- D

2- C

3- A

Part-2

1-C

2-B

3- A

Part -3 Recursion:

1- It is mandate else the program runs recursively. It ends in an infinite way. It is the case which decides the program when to stop

2-

3- C

4- C