You are on page 1of 3

1. A program P reads in 500 integers in the range [0..100] representing the scores of 500 students.

It then prints the frequency of each score above 50. What would be the best way for P to store
the frequencies?

An array of 100 numbers


An array of 50 numbers *
An array of 500 numbers
A Dynamically allocated array of 550 numbers.

2. Suppose you are given an implementation of a queue of integers. The operations that can be
performed on the queue are:

i. isEmpty (Q) — returns true if the queue is empty, false otherwise.


ii. delete (Q) — deletes the element at the front of the queue and returns its value.
iii. insert (Q, i) — inserts the integer i at the rear of the queue.

Write a small function that reverses the order of the elements in the queue
Answer:

Void f (queue Q) {
Int i ;
if(!isEmpty(Q)) {
i = delete(Q);
f(Q);
insert(Q, i);
}
}

3. Consider the following pseudocode that uses a stack

declare a stack of characters


while( there are more characters in the word to read )
{
read a character
push the character on the stack
}
while( the stack is not empty )
{
pop a character off the stack
write the character to the screen
}

What is output for input "geeksquiz"?

geeksquizgeeksquiz
ziuqskeeg
geeksquiz
ziuqskeegziuqskeeg

4. Which of the following sorting algorithms can be used to sort a random linked list with minimum
time complexity?
Insertion Sort
Quick Sort
Heap Sort
Merge Sort *

5. Which of the following statement(s) is TRUE?

I. A hash function takes a message of arbitrary length and generates a fixed length
code.

II. A hash function takes a message of fixed length and generates a code of variable
length.
III. A hash function may give the same hash value for distinct messages.

I only
II and III only
I and III only *
II only

OOPS Problem Statement

Design a parking lot using object-oriented principles with the following assumptions.

1) The parking lot has multiple levels. Each level has multiple rows of spots.
2) The parking lot can park motorcycles, cars, and buses.
3) The parking lot has motorcycle spots, compact spots, and large spots.
4) A motorcycle can park in any spot.
5) A car can park in either a single compact spot or a single large spot.
6) A bus can park in five large spots that are consecutive and within the same row. It cannot park in
small spots.

You might also like