You are on page 1of 4

Data structures and Algorithm 

Analysis Questions Group 2 


 
Q1) Write steps to test if the values in a non-empty Queue of size N is in ascending order 
or not? 
 
Answer: 
1. [Define variable ascending and set it to true] 
Ascending ← True 
2. [Loop through the Queue and check whether it’s in ascending order or not] 
For (i=0; i<N; i++) 

If Queue[i] > Queue[i+1] 
Ascending ← False 
Break from loop 

3. [Check the value of Ascending after the loop and print appropriate output] 
If Ascending = True 
Output “Queue is in Ascending order” 
Else 
Output “Queue is not is Ascending order” 
4. End 
 
 
Q2) A- Write the suf x and pre x forms equivalent to the expressions below: 
I. (B  +  D) ↑   (Z / R)  *  H   
II. (D / C) ↑1  (H  *  F ) ↑2  4  
 
Answer: 
I. B  D  +  Z R / ↑ H   *   (Post x) 
*   ↑   +  B D / Z R H (Pre x) 
II. D  C / H F   *  4 ↑1  ↑2   (Post x) 
/ D C ↑2   *  H F  4 (Pre x) 
 
 
 
 
 
 
 
 

1
B- What is meant by linked storage representation, what are the advantages and 
disadvantages of this representation?? 
 
Answer: 
Linked Storage Representation means that the order of the elements is determined by an 
explicit link field in each element rather than sequential position, which means the logical 
order is not equivalent to the physical management. The advantage is that this allows us 
to change the size of the storage(By shrinking or expanding) while the program is 
executing, while the disadvantages are that it takes more space to hold the link field and 
the access is not random(direct)
 
 
Q3) A- State the row major formula that is used to compute the location of an element in 
a two dimensional arrays. 
 
Answer: 
LOC(Ai, j )  =  LOC(A0, 0 )  +  ((i  −  b1 ) *  (U 2 − B 2   +  1)  + (j − b2 ))  * C  
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

2
B- Write a complete algorithm to: 
1. Delete an element from a circular Queue of size N 
2. Insert a new element to a stack of size M 
 
Answer: 
1. [We have a Circular Queue called CQ, of size N, element is a variable that we will 
use to store our deleted value, Front and Rear are pointers] 
I. [Check underflow] 
If Front ≤ 0 output “underflow” and return 
II. [Delete Element] 
element ← CQ[F] 
III. [Is Queue empty?] 
If Front = Rear then set Front = Rear = 0, and return 
IV. [Increment Front] 
If Front = N then  
Front ← 1 
Else  
Front ← Front + 1 
V. [Finished] return 
2. [We have a stack called Stack of size M, element is a variable that holds the 
element we want to insert, Top is a pointer that points to the top of the stack] 
I. [Check overflow] 
If Top ≥ M output overflow and exit 
II. [Increment Top] 
Top ← Top + 1 
III. [Insert new element] 
Stack[Top] ← element 
IV. [Finished] exit 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

3
Q4) Write steps to search for a given value in a singly linked linear list its head given by 
pointer variable (First), and whether it exists or not? 
 
Answer: 
1. [Define variables] 
value: which holds the value we are searching for 
p: which is a pointer that we will use to search the list 
found: which a boolean 
2. [Set their values] 
value ← the value we need to find 
p ← First 
found ← False 
3. [Loop through the list until p = Null] 
while link(p) ≠ Null 

If info(p) = value then 
found ← True 
break 
Else 
p ← link(p) 

4. [Check if value exists in the list] 
If found = True then  
Output “Value is in the list” 
Else 
Output “Value is not in the list” 
5. [End] 
 

You might also like