Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 10

Reg.

No

Dr.N.G.P Institute of Technology, Coimbatore – 48

DEPARTMENT OF COMPUTER SCINECE AND ENGINEERING


Common to Information Technology
Subject code: CS6202 – Programming & Data Structures I
Test-3 Answer Key

Semester & Branch: II & (BE CSE &B Tech IT) Max. Marks : 50 Marks
Date / Session : 11.04.2017 (FN) Max.Time : 1:30 Hour
ANSWER ALL THE QUESTIONS

PART A (9 x 2 = 18 Marks)

1 Differentiate Stack & Queue

2 What are polish & reverse polish notation?


Reverse Polish Notation – The arithmetic operator appears directly after 2 operands to which
it applies called Reverse Polish Notation.
Eg: ((A/B)+C)  AB/C+
Polish Notation – The arithmetic operator is placed before the 2 operands to which it applies
called Polish Notation.
Eg: ((A/B)+C)  +/ABC
3 Evaluate the following expression using stack: 562+*84/-
The evaluated value of the expression using stack is 38.
4 Define Circular Queue.
Circular queue is a linear data structure. It follows FIFO principle. In circular queue the last
node is connected back to the first node to make a circle. Elements are added at the rear end
and the elements are deleted at front end of the queue. Both the front and the rear pointers
points to the beginning of the array. It is also called as ―Ring buffer.
Reg.No

Dr.N.G.P Institute of Technology, Coimbatore – 48

5 List the applications of Queue.


The applications of queue are:
 When a resource is shared among multiple consumers. Examples include CPU
scheduling, Disk Scheduling.
 When data is transferred asynchronously (data not necessarily received at same rate as
sent) between two processes. Examples include IO Buffers, pipes, file IO, etc.
 For simulation of real-world situations.
 Call center phone systems will use a queue to hold people in line until a service
representative is free.
6 How sorting can be classified?
The sorting algorithm is classified by:
 Computational Complexity
 Memory Utilization
 Stability
 No of comparisons
 Methods – Insertion, exchange, selection, merging etc.,
7 What is meant by rehashing?
Construction of a table which is twice as big and scans down the original hash table, computing
the new hash value for each element and inserting it into new table is called rehashing.
8 Distinguish between Linear Search & Binary Search.

9 What is meant by Linear Probing?


Linear probing is a scheme in computer programming for resolving hash collisions of values of
hash functions by sequentially searching the hash table for a free location.
Reg.No

Dr.N.G.P Institute of Technology, Coimbatore – 48

Part - B (2 x 16 marks = 32 Marks)

10 a) How the following applications are carried out using Stack?


a. Balancing Symbols (8)
 A symbol is balanced only if every right brace,bracket and
parenthesis in a program must correspond to its left counterpart.
 For example, the sequence [()] is correct. But the sequence [(]) is
wrong one.
 Writing separate program for checking of balancing symbols is not
a good practise.
 For make it simple, we should check the symbols alone ignoring
other characters using a stack.
Algorithm for Balancing Symbols Using Stack:
Step 1: Create an empty stack. For routine create stack please click
EmptyStack.
Step 2: Read the characters sequentially until the program ends.
Step 3: If the character read is an opening symbol, then push it into the
stack. For push routine click Pushoperation.
Step 4: If the character is a closing symbol, check emptiness of the stack.
If the stack is empty, then display error message: “Stack is Empty”.
If the stack is not empty, then pop the element from the stack. For pop
routine click PopOperation
Step 5: If the symbol popped is not an opening symbol, then report an
error message.
Step 6: Repeat the steps 3,4 and 5 until the program ends.
Step 7: As the program ends, if the stack is empty then the symbols are
balanced. if the stack is not empty, then there is an error.i.e., some
symbol(s) is not balanced.
Example:
Consider the expressions: 1. (a*b) +c 2. (a*b+[c
Example 1: (a * b) + c
step 1: Read the symbol ‘(‘ and push it in the stack.
step 2: Read next symbol ‘)’ . It is a closing symbol. Hence check the stack
for emptiness.
The stack already has an opening symbol “‘(‘. So pop the elements both
opening and closing symbols ‘(‘ and ‘)’ from the stack.
step 3: Read the next opening or closing symbol. there is no such symbols
till the end of the expression.
Step 4: Now check the emptiness of the stack. The stack is empty. So the
expression has balanced symbols.
Example 2: (a*b)+[c
Step 1: Read the first opening symbol ‘(‘ and push it in the stack.
Step 2: Read next symbol ‘)’ . It is a closing symbol. Hence check the stack
for emptiness.
The stack already has an opening symbol “‘(‘. So pop the elements both
opening and closing symbols ‘(‘ and ‘)’ from the stack.
Reg.No

Dr.N.G.P Institute of Technology, Coimbatore – 48

Step 3: Read the first opening symbol ‘[‘ and push it in the stack.
Step 4: Read the next opening or closing symbol. there is no such symbols
till the end of the expression.
Step 5: Now check the emptyness of the stack. The stack has an opening
symbol'[‘. So the expression does not have balanced symbols.
Thus we have seen two different examples explaining how a stack is used
to check for balancing symbols.

b. Tower of Hanoi (8)


Reg.No

Dr.N.G.P Institute of Technology, Coimbatore – 48

or
10 b) Describe the algorithm to insert & delete elements from circular queue
and normal queue using arrays (8+8)
Reg.No

Dr.N.G.P Institute of Technology, Coimbatore – 48


Reg.No

Dr.N.G.P Institute of Technology, Coimbatore – 48

11 a) Write an algorithm to sort ‘n’ integers using:


a. Selection Sort (8)

b. Insertion Sort (8)


Reg.No

Dr.N.G.P Institute of Technology, Coimbatore – 48

or
11 b) Insert the following items into empty hash table using Linear Probing,
Quadrating Probing & Double Hashing: 89, 18, 49, 58, 69.
Linear Probing:
Reg.No

Dr.N.G.P Institute of Technology, Coimbatore – 48

Quadratic Probing:
Reg.No

Dr.N.G.P Institute of Technology, Coimbatore – 48

Double Hashing:

Prepared by Approved by
Mr.Mani Deepak Choudhry, AP/IT HoD-CSE

You might also like