You are on page 1of 9

Subject : Data Structures & Algorithm

I. MULTIPLE CHOICE. Choose the letter of the correct answer by writing the letter on the blank
provided before each number.
___D__ 1. Types of data structures are …

a. Primitive and non-primitive.


b. Linear and Non-linear.
c. Static and dynamic.
d. All above.

___B__ 2. In this type of data structures, data structures, data values of different types are grouped,
as in structures and classes. Refer to …

a. Homogenous
b. Non-homogenous

__B___ 3. A container which can hold a fix number of items and these items should be of the same
type. Most of the data structures make use of arrays to implement their algorithms.

a. Element
b. Array
c. Index

___D__ 4. Which one of the below mentioned is linear data structure –

a. Queue
b. Stack
c. Arrays
d. All of the above.

___C_ 5. An algorithm is

a. A piece of code to be executed.


b. A loosely written code to make final code.
c. A step by step procedure to solve problem.
d. All of the above.

__D___ 6. Operations on a data structure may be …

a. Creation
b. Sorting
c. Selection
d. All above.

__A___7. The operation of processing each element in the list is known as

a. Traversal
b. Merging
c. Inserting
d. Sorting

__D___ 8. The difference between linear array and a record is


a. An array is suitable for homogenous data but the data items in a record may have
different data type
b. In a record, there may not be a natural ordering in opposed to linear array
c. A record form a hierarchical structure but a linear array does not
d. All of the above.

__A___ 9. Which of the following data structure can’t store the non-homogenous data elements?
a. Arrays
b. Records
c. Pointers
d. None of the above.

__A___ 10. Type data abstraction which allows conceptual representation of data in database
management system is considered as
a. Logical design model
b. Data Model
c. Interface Model
d. User friendly model

___C__ 11. For a binary search algorithm to work, it is necessary that array (list) must be

a. Unsorted
b. In a heap
c. Popped out of stack

__B___ 12. Which of the following searching techniques do not require the data to be in sorted form

a. Interpolation Search

b. Linear Search
c. Binary Search
d. All of the above

__B___ 13. What data structure is used for depth first traversal of a graph?
a. Queue
b. Stack
c. List
d. None of the above.

___B__ 14. If the array is already sorted, which of these algorithms will exhibit the best
performance? a. Merge sort
b. Insertion Sort
c. Quick Sort
d. Heap Sort

___B__ 15. What are the basic components of a linked list?

a. Head and tail are the only important components


b. Data members for the information to be sorted and a link to the next item
c. Generic class because without this linked list is not possible

___B__ 16.In addition to the information and link components, the linked list must also contain what
other components?

a. Sorting information about the list


b. Head and tail pointers to the first and last nodes
c. The current node that was last accessed

____B_ 17.Given the fixed size of an array is not important, which class is more efficient at storing
and retrieving information?
a. A linked list because of the nodes
b. An array because of the reduced code and efficient storage allocation
c. Neither ir more efficient over the other

_B____ 18.What is the proper code for accessing the information of the second item in a linked list?

a. Head.info

b. Head.link.info
c. Head.linl.link.info

___A__ 19. Which of this not about linked list?

a. Linear collection of data elements


b. It can be used to implement several other common abstract data types example stack,
queue, tree
c. It uses more memory than arrays because of the storage used by their pointers.
d. Each record of a linked list is often called ‘element’ or ‘node’

___B__ 20. What are the basic components of a linked list?


a. Head and tail are the only important components
b. Data members for the information to be stored and a link to the next item
c. Generic class because without this linked list is not possible

___A__ 21. What is a node used for in a linked list?


a. To store the information and the link to the next item
b. To check for the end of the list
c. Not used in a linked list

___C__ 22. A linked list is different from an array, because why?


a. A linked list can handle more types of information than an array
b. An array cannot be sorted but a linked list can be
c. An array is fixed in size but a linked list is dynamically sizable

___B__ 23. In addition to the information and link components, the linked list must also contain
what other components?
a. Sorting information about the list
b. Head and tail pointers to the first and last nodes
c. The current node that was last accessed

__B___ 24. Given the fixed size of an array is not important, which class is more efficient at storing
and retrieving information?

a. A linked list because of the nodes


b. An array because of the reduces code and efficient storage allocation
c. Neither is more efficient over the other

__B___ 25. A stack is a data structure that implements movement of data in which format?

a. First in First out

b. Last in First out


c. Random access

__A___ 26. What are the basic operations performed on a stack?

a. Push, pop, and peek


b. InsertAt, removeAt, peekAt
c. None of the above.

__C___ 27. The initializeStack ( ) operation can only be performed when?


a. Before the stack is used, and never after
b. Before the stack is used, and anytime the stack is empty
c. Any time

____B_ 28. A data structure that changes in size as a program needs it by allocating and
deallocating memory is about …What approaches are generally used for implementing a stack data
structure?

a. Stacks can only be implemented with generic class.


b. Stacks are implemented using either an array or a linked list
c. Stacks can only be implemented using the operating system resources for a stack.

__A___ 29. How data in a queue accessed?

a. First in First out


b. First in Last out
c. Last in First out
d. None of these

__A___ 30. Which one of the following is an application of Queue Data Structure?

a. When a resource is shared among multiple consumers.


b. When data is transferred (data not necessarily received at same rate as sent) between
two process
c. Load Balancing
d. All of the above.
II. APPLICATION. GIVING THE OUTPUTS OF THE FOLLOWING PROGRAMS. Write the
correct output inside box provided in each item. Avoid erasures.

Program No. 1 (5pts) OUTPUT:

#include<stdio.h> main() The original array elements are:


{ LA[0] = 1
int LA[]={1,3,5,7,8}; int item =10, k =3, n
=5; int i =0, j = n; LA[1] = 3
printf("The original array elements are LA[2] = 5
:\n"); LA[3] = 7
for(i =0; i<n; i++){
printf("LA[%d] = %d \n", i, LA[i]); LA[4] = 8
} }

Program No. 2 (10pts)


#include<stdio.h>

main(){
int LA[]={1,3,5,7,8}; int
item =10, k =3, n =5;
int i =0, j = n;

printf("The original array elements are :\n");


for(i =0; i<n; i++){
printf("LA[%d] = %d \n", i, LA[i]);
} n = n
+1;

while( j >= k){


LA[j+1]= LA[j]; j = j -1; } LA[k]=
item; printf("The array elements after insertion
:\n");

for(i =0; i<n; i++){


printf("LA[%d] = %d \n", i, LA[i]);
}
}

OUTPUT:
The original array elements are :
LA[0] = 1
LA[1] = 3
LA[2] = 5
LA[3] = 7
LA[4] = 8
The array elements after insertion :
LA[0] = 1
LA[1] = 3
LA[2] = 5
LA[3] = 10
LA[4] = 7
LA[5] = 8

Program No. 3 (10pts)


#include<stdio.h>

void main(){ int LA[]={1,3,5,7,8}; int k =3, n


=5; int i, j; printf("The original array
elements are :\n");

for(i =0; i<n; i++){


printf("LA[%d] = %d \n", i, LA[i]);
} j = k;

while( j < n){


LA[j-1]= LA[j]; j = j +1; } n = n -
1; printf("The array elements after deletion :\
n");

for(i =0; i<n; i++){


printf("LA[%d] = %d \n", i, LA[i]);
}
}

OUTPUT: The original array elements are :


LA[0] = 1
LA[1] = 3
LA[2] = 5
LA[3] = 7
LA[4] = 8
The array elements after deletion :
LA[0] = 1
LA[1] = 3
LA[2] = 7
LA[3] = 8

III. IDENTIFICATION. IDENTIFY WHAT OPERATION IS PERFORMED IN THE FOLLOWING SET


OF ALGORITHMS OF THE DIFFERENT DATA STRUCTURES SUCH AS IN AN ARRAY,
LINKED LIST, STACKS & QUEUES. Write the letter of the correct answer on the blank
provided before each number. Each number is equivalent to 3pts.

A. UPDATE operation (ARRAY)


B. ENQUEUE operation (QUEUE)
C. INSERT operation (LINKED LIST)
D. PUSH operation (STACK)
E. DELETE operation (ARRAY)
F. INSERT at the END of an operation (LINKED LIST)
G. POP operation (STACK)
H. DEQUEUE operation (QUEUE)
I. SEARCH operation (ARRAY)
J. DELETE operation (LINKED LIST)

_B____ 1.
procedure EnQ(data)

if queue is full
return overflow
endif

rear ← rear +1
queue[rear]← data return
true

end procedure
__D___ 2.
begin procedure PuS: stack, data
if stack is full
returnnull
endif

top ← top +1
stack[top]← data

end procedure
___A_ 3.

#include<stdio.h>

void main(){ int LA[]={1,3,5,7,8}; int k =3, n


=5, item =10; int i, j; printf("The original
array elements are :\n");

for(i =0; i<n; i++){


printf("LA[%d] = %d \n", i, LA[i]);

LA[k-1]= item;

printf("The array elements after updation :\n");

for(i =0; i<n; i++){


printf("LA[%d] = %d \n", i, LA[i]);
}
}
_E____ 4.
#include<stdio.h>

void main(){ int LA[]={1,3,5,7,8}; int k =3, n


=5; int i, j; printf("The original array
elements are :\n");

for(i =0; i<n; i++){


printf("LA[%d] = %d \n", i, LA[i]);
} j = k;

while( j < n){


LA[j-1]= LA[j];
j = j +1; } n = n
-1; printf("The
array elements after
deletion :\n");

for(i =0; i<n; i++){


printf("LA[%d] = %d \n", i, LA[i]);
}
}

___H__ 5.

procedure dq

if queue is empty
return underflow
endif

data = queue[front]
front ← front +1
returntrue end
procedure

__C___ 6.

void insertFirst(int key,int data){


struct node *link =(struct node*) malloc(sizeof(struct node));
link->key = key; link->data = data;

if(isEmpty())
{ last= link;
}else{
head->prev = link;
} link->next= head;

head =
link; }
___F__ 7.

void insertLast(int key,int data){

struct node *link =(struct node*) malloc(sizeof(struct node));


link->key = key; link->data = data;

if(isEmpty())
{ last= link;
}else{ last-
>next= link; }
last= link;

_J____ 8.
struct node* deleteFirst()

{ struct node *tempLink = head;

if(head->next== NULL)
{ last= NULL;
}else{
head->next->prev = NULL;
} head = head->next;

return
tempLink; }

__I___ 9.

#include<stdio.h>

void main(){ int LA[]={1,3,5,7,8}; int item =5, n


=5; int i =0, j =0; printf("The original
array elements are :\n");

for(i =0; i<n; i++){


printf("LA[%d] = %d \n", i,
LA[i]); }

while( j < n)
{ if( LA[j]== item
){ break; }

j = j
+1; }

printf("Found element %d at position %d\n", item,


j+1); }
__G___ 10.

int pop(int data){

if(!isempty())
{ data =
stack[top]; top =
top -1; return data;
}else{
printf("Could not retrieve data, Stack is empty.\n");
}
}

You might also like