0% found this document useful (0 votes)
166 views

BCA-2Sem Data Structure

The document provides 20 multiple choice questions about data structures and algorithms. The questions cover topics like stacks, queues, linked lists, trees, arrays, and time complexity. Sample questions ask about operations on stacks and queues, implementing different data structures using arrays, time complexity of operations like searching a linked list, properties of binary trees, and analyzing algorithms like quicksort.

Uploaded by

SHAMBHU JHA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
166 views

BCA-2Sem Data Structure

The document provides 20 multiple choice questions about data structures and algorithms. The questions cover topics like stacks, queues, linked lists, trees, arrays, and time complexity. Sample questions ask about operations on stacks and queues, implementing different data structures using arrays, time complexity of operations like searching a linked list, properties of binary trees, and analyzing algorithms like quicksort.

Uploaded by

SHAMBHU JHA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 30

Knowledge & Expertise of a discipline

1. Process of inserting an element in stack is called ____________


a) Create
b) Push
c) Evaluation
d) Pop
Answer b

2. Process of removing an element from stack is called __________


a) Create
b) Push
c) Evaluation
d) Pop
Answer d

3. In a stack, if a user tries to remove an element from an empty stack it is called


_________
a) Underflow
b) Empty collection
c) Overflow
d) Garbage Collection
Answer a

4. Pushing an element into stack already having five elements and stack size of 5, then
stack becomes ___________
a) Overflow
b) Crash
c) Underflow
d) User flow

Answer a

5. Entries in a stack are “ordered”. What is the meaning of this statement?


a) A collection of stacks is sortable
b) Stack entries may be compared with the ‘<‘ operation
c) The entries are stored in a linked list
d) There is a Sequential entry that is one by one

Ans d

6. A linear list of elements in which deletion can be done from one end (front) and
insertion can take place only at the other end (rear) is known as _____________
a) Queue
b) Stack
c) Tree
d) Linked list
Answer a
7. The data structure required for Breadth First Traversal on a graph is?
a) Stack
b) Array
c) Queue
d) Tree

View c

8. A queue follows __________


a) FIFO (First In First Out) principle
b) LIFO (Last In First Out) principle
c) Ordered array
d) Linear tree
Answer a
9. Circular Queue is also known as ________
a) Ring Buffer
b) Square Buffer
c) Rectangle Buffer
d) Curve Buffer
Answer a

10. If the elements “A”, “B”, “C” and “D” are placed in a queue and are deleted one at a
time, in what order will they be removed?
a) ABCD
b) DCBA
c) DCAB
d) ABDC

Ans a

11. A linear collection of data elements where the linear node is given by means of
pointer is called?
a) Linked list
b) Node list
c) Primitive list
d) Unordered list
Answer a

12. Consider an implementation of unsorted singly linked list. Suppose it has its
representation with a head pointer only. Given the representation, which of the following
operation can be implemented in O(1) time?

i) Insertion at the front of the linked list


ii) Insertion at the end of the linked list
iii) Deletion of the front node of the linked list
iv) Deletion of the last node of the linked list

a) I and II
b) I and III
c) I, II and III
d) I, II and IV
Answer b

13. In linked list each node contains a minimum of two fields. One field is data field to
store the data second field is?
a) Pointer to character
b) Pointer to integer
c) Pointer to node
d) Node
Ans c

14. What would be the asymptotic time complexity to add a node at the end of singly
linked list, if the pointer is initially pointing to the head of the list?
a) O(1)
b) O(n)
c) θ(n)
d) θ(1)
Answer c

15. What would be the asymptotic time complexity to insert an element at the front of the
linked list (head is known)?
a) O(1)
b) O(n)
c) O(n2)
d) O(n3)
Answer c

16. How many children does a binary tree have?


a) 2
b) any number of children
c) 0 or 1 or 2
d) 0 or 1
Answer a

17. What is/are the disadvantages of implementing tree using normal arrays?
a) difficulty in knowing children nodes of a node
b) difficult in finding the parent of a node
c) have to know the maximum number of nodes possible before creation of trees
d) difficult to implement
Answer d

18. What must be the ideal size of array if the height of tree is ‘l’?
a) 2l-1
b) l-1
c) l
d) 2l
Answer c

19. What are the children for node ‘w’ of a complete-binary tree in an array
representation?
a) 2w and 2w+1
b) 2+w and 2-w
c) w+1/2 and w/2
d) w-1/2 and w+1/2
Answer d

20. What is the parent for a node ‘w’ of a complete binary tree in an array representation
when w is not 0?
a) floor(w-1/2)
b) ceil(w-1/2)
c) w-1/2
d) w/2
Answer c

Research Enquiry

1.A program P reads in 500 integers in the range [0..100] exepresenting 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?

A. An array of 50 numbers
B. An array of 100 numbers
C. An array of 500 numbers
D. A dynamically allocated array of 550 numbers
Ans D.

2. Consider an array A[20, 10], assume 4 words per memory cell and the base address of
array A is 100. What is the address of A[11, 5] ? Assume row major storage.

A. 560
B. 565
C. 570
D. 575

Ans A
3. Which of the following is an illegal array definition?

A. Type COLONGE : (LIME, PINE, MUSK, MENTHOL); var a : array [COLONGE] of


REAL;
B. var a : array [REAL] of REAL;
C. var a : array [‘A’…’Z’] of REAL;
D. var a : array [BOOLEAN] of REAL;
Ans B

4. What is the output of the below code?


1. #include <stdio.h>  
2. int main()  
3. {  
4.    int arr[5]={10,20,30,40,50};  
5.    printf("%d", arr[5]);  
6.   }
7.     return 0;  
8. }  

a. Garbage value
b. 10
c. 50
d. None of the above

Ans a

5. What is the maximun number of dimensions an array in C may have?

A. Two
B. eight
C. sixteen
D. Theoratically no limit. The only practical limits are memory size and compilers

Ans d

6.What is the outcome of the prefix expression +, -, *, 3, 2, /, 8, 4, 1?

a. 12
b. 11
c. 5
d. 4

Ans c

7. If the elements '1', '2', '3' and '4' are inserted in a queue, what would be order for the
removal?

a. 1234
b. 4321
c. 3241
d. None of the above

Ans a

8. Which one of the following is the overflow condition if linear queue is implemented using
an array with a size MAX_SIZE?

a. rear = front
b. rear = front+1
c. rear=MAX_SIZE -1
d. rear = MAX_SIZE

Ans b

9. The time complexity of enqueue operation in Queue is __

a. O(1)
b. O(n)
c. O(logn)
d. O(nlogn)

Ans a

10. Which one of the following is the correct way to increment the rear end in a circular
queue?

a. rear =rear+1
b. (rear+1) % max
c. (rear % max) + 1
d. None of the above

Ans b

11. public void function(Node node)


e. {
f. if(size == 0)
g. head = node;
h. else
i. {
j. Node temp,cur;
k. for(cur = head; (temp = cur.getNext())!=null; cur = temp);
l. cur.setNext(node);
m. }
n. size++;
o. }
a) Inserting a node at the beginning of the list
b) Deleting a node at the beginning of the list
c) Inserting a node at the end of the list
d) Deleting a node at the end of the list
Ans c
12. Consider an implementation of unsorted singly linked list. Suppose it has its
representation with a head pointer only. Given the representation, which of the
following operation can be implemented in O(1) time?

i) Insertion at the front of the linked list


ii) Insertion at the end of the linked list
iii) Deletion of the front node of the linked list
iv) Deletion of the last node of the linked list

a) I and II
b) I and III
c) I,II and III
d) I,II and IV
Ans b

13. Consider the following definition in c programming language

struct node
{
int data;
struct node * next;
}
typedef struct node NODE;
NODE *ptr;

Which of the following c code is used to create new node?

a) ptr=(NODE*)malloc(sizeof(NODE));
b) ptr=(NODE*)malloc(NODE);
c) ptr=(NODE*)malloc(sizeof(NODE*));
d) ptr=(NODE)malloc(sizeof(NODE));
Ans a

14. In worst case, the number of comparison need to search a singly linked list of length n for
a given element is

a) log n
b) n/2
c) log2n-1
d) n

Ans d

15. . In-order traversing a tree resulted E A C K F H D B G; the pre-order traversal would


return.

A. FAEKCDBHG

B. FAEKCDHGB

C. EAFKHDCBG

D. FEAKDCHBG
Ans b

16. In linked representation of Binary trees LEFT[k] contains the ........ of at the node N,
where k is the location.

A. Data

B. Location and left child

C. Right child address

D. Null value
Ans a

17..What is a complete binary tree?


a) Each node has exactly zero or two children
b) A binary tree, which is completely filled, with the possible exception of the
bottom level, which is filled from right to left
c) A binary tree, which is completely filled, with the possible exception of the
bottom level, which is filled from left to right
d) A tree In which all nodes have degree 2

Ans c

18.What is the average case time complexity for finding the height of the binary
tree?
a) h = O(loglogn)
b) h = O(nlogn)

c) h = O(n)
d) h = O(log n)
Ans d

19.In a full binary tree if number of internal nodes is I, then number of nodes N
are?
a) N = 2*I
b) N = I + 1
c) N = I – 1
d) N = 2*I + 1

Ans d

20. Suppose we have a O(n) time algorithm that finds median of an unsorted array. Now
consider a QuickSort implementation where we first find median using the above algorithm,
then use median as pivot. What will be the worst case time complexity of this modified
QuickSort.

A. O(n^2 Logn)
B. O(n^2)
C. O(n Logn Logn)
D. O(nLogn)
Ans d
Information & Digital LiteIracy

1. In general, the index of the first element in an array is __________


a) 0
b) -1
c) 2
d) 1
Ans a
2. Elements in an array are accessed _____________
a) randomly
b) sequentially
c) exponentially
d) logarithmically

Ans b

3. Which of the following highly uses the concept of an array?

a. Binary Search tree

b. Caching

c. Spatial locality

d. Scheduling of Processes

Ans b

4. Which of the following operations is not O(1) for an array of sorted data. You may assume
that array elements are distinct.

a. Find the ith largest element


b. Delete an element
c. Find the ith smallest element
d. All of the above
Ans b

5.The memory address of the first element of an array is called


a. floor address
b. foundation address
c. first address
d. base address

Ans d

6. Two-dimensional arrays are also called


a. tables arrays
b. matrix arrays
c. both of above
d. none of the above

Ans c

7.Which of the following is the infix expression?

a. A+B*C
b. +A*BC
c. ABC+*
d. None of the above

Ans a

8. A list of elements in which enqueue operation takes place from one end, and dequeue
operation takes place from one end is__

a. Binary tree
b. Stack
c. Queue
d. Linked list

Ans c

9. Which of the following principle does Queue use?

a. LIFO principle
b. FIFO principle
c. Linear tree
d. Ordered array

Ans b

10. Which one of the following is not the type of the Queue?

a. Linear Queue
b. Circular Queue
c. Double ended Queue
d. Single ended Queue
Ans d

11. Which of the following that determines the need for the Circular Queue?

a. Avoid wastage of memory


b. Access the Queue using priority
c. Follows the FIFO principle
d. None of the above

Ans a

Global Citizen

1.Which of the following operations is performed more efficiently by doubly linked


list than by singly linked list?

a) Deleting a node whose location in given


b) Searching of an unsorted list for a given item
c) Inverting a node after the node with given location
d) Traversing a list to process each node

Ans a

2. In linked list each node contain minimum of two fields. One field is data field to
store the data second field is?

a) Pointer to character
b) Pointer to integer
c) Pointer to node
d) Node

Ans c

3.What would be the asymptotic time complexity to add a node at the end of singly linked
list, if the pointer is initially pointing to the head of the list?

a) O(1)
b) O(n)
c) θ (n)
d) θ (1)

Ans c

4.In doubly linked lists, traversal can be performed?

a) Only in forward direction


b) Only in reverse direction
c) In both directions
d) None

Ans c

5.In circular linked list, insertion of node requires modification of?

a) One pointer
b) Two pointer
c) Three pointer
d) None
Ans b

6.The post order traversal of a binary tree is DEBFCA. Find out the pre order Traversal.

A. ABFCDE

B. ADBFEC

C. ABDECF

D. ABDCEF
Ans c

7. In a graph if e=[u,v], then u and v are called

A. endpoints of e

B. adjacent nodes

C. neighbours

D. all of the above


Ans d

8. A connected graph T without any cycles is called .

A. a tree graph

B. free tree

C. a tree

D. All of above
Ans d

9. If every node u in G adjacent to every other node v in G, A graph is said to be

A. isolated

B. complete

C. finite

D. strongly connected
Ans b

10. Three standards ways of traversing a binary tree T with root R .......

A. Prefix, infix, postfix

B. Pre-process, in-process, post-process

C. Pre-traversal, in-traversal, post-traversal

D. Pre-order, in-order, post-order


Ans d
Problem Solving

1.Which of these best describes an array?


a) A data structure that shows a hierarchical behaviour
b) Container of objects of similar types- Answer
c) Arrays are immutable once initialised
d) Array is not a data structure

2.How do you initialize an array in C?


a) int arr[3] = (1,2,3);
b) int arr(3) = {1,2,3};
c) int arr[3] = {1,2,3}; - Answer
d) int arr(3) = (1,2,3);
3.When does the ArrayIndexOutOfBoundsException occur?
a) Compile-time
b) Run-time- Answer
c) Not an error
d) Not an exception at all
4.What are the advantages of arrays?
a) Objects of mixed data types can be stored
b) Elements in an array cannot be sorted
c) Index of first element of an array is 1
d) Easier to store elements of same data type- Answer

5.In a stack, if a user tries to remove an element from empty stack it is called _________
a) Underflow - Answer
b) Empty collection
c) Overflow
d) Garbage Collection

6.Entries in a stack are “ordered”. What is the meaning of this statement?


a) A collection of stacks is sortable
b) Stack entries may be compared with the ‘<‘ operation
c) The entries are stored in a linked list
d) There is a Sequential entry that is one by one- Answer

7. A linear list of elements in which deletion can be done from one end (front) and
insertion can take place only at the other end (rear) is known as a ?
a) Queue - Answer

b) Stack
c) Tree
d) Linked list

8.
A normal queue, if implemented using an array of size MAX_SIZE, gets full when
a) Rear = MAX_SIZE – 1 Answer
b) Front = (rear + 1)mod MAX_SIZE
c) Front = rear + 1
d) Rear = front

9. Which of these is not an application of linked list?


a) To implement file systems
b) For separate chaining in hash-tables
c) To implement non-binary trees
d) Random Access of elements Answer

10. In linked list each node contain minimum of two fields. One field is data field to store
the data second field is?
a) Pointer to character
b) Pointer to integer
c) Pointer to node Answer

d) Node

11. Which of the following is false about a doubly linked list?


a) We can navigate in both the directions
b) It requires more space than a singly linked list
c) The insertion and deletion of a node take a bit longer
d) Implementing a doubly linked list is easier than singly linked list Answer

12. The type of expression in which operator succeeds its operands is?
a) Infix Expression
b) Prefix Expression
c) Postfix Expression Answer

d) Both Prefix and Postfix Expressions


13. The following given tree is an example for?

a) Binary tree Answer


b) Binary search tree
c) Fibonacci tree
d) AVL tree

14. What is a complete binary tree?


a) Each node has exactly zero or two children
b) A binary tree, which is completely filled, with the possible exception of the bottom
level, which is filled from right to left
c) A binary tree, which is completely filled, with the possible exception of the bottom
level, which is filled from left to right Answer
d) A tree In which all nodes have degree 2
15. Which of the following statements for a simple graph is correct?
a) Every path is a trail Answer
b) Every trail is a path
c) Every trail is a path as well as every path is a trail
d) Path and trail have no relation
16.  In the given graph identify the cut vertices.

a) B and E
b) C and D
c) A and E
d) C and B Answer

17. For the given graph(G), which of the following statements is true?

a) -G is a complete graph
b) G is not a connected graph
c) The vertex connectivity of the graph is 2
d) The edge connectivity of the graph is 1 Answer

18. The worst-case occur in linear search algorithm when …….


A. Item is somewhere in the middle of the array
B. Item is not in the array at all
C. Item is the last element in the array
D. Item is the last element in the array or item is not there at all Answer

19. 2) If the number of records to be sorted is small, then …… sorting can be efficient.
A. Merge 
B. Heap
C. Selection Answer
D. Bubble

20 The complexity of bubble sort algorithm is …..


A. O(n)
B. O(logn)
C. O(n2) Answer

D. O(n logn)

Ethical, Social and Professional Responsibility

4. Which of these best describes an array?


a) A data structure that shows a hierarchical behavior
b) Container of objects of similar types
c) Arrays are immutable once initialised
d) Array is not a data structure

Ans b

5. 2. How do you initialize an array in C?


a) int arr[3] = (1,2,3);
b) int arr(3) = {1,2,3};
c) int arr[3] = {1,2,3};
d) int arr(3) = (1,2,3);

Ans c
6. When does the ArrayIndexOutOfBoundsException occur?
a) Compile-time
b) Run-time
c) Not an error
d) Not an exception at all
Ans b
7. What are the advantages of arrays?
a) Objects of mixed data types can be stored
b) Elements in an array cannot be sorted
c) Index of first element of an array is 1
d) Easier to store elements of same data type

Ans d
8.  Assuming int is of 4bytes, what is the size of int arr[15];?
a) 15
b) 19
c) 11
d) 60
Ans d

9. In general, the index of the first element in an array is __________


a) 0
b) -1
c) 2
d) 1

Ans a
10. Elements in an array are accessed _____________
a) randomly
b) sequentially
c) exponentially
d) logarithmically

Ans b

11. Which of the following highly uses the concept of an array?

a. Binary Search tree

b. Caching

c. Spatial locality

d. Scheduling of Processes
Ans b

9. Which of the following operations is not O(1) for an array of sorted data. You may assume
that array elements are distinct.

a. Find the ith largest element


b. Delete an element
c. Find the ith smallest element
d. All of the above
Ans b

10.The memory address of the first element of an array is called


a. floor address
b. foundation address
c. first address
d. base address

Ans d

Employability, Enterprise & Entrepreneurship

1. The post order traversal of binary tree is DEBFCA. Find out the pre order traversal.

A. ABFCDE

B. ADBFEC

C. ABDECF

D. ABDCEF
Ans c

2. While converting binary tree into extended binary tree, all the original nodes in binary tree
are .......

A. Internal nodes on extended tree

B. External nodes on extended tree

C. Vanished on extended tree

D. Intermediate nodes on extended tree


Ans a
3. In a graph if e=(u,v) means .......

A. u is adjacent to v but v is not adjacent to u.

B. e begins at u and ends at v

C. u is node and v is an edge.

D. both u and v are edges.


Ans b

4. A binary tree whose every node has either zero or two children is called .........

A. Complete binary tree

B. Binary Search tree

C. Extended binary tree

D. E2 tree
Ans c

5. If every node u in G is adjacent to every other node v in G,A graph is said to be ........

A. isolated

B. complete

C. finite

D. strongly connected.
Ans b

6. The post order traversal of a binary tree is DEBFCA. Find out the pre order Traversal.

A. ABFCDE

B. ADBFEC

C. ABDECF

D. ABDCEF
Ans c

7. In a graph if e=[u,v], then u and v are called


A. endpoints of e

B. adjacent nodes

C. neighbours

D. all of the above


Ans d

8. A connected graph T without any cycles is called .

A. a tree graph

B. free tree

C. a tree

D. All of above
Ans d

9. If every node u in G adjacent to every other node v in G, A graph is said to be

A. isolated

B. complete

C. finite

D. strongly connected
Ans b

10. Three standards ways of traversing a binary tree T with root R .......

A. Prefix, infix, postfix

B. Pre-process, in-process, post-process

C. Pre-traversal, in-traversal, post-traversal

D. Pre-order, in-order, post-order


Ans d
11. A graph is said to be ....... if every node u in G is adjacent to every other node v in G.

A. Absolute
B. Entire

C. Inclusive

D. Complete
Ans d

Life Long Learning

1.Which of the following is not a stable sorting algorithm?

A. Insertion sort
B. Selection sort
C. Bubble sort
D. Merge sort
Ans b
2. If the number of records to be sorted is small, then …… sorting can be efficient.

A. Merge
B. Heap
C. Selection
D. Bubble
Ans c
3. What is the advantage of bubble sort over other sorting techniques?

A. It is faster
B. Consumes less memory
C. Detects whether the input is already sorted
D. All of the mentioned
Ans c
4. Consider the situation in which assignment operation is very costly. Which of the
following sorting algorithm should be performed so that the number of assignment operations
is minimized in general?

A. Insertion sort
B. Selection sort
C. Heap sort
D. None
Ans b
5.The worst-case occur in linear search algorithm when …….
A. Item is somewhere in the middle of the array

B. Item is not in the array at all


C. Item is the last element in the array
D. Item is the last element in the array or item is not there at all
Ans d
6.Which of the following is not a limitation of binary search algorithm?
A. must use a sorted array
B. requirement of sorted array is expensive when a lot of insertion and deletions are
needed
C. there must be a mechanism to access middle element directly
D. binary search algorithm is not efficient when the data elements more than 1500.
Ans d
7. The Average case occurs in the linear search algorithm ……….
A. when the item is somewhere in the middle of the array
B. when the item is not the array at all
C. when the item is the last element in the array
D. Item is the last element in the array or item is not there at all

Ans a

8. Binary search algorithm cannot be applied to …


A. sorted linked list
B. sorted binary trees
C. sorted linear array
D. pointer array
Ans a
9. Complexity of linear search algorithm is ………
A. O(n)
B. O(logn)
C. O(n2)
D. O(n logn)
Ans a
10.  is putting an element in the appropriate place in a sorted list yields a larger sorted order list.
A. Insertion
B. Extraction

C. Selection
D. Distribution
Ans a
11. Which of the following sorting algorithm is of divide and conquer type?
A. Bubble sort
B. Insertion sort
C. Merge sort
D. Selection sort
Ans c
12. Suppose we have a O(n) time algorithm that finds median of an unsorted array. Now
consider a QuickSort implementation where we first find median using the above algorithm,
then use median as pivot. What will be the worst case time complexity of this modified
QuickSort.

A. O(n^2 Logn)
B. O(n^2)
C. O(n Logn Logn)
D. O(nLogn)
Ans d

Any Other (Domain Specific)

1. The given array is arr = {1,2,4,3}. Bubble sort is used to sort the array elements. How
many iterations will be done to sort the array?

 A. 4

 B. 2

 C. 1

 D. 0

Ans a
2.The total number of comparisons in a bubble sort is ....

A. O(n logn)

B. O(2n)

C. O(n2)

D. O(n)
Ans a

3 .f the number of record to be sorted large and the key is long, then ...... sorting
can be efficient.

A. Merge

B. Heap

C. Quick
D. Bubble
Ans c

4.The given array is arr = {1,2,4,3}. Bubble sort is used to sort the array elements.
How many iterations will be done to sort the array with improvised version?
a) 4
b) 2
c) 1
d) 0
Ans b

5.Suppose we are sorting an array of eight integers using quicksort, and we have just finished
the first partitioning with the array looking like this:
    2 5 1 7 9 12 11 10
    Which statement is correct?

A. The pivot could be either the 7 or the 9.


B. The pivot could be the 7, but it is not the 9
C. The pivot is not the 7, but it could be the 9
D. Neither the 7 nor the 9 is the pivot.
Ans a

6. Select the appropriate code that performs bubble sort.


a)

for(int j=arr.length-1; j>=0; j--)


{
for(int k=0; k<j; k++)
{
if(arr[k] > arr[k+1])
{
int temp = arr[k];
arr[k] = arr[k+1];
arr[k+1] = temp;
}
}
}
b)

for(int j=arr.length-1; j>=0; j--)


{
for(int k=0; k<j; k++)
{
if(arr[k] < arr[k+1])
{
int temp = arr[k];
arr[k] = arr[k+1];
arr[k+1] = temp;
}
}
}
c)

for(int j=arr.length; j>=0; j--)


{
for(int k=0; k<j; k++)
{
if(arr[k] > arr[k+1])
{
int temp = arr[k];
arr[k] = arr[k+1];
arr[k+1] = temp;
}
}
}
d)

for(int j=arr.length; j>=0; j--)


{
for(int k=0; k<j; k++)
{
if(arr[k] > arr[k+2])
{
int temp = arr[k];
arr[k] = arr[k+1];
arr[k+1] = temp;
}
}
}
Ans a
7. How can you improve the best case efficiency in bubble sort? (The input is already sorted)
a)

boolean swapped = false;


for(int j=arr.length-1; j>=0 && swapped; j--)
{
swapped = true;
for(int k=0; k<j; k++)
{
if(arr[k] > arr[k+1])
{
int temp = arr[k];
arr[k] = arr[k+1];
arr[k+1] = temp;
swapped = false;
}
}
}
b)

boolean swapped = true;


for(int j=arr.length-1; j>=0 && swapped; j--)
{
swapped = false;
for(int k=0; k<j; k++)
{
if(arr[k] > arr[k+1])
{
int temp = arr[k];
arr[k] = arr[k+1];
arr[k+1] = temp;
}
}
}
c)

boolean swapped = true;


for(int j=arr.length-1; j>=0 && swapped; j--)
{
swapped = false;
for(int k=0; k<j; k++)
{
if(arr[k] > arr[k+1])
{
int temp = arr[k];
arr[k] = arr[k+1];
arr[k+1] = temp;
swapped = true;
}
}
}
d)

boolean swapped = true;


for(int j=arr.length-1; j>=0 && swapped; j--)
{
for(int k=0; k<j; k++)
{
if(arr[k] > arr[k+1])
{
int temp = arr[k];
arr[k] = arr[k+1];
arr[k+1] = temp;
swapped = true;
}
}
}
Ans c
8. The post order traversal of binary tree is DEBFCA. Find out the pre order traversal.

A. ABFCDE

B. ADBFEC

C. ABDECF

D. ABDCEF
Ans c

9. While converting binary tree into extended binary tree, all the original nodes in binary tree
are .......

A. Internal nodes on extended tree

B. External nodes on extended tree

C. Vanished on extended tree

D. Intermediate nodes on extended tree


Ans a

10. In a graph if e=(u,v) means .......

A. u is adjacent to v but v is not adjacent to u.

B. e begins at u and ends at v

C. u is node and v is an edge.

D. both u and v are edges.


Ans b

You might also like