Programming & Algorithm

posted by .

(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.

  • Programming & Algorithm -

    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.

Respond to this Question

First Name
School Subject
Your Answer

Similar Questions

  1. Max 2

    what is the effect of the delete operations on stack and queue. design algorithms
  2. Programming

    (i) What is binary tree (ii) Write a program to multiply any two matrices. (use any program of choice)
  3. Programming & Algorithms

    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.
  4. Programing

    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.
  5. Computers

    Problem-Solving 1. Develop an algorithm or write pseudocode to determine if a citizen is eligible to vote. The criteria for eligibility are that the citizen must be 18 or older and must not be a convicted felon. The algorithm must …
  6. It/210 Axia College

    Design complex program algorithms using the three basic control structures.Currency Conversion Design Appendix h
  7. Visual Basic (Computer Programming)

    ALGORITHM EXERCISES 1. Wilma Peterson is paid by the hour. She would like a program that both calculates and displays her weekly gross pay. For this exercise, you do not need to worry about overtime pay, as Wilma never works more than …
  8. visual basic programming

    Write a Visual Basic program that will calculate the assessment marks of a student taking the Computer Programming subject in College. The program must be able to determine the total result and finally display the grade of that student. …
  9. 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 the …
  10. programming

    Step 1: Design a flowchart or write pseudocode for a program that allows a user to enter 12 numbers, then displays all of the numbers (in the order they were entered) as well as the largest number and the smallest number. Step 2: Implement …

More Similar Questions