# Programming & Algorithm

(1) How to design algorithms to implement the stack operations.

(2) Write a program to multiply any two matrices. (Using Basic)

and finally,
(3) Consider the algebraic expression E=(2x+y)(5a-b)^3. Draw the tree T which correspond to the expression E and find the pre-order traversal of T.

1. 👍
2. 👎
3. 👁
1. I'm not exactly sure what (1) is asking. General considerations? An exemplar? Anyway, a stack has only two operations:
push something in;
pop something out.

You will need space in which to store the items on the stack. Start with the items. What data types will you be storing? Stacks are most commonly used for integer addresses, but you need to consider what your implementation will be. The space can be preallocated in one big lump, if you specify a limitation that your stack cannot grow beyond a certain size. That makes your implementation easier than the alternative, which is to allocate new space every time a new item is pushed, and possibly deallocate it when an item is popped, or let it grow, and then deallocate it when some threshold is reached.

Now you can consider the methods themselves. Let's assume you have the easiest case, which involves a fixed-size (or elastic, with the O/S doing the allocation work for you) linear array. You must have set up:
1) an array
2) a pointer to the latest entry in that array

Push implies
a) increment pointer into the array
b) copy item to the array item of current pointer

and Pop implies
a) copy array item at current pointer position into return value
b) decrement pointer

Things to consider: what happens if the pointer is about to exceed its specified limit? what happens if a pop request would decrement the pointer below its zero value?

As for (2), I suggest you start, and ask again about any problems you have. It seems to me that the hardest part of this, like many programming issues, is the input and output - in this case, how to handle the ins and outs and organize the data for matrices of wildly different shapes, and validate that they can be multiplied at all - rather than the matrix multiplication itself, which is relatively easy.

Where to start? Work a simple case, to allow you to think about the method. How do you multiply two 2x2 matrices? Work that theough step by step. What data structure do you need? What algorithm? When you've done that, consider how to adapt it for a different shape of matrix. BASIC - well, most BASICs, I suppose, since I haven't used them all - are a bit limiting in terms of what you can DIM at runtime; in BASIC, I'd be inclined to DIM a whopping big single-dimension array for each of my matrices and manage the dimensions with a couple of pointers.

(3) is really very simple, when compared with the other two.

1. 👍
2. 👎

## Similar Questions

1. ### Programming concepts

Develop a menu-driven program that inputs two numbers and, at the user’s option, finds their sum, difference, product, or quotient. top-down modular approach and pseudocode to design a suitable program to solve it. I am having

2. ### Computer Programing & Logic Design

Submit pseudocode and a flowchart for the following programming exercise: Test Average and Grade Write a program that asks the user to enter five test scores. The program should display a letter grade for each score and the

3. ### c programming

a student designed a program to accept the age of an employee and then compute the employees retirement year and display the same in a statement on the screen required. a) write out the pseudo-code for the program above b) write

4. ### Math

Please this problem to me There is a stack of 8 cards from 1-8 suppose we select a card randomly from the stack, replace it, then randomly select another card What is the probability the first card is a even number and the second

1. ### c programing

Write a C program to calculate the value of x in the quadratic equation. 𝑎𝑥 2 + 𝑏𝑥 + 𝑐 = 0 Where 𝑥 = −𝑏±√𝑏2−4𝑎𝑐 2𝑎 Implement using the following conditions. If 𝑏 2 − 4𝑎𝑐 = 0 then

2. ### PM

You are creating a customer database for Modesto Nuts minor league baseball team. Draw a project network given the information below. Complete the forward and backward pass, compute activity slack, and identify the critical path.

3. ### Programming

Write a pseudocode program that asks the user for an integer between 1 and 12. The program is to calculate the times table for that number. So for example, if the user enters a 2, then the program has to calculate 2x1 and display

4. ### chemistry

The height of a stack of 5 pennies is 0.72 cm and the radius of the stack is 0.91 cm. The volume in mL of this stack of 5 pennies is...

1. ### Computer Science

The compare_and_swap() instruction (CAS) can be used to design lock-free data structures such as stacks, queues, and lists. The program example shown below presents a possible solution to a lock-free stack using CAS instructions,

2. ### Sequential and Selection Processing Control Struct

You are an accountant setting up a payroll system for a small firm. Each line of the table in Appendix G indicates an employee’s salary range and corresponding base tax amount and tax percentage. Given a salary amount, the tax

3. ### programming logic and design

Design a program that prompts the user for a number of miles driven and a current cost per gallon. The program computes and displays the cost of the trip as well as the cost if gas prices rise by 10 percent. The program accepts

4. ### chem

The height of a stack of 5 pennies is 0.72 cm and the radius of the stack is 0.91 cm. The volume in mL of this stack of 5 pennies is.