0% found this document useful (0 votes)
39 views4 pages

Data Structure Assignment Questions

bkb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views4 pages

Data Structure Assignment Questions

bkb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

ACHARYA INSTITUTE OF GRADUATE STUDIES

(NAAC Re-Accredited ‘A+’ and Affiliated to Bengaluru City University)


Soladevanahalli, Bengaluru-560107

Assignment Questions

1. List the different memory representation of


two-dimensional arrays
2. What do you mean by header node?
3. Define a stack. List two operations of stack.
4. List the applications of stacks.
5. Write the Algorithm for Push and Pop.
6. List the types of polish notations
7. Write the algorithm for IsEmpty() and IsFull().
8. What is Recursion?
9. Explain Garbage Collection
10. Solve the following Arithmetic Expression
2 ↑ 3 + 5 * 2 ↑ 2 – 12 / 6
11. Solve the following
Consider the following infix expression Q and convert it to Postfix expression
Q= (A + ( B * C – ( D / E ^ F ) * G ) * H
12. Write a program to generate Fibonacci series using recursion.

1. List the different memory representation of two-dimensional arrays:

 Row-Major Order: Stores rows one after another in memory.


 Column-Major Order: Stores columns one after another in memory.
 Array of Arrays (Pointer to Pointers): Each row is a separate array with its own
memory block.

2. What do you mean by header node?

A header node is a special node in linked data structures (like linked lists) that does not store
actual data but is used to simplify operations such as insertion and deletion. It usually stores
metadata like the length of the list or a pointer to the first node.

3. Define a stack. List two operations of stack.

A stack is a linear data structure that follows the LIFO (Last In, First Out) principle.
Two basic operations:

 Push: Add an element to the top of the stack.


 Pop: Remove the top element from the stack.

4. List the applications of stacks.

 Function call management (recursion)


 Expression evaluation and conversion (infix to postfix/prefix)
 Undo operations in text editors
 Backtracking algorithms (e.g., maze solving)
 Syntax parsing in compilers

5. Write the Algorithm for Push and Pop.

Push Algorithm:

arduino
CopyEdit
PUSH(stack, item)
1. if TOP == MAX - 1
2. print "Stack Overflow"
3. else
4. TOP ← TOP + 1
5. stack[TOP] ← item

Pop Algorithm:

arduino
CopyEdit
POP(stack)
1. if TOP == -1
2. print "Stack Underflow"
3. else
4. item ← stack[TOP]
5. TOP ← TOP - 1
6. return item

6. List the types of polish notations

 Infix Notation: Operator is between operands (e.g., A + B)


 Prefix Notation (Polish): Operator before operands (e.g., + A B)
 Postfix Notation (Reverse Polish): Operator after operands (e.g., A B +)

7. Write the algorithm for IsEmpty() and IsFull().


IsEmpty(stack):

kotlin
CopyEdit
if TOP == -1
return true
else
return false

IsFull(stack):

kotlin
CopyEdit
if TOP == MAX - 1
return true
else
return false

8. What is Recursion?

Recursion is a programming technique where a function calls itself directly or indirectly to


solve a problem in smaller subproblems.

Example: Calculating factorial using recursion.

9. Explain Garbage Collection

Garbage Collection is the process of automatically identifying and reclaiming memory that
is no longer in use by a program. It prevents memory leaks and optimizes resource
management, especially in languages like Java and Python.

10. Solve the following Arithmetic Expression:


Expression: 2 ↑ 3 + 5 * 2 ↑ 2 – 12 / 6
Operator Precedence: ↑ > * / > + -

Step-by-step:

 2↑3=8
 2↑2=4
 5 * 4 = 20
 12 / 6 = 2
 8 + 20 = 28
 28 – 2 = 26

Answer: 26
11. Convert the infix expression to postfix:
Q = (A + ( B * C – ( D / E ^ F ) * G ) * H)

Step-by-step:

 E ^ F → EF^
 D / EF^ → DEF^/
 DEF^/ * G → DEF^/G*
 B * C → BC*
 BC* – DEF^/G* → BCDEF^/G-
 BCDEF^/G- * H → BCDEF^/G-H*
 A + (result) → ABCDEF^/G-H*+

Postfix: ABCDEF^/G-H+*

12. Write a program to generate Fibonacci series using recursion (in C):

c
CopyEdit
#include <stdio.h>

int fibonacci(int n) {
if(n == 0)
return 0;
else if(n == 1)
return 1;
else
return fibonacci(n-1) + fibonacci(n-2);
}

int main() {
int n, i;
printf("Enter the number of terms: ");
scanf("%d", &n);

printf("Fibonacci Series: ");


for(i = 0; i < n; i++) {
printf("%d ", fibonacci(i));
}

return 0;
}

You might also like