• Home
  • Textbooks
  • Data Structures Using C
  • Sequential Representation of Linear Data Structures

Data Structures Using C

Amol M. Jagtap, Ajit S. Mali

Chapter 2

Sequential Representation of Linear Data Structures - all with Video Answers

Educators


Chapter Questions

Problem 1

Stack data structure is based on which of the following principle
A. First in first out
B. First in last out
C. Last in last out
D. Last in first out

Check back soon!

Problem 2

Which of the following is not the type of queue data structure?
A. Priority queue
B. Circular queue
C. Single-ended queue
D. Ordinary queue

Check back soon!

Problem 3

Which of the following data structure is non-primitive linear data structure?
A. Stack
B. Graph
C. Trees
D. Binary tree

Check back soon!

Problem 4

Which of the below is true about stack implementation using a linked list?
A. In a push operation, if new nodes are inserted at the beginning of the linked list, then in pop operation, nodes must be deleted from the end.
B. In a push operation, if new nodes are inserted at the end of the linked list, then in pop operation, nodes must be deleted from the beginning.
C. Both of the above are true.
D. None of the above is true.

Check back soon!

Problem 5

Assume that a stack is to be implemented with a linked list rather than an array. What is the time complexity of the push and pop operations of the stack implemented using a linked list hoping that stack is implemented effectively?
A. $\mathbf{O}(\mathrm{n} \log \mathrm{k})$
B. $\mathrm{O}(\mathrm{nk})$
C. $O\left(\mathrm{n}^2\right)$
D. $\mathrm{O}\left(\mathrm{k}^2\right)$

Check back soon!

Problem 6

Which of the following statements is false or true?
A. The stack is a non-primitive linear data structure.
B. The queue is a primitive nonlinear data structure.
A. Statement 1 is false
B. Statement 2 is false
C. Statements 1 and 2 are false
D. Statements 1 and 2 are true

Check back soon!

Problem 7

The seven elements A, B, C, D, E, F and G are pushed onto a stack in reverse order, that is, starting from G. The stack is popped five times, and each element is inserted into a queue. Two elements are deleted from the queue and pushed back onto the stack. Now, one element is popped from the stack. The popped item is
A. A
B. B
C. F
D. D.G

Check back soon!

Problem 8

Which of the following is an application of non-primitive linear queue data structure?
A. When a resource is shared among multiple consumers?
B. When data is transferred asynchronously between two processes?
C. Load balancing
D. All of the above

Check back soon!

Problem 9

Which of the following statements is false or true?
A. The queue is useful in CPU scheduling, disk scheduling.
B. Priority queues are used in Huffman codes for data compression.
A. Statement 1 is false
B. Statement 2 is false
C. Statements 1 and 2 are false
D. Statements 1 and 2 are true

Check back soon!

Problem 10

Which of the following statements is false or true?
A. In the DFS graph, the traversing technique queue data structure is used.
B. In expression evaluation, the stack data structure is used.
A. Statement 1 is false
B. Statement 2 is false
C. Statements 1 and 2 are false
D. Statements 1 and 2 are true

Check back soon!

Problem 11

Stack cannot be used to
A. Implement recursion
B. Arithmetic expression evaluation
C. Parsing or syntax analysis
D. In CPU scheduling and disk scheduling.

Check back soon!

Problem 12

A single array A[1..MAXSIZE] is used to implement two stacks. The two stacks grow from opposite ends of the array. Variables top1 and top2 (topl<top 2) point to the location of the topmost element in each of the stacks. If the space is to be used efficiently, the condition for "stack full" is (GATE CS 2004)
A. $($ top $1=$ MAXSIZE $/ 2)$ and $($ top2 = MAXSIZE $/ 2+1)$
B. topl + top2 = MAXSIZE
C. (top1 = MAXSIZE/2) or (top2=MAXSIZE)
D. top1= top2-1

Check back soon!

Problem 13

Which one of the following is an application of stack data structure?
A. Implement recursion
B. Towers of Hanoi problems
C. Arithmetic expression evaluation
D. All of the above

Check back soon!

Problem 14

The postfix form of the expression $(\mathrm{A}+\mathrm{B})^*\left(\mathrm{C}^* \mathrm{D}-\mathrm{E}\right)^* \mathrm{~F} / \mathrm{G}$ is?
A. $\mathbf{A B}+\mathrm{CD}^* \mathbf{E}-\mathrm{FG} /{ }^{* *}$
B. $\mathrm{AB}+\mathrm{CD}{ }^* \mathrm{E}-\mathrm{F}^{* *} \mathrm{G} /$
C. $\mathrm{AB}+\mathrm{CD}^* \mathrm{E}-{ }^* \mathrm{~F}{ }^* \mathrm{G} /$
D. $\mathrm{AB}+\mathrm{CDE} *-{ }^* \mathrm{~F}{ }^* \mathrm{G} /$

Check back soon!

Problem 15

The non-primitive linear data structure required to check whether an expression contains balanced parenthesis is
A. Stack
B. Queue
C. Array
D. Tree

Check back soon!

Problem 16

If the elements "A", "B", "C" and "D" are placed in a stack and are removed one at a time, in what order will they be deleted?
A. ABCD
B. DCBA
C. DCAB
D. ABDC

Check back soon!

Problem 17

What is the minimum number of stacks of size n required to implement a queue data structure of size $n$ ?
A. One
B. Two
C. Three
D. Four

Check back soon!

Problem 18

Consider the following array implementation of stack:
```
taerine max 10
Struct STACK
|
Int arr [MAX];
Int top = -1;
)
```

If the array index starts with 0 , the maximum value of top that does not cause stack overflow is?
A. 8
B. 9
C. 10
D. 11

Check back soon!

Problem 19

Which of the following applications utilizes a stack data structure?
A. Parenthesis balancing program
B. Syntax analyzer in compiler
C. Keeping track of local variables at run time
D. All of the above

Check back soon!

Problem 20

Consider the following operation performed on a stack of size 5 .

Push (1);
Pop () :
Push (2) :
Push (3) ;
Pop () ;
Push (4);
Pop () ;
Pop () :
Push (5) ;
After the completion of all operations, the number of elements present on the stack are
A. 1
B. 2
C. 3
D. 4

Check back soon!

Problem 21

What is the name where deletion can be done in a linear list of elements from one end (front) and insertion can take place only at the other end (rear)?
A. Queue
B. Stack
C. Tree
D. Linked list

Check back soon!

Problem 22

Let the following circular queue can accommodate maximum six elements with the following data
front $=2$ rear $=4$
queue = $\qquad$ : L, M, N, $\qquad$ ,
What will happen after ADD O operation takes place?
A. front $=2$ rear $=5$ queue $=$ $\qquad$ ; L, M, N, O, $\qquad$
B. front $=3$ rear $=5$ queue $=\mathrm{L}, \mathrm{M}, \mathrm{N}, \mathrm{O}$, $\qquad$
C. front $=3$ rear $=4$ queue $=$ $\qquad$ ; L, M, N, O, $\qquad$
D. front $=2$ rear $=4$ queue $=L, M, N, O$, $\qquad$

Check back soon!

Problem 23

If the MAX_SIZE is the size of the array used in the implementation of the circular queue. How is rear manipulated while inserting an element in the queue?
A. rear $=($ rear\% $\% 1)+$ MAX_SIZE
B. rear-rear\%(MAX_SIZE+1)
C. rear=(rear+1)\%MAX_SIZE
D. rear=rear+ $(1 \%$ MAX_SIZE

Check back soon!

Problem 24

What is the name where elements can be inserted or deleted, in a non-primitive linear data structure, from both the ends but not in the middle?
A. Queue
B. Circular queue
C. Dequeue
D. Priority queue

Check back soon!

Problem 25

Consider the following pseudo-code. Assume that IntQueue is an integer queue. What does the function fun do?
```
void fun(int n)
l
IntQueve q = new IntQueve();
q. enqueve (0);
q.enqueue (1);
for (int i = 0; i < n; i++)
l
int a = q. dequeue();
int b - q.dequeue () ;
q. enqueue (b);
q.enqueue (a + b);
ptint(a);
}
l
```
A. Prints numbers from 0 to $\mathrm{n}-1$
B. Prints numbers from $\mathrm{n}-1$ to 0
C. Prints first n Fibonacci numbers
D. Prints first n Fibonacci numbers in reverse order.

Check back soon!

Problem 26

Suppose a circular queue of capacity $(\mathrm{n}-1)$ elements is implemented with an array of n elements. Assume that the insertion and deletion operations are carried out using REAR and FRONT as array index variables, respectively. Initially, REAR $=F R O N T=0$. The conditions to detect queue full and queue empty are
A. Full: $($ REAR +1$) \bmod n=$ FRONT, empty: REAR $==$ FRONT
B. Full: $($ REAR +1$) \bmod n=F R O N T$, empty: $(F R O N T+1) \bmod n==$ REAR
C. Full: REAR $=$ FRONT, empty: $($ REAR +1$) \bmod n==$ FRONT
D. Full: $($ FRONT +1$) \bmod n=$ REAR, empty: REAR $==$ FRONT
implement, this circular queue is 5 , which is n .
In the beginning when the queue is empty, FRONT and REAR point to 0 index in the array. REAR represents insertion at the REAR index. FRONT represents deletion from the FRONT index.

$$
\begin{aligned}
& \text { enqueue ("a"); REAR }=(\text { REAR }+1) \text { \% } ;(\text { ERONT }=0, \text { REAR }=1) \\
& \text { enqueue }(" \mathrm{~b} ") \text {; REAR }=(\operatorname{REAR}+1)=5 ;(\text { FRONT }=0, \text { REAR }-2) \\
& \text { enquetue ("c"); RENR }=(\text { RENR }+1) \text { s5; ( FRONT }=0, \text { REMR }=3 \text { ) } \\
& \text { enqueue }(" \mathrm{~d} \text { "); REAR }=(\text { REAR }+1) \text { 85; ( FRONT }=0, \text { REAR }=4)
\end{aligned}
$$

Now, the queue size is 4 , which is equal to the maxQueueSize. Hence, the overflow condition is reached.
Now, we can check for the conditions.
When Queue Full:
```
(REAR+1) &n - (4+1) &5 - 0
FRONT is also 0.
Hence (REAR + 1) in is equal to the FRONT.
When Queue Empty:
REAR was equal to ERONT when empty (because in the starting,
before filling the queve FRONT - REAR - 0)
Hence Option A is correct.
```

Check back soon!

Problem 27

Following is a C like pseudo-code of a function that takes a queue as an argument and uses a stack S to do the processing.
```
void IUn(Queue *Q)
I
Stack S; // Say it creates an empty stack S
// Run while Q is not empty
While (!isEmpty(Q))
l
// deQueve an item from Q and push the dequeued item
to S
push(6S, deQueue (Q));
l
// Run while stack S is not empty
while (!isEmpty(5S))
l
// Pop an item from S and enqueue the poppped item to Q
```
```
enQueue (Q, pop(5S));
1
l
```

What does the above function do in general?
A. Removes the last from $Q$
B. Keeps the Q the same as it was before the call
C. Makes Q empty
D. Reverses the $Q$

Check back soon!

Problem 28

A data structure in which elements can be inserted or deleted at/from both the ends but not in the middle is?
A. Queue
B. Circular queue
C. Dequeue
D. Priority queue

Check back soon!

Problem 29

A circular queue is implemented using an array of size 10 . The array index starts with 0 , the front is 6 , and the rear is 9 . The insertion of the next element takes place in the array index.
A. 0
B. 7
C. 9
D. 10

Check back soon!

Problem 30

Trees and graphs are which type of data structures?
A. Linear data structures
B. Nonlinear data structures
C. Primitive data structures
D. None of the above

Check back soon!

Problem 31

Consider the following pseudo-code. Assume that IntQueue is an integer queue. What does the function fun do?
```
void fun (int n)
f
IntQueve q = new IntQueue();
q.enqueue (0);
q.enqueue (1);
for (int i = 0; i<n; i++)
i
int a = q.dequeue();
int b - q.dequeue();
q. enqueue (b);
q.enqueue (a + b);
print(a);
}
l
```
A. Prints numbers from 0 to $\mathrm{n}-1$
B. Prints numbers from $\mathrm{n}-1$ to 0
C. Prints first $\mathbf{n}$ Fibonacci numbers
D. Prints first n Fibonacci numbers in reverse order.

Check back soon!