Docsity

Study Questions for Programming Methodology II | 332 351, Assignments of Electrical and Electronics Engineering

Toggle sidebar
bg1
Date: November 28, 2020
RUTGERS UNIVERSITY
The State University of New Jersey
School of Engineering
Department of Electrical and Computer Engineering
14:332:351 Programming Methodology โ€“ II Fall 2004
Stacks, Linked Lists and Queues
Theory Questions:
1. What data structure(s) would you use to represent:
a. Polynomials
b. Trees
c. Graphs
d. Matrices [Do not forget to consider sparse matrices]
If alternatives exist, discuss tradeoffs.
2. Explain how to implement two stacks in one array A[1..n] in such a way that neither stack
overflows unless the total number of elements in both stacks together is n. The Push and Pop
operations should run in O(1) time.
3. Show how to implement a queue using two stacks. Analyze the running time of the queue
operations.
4. Consider an n-node complete binary-tree. What is the (asymptotic) height h2 of this tree?
What would be the (asymptotic) height hk of an n-node complete k-ary tree? What is the
(asymptotic) ratio h2/hk? [Definition: A complete tree is a maximal height-balanced tree].
5. Write an O(n) time procedure that prints all the keys of an arbitrary rooted tree with n-nodes,
where the tree is stored using the left-child, right-sibling representation. Explain how
insertion and deletion can take place in this representation.
6. The left-child, right-sibling representation of an arbitrary rooted tree uses three pointers in
each node: left-child, right-sibling and parent. From any node, the parent and all children can
be reached and identified. Show how to achieve the same effect using only two pointers and
one Boolean value in each node.
7. Suppose we use tail[Q] to point to the last element in the queue instead of the first empty
position in the queue, so as to attempt to use all n spaces in the array instead of (n-1)
positions as proposed by the method in the text. Explain whether or not this idea will work.
Programming Questions:
1. Use an array to implement a (1) circular queue (2) circular de-queue
Page 1 of 1

Partial preview of the text

Download Study Questions for Programming Methodology II | 332 351 and more Assignments Electrical and Electronics Engineering in PDF only on Docsity!

Date: November 28, 2020

RUTGERS UNIVERSITY

The State University of New Jersey School of Engineering Department of Electrical and Computer Engineering 14:332:351 Programming Methodology โ€“ II Fall 2004

Stacks, Linked Lists and Queues

Theory Questions:

1. What data structure(s) would you use to represent: a. Polynomials b. Trees c. Graphs d. Matrices [Do not forget to consider sparse matrices] If alternatives exist, discuss tradeoffs. 2. Explain how to implement two stacks in one array A[1..n] in such a way that neither stack overflows unless the total number of elements in both stacks together is n. The Push and Pop operations should run in O(1) time. 3. Show how to implement a queue using two stacks. Analyze the running time of the queue operations. 4. Consider an n-node complete binary-tree. What is the (asymptotic) height h 2 of this tree? What would be the (asymptotic) height hk of an n-node complete k-ary tree? What is the (asymptotic) ratio h 2 /hk? [Definition: A complete tree is a maximal height-balanced tree]. 5. Write an O(n) time procedure that prints all the keys of an arbitrary rooted tree with n-nodes, where the tree is stored using the left-child, right-sibling representation. Explain how insertion and deletion can take place in this representation. 6. The left-child, right-sibling representation of an arbitrary rooted tree uses three pointers in each node: left-child, right-sibling and parent. From any node, the parent and all children can be reached and identified. Show how to achieve the same effect using only two pointers and one Boolean value in each node. 7. Suppose we use tail[Q] to point to the last element in the queue instead of the first empty position in the queue, so as to attempt to use all n spaces in the array instead of (n-1) positions as proposed by the method in the text. Explain whether or not this idea will work. Programming Questions:

  1. Use an array to implement a (1) circular queue (2) circular de-queue

Page 1 of 1