ALL TEST SET E LVL1 PROGRAMMING
To complete ✅ your Tests of Hitbullseye
and Myperfectice with highest marks.
Dm now 96464 49252
What is the output of this program?
#mclude <stdio.h> int testo sta c int
n = 10; return n—; int main()
for(test(); test(); test()) prm ("%d
", test()); return 0; 741
852
Infinite loop
Compila on Error
What is the output of this program?
int main() void test(),
tenv()-, void test()
prin ("2
void tempo
prin ("l ");
10
01
Compile me error as foo is local to main
Compile me error due to declara on of func ons inside
main
What is the output of this program?
*include <stdio void main() void test() prin
(" 1 "); 1
Compila on Error
Run Time Error
None of the above
What is the output of this program? #include
<stdio .h> void test(int * ,
int
s); void main() { mta=5,b=6;
pnn ("%d void test(int *p, int
*q)
30 5
65 56
None of the above
What is the output of this program?
*include void test(char**); int
mamo
{ char = {"a", "b", "c", "d"};
test(argv); return 0; void test(char *
*p) { char
*m; m = (p+=
sizeof(int))[-2]; prm
("%s", m); a b c d
What is the output of this program?
*include int main() char =
"Hello"; *&*&*ptr);
return 0; H
Compila on Error
Run Time Error
Garbage Value
What is the output of this program?
*include void test(int
*a, int *b)
{ a=b; *a= 15; int x = 10, y =
20; { test(&x, &y); prin ("%d
%d", x, y); retum O; 15 15
10 15
10 20
15 20
What does the following statement mean? mt (*ptr)[5]; ptr
is an array of 5 integers ptr is a pointer to an array of 5
integers ptr is array of pointers to 5 integers ptr is an
pointer to array
What is the output of this program?
*Include int maino inta = 5; void *ptr =
&a return 0; 5
0.0000 0
What is the output of the given code?
*include <stdio.h> void maino inta = 0; int
&a ; " : ptr); prin ("%p " , ptr);
0 1 compila on
Error Run Time
Error
None of the above
What is the output of this program?
#mclude <stdio.h> void main() int *b = &a
; int * = ,
5 garbage value garbage value
5 5 garbage value
555
Error
What is the output of this program? #include void main()
int arr[3J = {1, 2, 3}; int *ptr = arr; int * *temp = &ptr prin
("%p %p", *tenv, arr); Same Address
Different Address
12
23
What will be the output? void maino
char far *farther, *farthest;
%d", sizeof(farther), sizeof(farthest));
42
22
44
24
Is this the correct way for a NULL pointer assignment?
int i=O-, char
*q=(char*)i;
Yes
No
May B
Can't Say
What is the output of this program?
*include void test(int * , int *);
void main() mta=5,b=6;
test(&a.&b); prin ("%d
%d",a,b); void test(int *p, int
*q)
30 6
6 36
36 6
-42
What is the storage class for variable A in the below code?
int main() int A; A
= 10; A); return O;
Auto
Register
Sta c
Extern
hich operator is used to access the member func ons and
variables of a class through a pointer in C++?
. (dot operator)
-> (arrow operator)
:: (scope resolu on operator)
: (colon operator)
What is the correct output of given code snippets in C++?
*include <iostream> *include
<deque> usmg namespace
std; int main() deque<int> d;
dpush_back(10);
dpush_back(20);
dpush_back(30);
:iterator itr = [Link]()
[Link](itr, 40); for (int i =
O; i < d-size(); i*+) { cout
<< d[i] << return O;
10 20 30 40
10 40 20 30 10 30 40
20
Syntax error
To complete ✅ your Tests of Hitbullseye
and Myperfectice with highest marks.
Dm now 96464 49252
Which of the following pseudo-codes correctly represents
the implementa on of a circular queue in C++?
enqueue(item): if rear
max size -
1 rear = 0 else: rear* +
queue[rear] = item
enqueue(item): rear = (rear
+ 1)
% max_size queue[rear] =
item enqueue(item): if rear
max size - 1: rear = 0
queue[rear] = item
enqueue(item): rear* +
queue[rear]
= item
In C++, what is the purpose of the "namespace" keyword
in program structure?
It defines a new scope for variables and func ons to avoid
naming conflicts.
It specifies the memory alloca on strategy for variables and
func ons.
It declares the visibility of variables and func ons within a
program.
It defines the inheritance hierarchy for classes and objects.
What is the primary purpose of backtracking in the context
of constraint sa sfac on problems?
To explore all possible solu ons
To quickly find the op mal solu on
To reduce the problem size
To enforce constraints on the search space
Let X be a problem that belongs to the class NP. Then
which one of the following is TRUE?
There is no polynomial me algorithm for X.
If X can be solved determinis cally in polynomial me, then
P = NP
If X is NP-hard, then it is NP-complete.
X may be undecidable.
ich of the following statements are TRUE? (1) The
problem of determining whether there exists a
cycle in
n undirected graph is in P. (2) The problem of determining
whether there exists a cycle in an
undirected raph is in NP. (3) If a problem A is NP-Complete, there exists a non-determinis c polynomial
me
algorithm o solve A.
1, 2 and 3
1 and 3
2 and 3
1 and 2
The Euler's circuit problem can be solved in?
O(N)
O(N log N)
O(log N)
O(N2)
In the Frac onal Knapsack problem, if the items have equal values but different weights, which
strategy should the greedy algorithm follow to obtain the op mal solu on?
Select the item with the highest weight
Select the item with the lowest weight
Select the item with the highest value-to-weight ra o
Select the item with the lowest value-to-weight ra o
Given a hash table T with 25 slots that stores 2000
elements, the load factor a for T is
80
0.0125
8000
1.25
In a doubly linked list, what is the me complexity of dele
ng a node when its pointer is given?
0(1)
O(log n)
O(n)
0(nA2)
Which data structure can be used to efficiently implement
a priority queue that supports efficient inser on, dele on,
and upda ng of priori es?
Binary heap
AVL tree
Hash table
Linked list
In the Knuth-Morris-Pra (KMP) algorithm, what is the
primary purpose of the "par al match table" or "failure
func on"?
To op mize the pa ern matching process
To make the pa ern shorter
To decrease memory usage
To ensure the pa ern is in lexicographical order
The average successful search me taken by binary search
on a sorted array of 10 items is
2.6
2.7
2.8 2.9
Consider the following code:
intarr[] = {1, 2, 3, 4,
5}; int *ptrl = arr, int *ptr2 = arr + 2; ptr2 -
ptrl);
What does this code snippet print?
3
4
Consider the following code:
int arr[3] = {1, 2, 3}; int *ptr = arr;
prin ("%d", ptr[2J);
What does this code snippet print?
2
3
Compiler Error
How are func on arguments passed in C++ by default?
By reference
By value
By pointer
By constant reference
How do you define a member func on of a class outside the class in C++?
returnType className::func onName(parameters) {body} func
onName::className(parameters) {body} className returnType::func
onName(parameters) {body} returnType func onName(parameters) ::
className {body}
Which of the following is NOT a valid C++ program structure?
Program with no "main" func on but with other func ons defined.
Program with mul ple "main" func ons defined.
Program with a "main" func on defined within a namespace
Program with a class defini on containing only sta c member func ons
What will be the output of the following C++ code?
*include <iostream>
[Link] namespace std; int main() {
mtn, for (n = 5; n < 0; n—) cout n;
if(n— 3) break;
Return 0;
543
54
5432
53
What is the main difference between a func on and a method in C++?
A func on cannot return a value, while a method can
A func on is defined inside a class, while a method is not
A method is a func on defined inside a class
There is no difference
What is a default argument in a func on in C++?
An argument that is always required
An argument that the func on uses if no corresponding
argument is passed
The first argument in a func on
An argument that defaults to zero
What is inheritance in C++?
Sharing data between classes
Deriving new classes from exis ng classes
Copying proper es of one class into another
Changing the behavior of a func on
Which of the following is NOT a valid C++ program structure?
Program with no "main" func on but with other func ons defined.
Program with mul ple "main" func ons defined.
Program with a "main" func on defined within a namespace.
Program with a class defini on containing only sta c member func ons.
Which of the following statements accurately describes the role of header files in C++ program structure?
Header files contain executable code that is included in the final program.
Header files define the interface for func ons and classes
used in a program.
Header files provide the main entry point for program execu on.
Header files declare global variables and func ons for the program.
In C++, what is the purpose of the "sta c" keyword in program structure?
It specifies that a variable or func on is only visible within
the current source file.
It defines a new namespace for the program.
It specifies that a variable or func on is defined in another source file.
It imports external libraries or header files into the program.
Which of the following statements accurately describes the role of the "iostream" header file in C++
program structure?
It defines input and output opera ons for console-based
programs.
It provides defini ons for standard data types and macros used in C++ programs.
It declares global variables and func ons for the program.
It specifies the entry point for program execu on.
To complete ✅ your Tests of Hitbullseye
and Myperfectice with highest marks.
Dm now 96464 49252
Consider the following C++ program snippet for inser ng a node at the end of a linked list:
*include <iostream> usmg namespace
std; struct Node { int data;
Node* next; void head, int value) {
Node* newNode = new Node newNode-
>data = value newNode->next =
nullptr; if (head == nullptr) {
head = newNode; Node* temp = head;
while (temp->next nullptr)
{ temp = temp->next; temp>next =
newNode; int main() { Node* head =
nullptr; insenEnd(head, l); insenEnd(head,
2); insertEnd(head, 3); insertEnd(head, 4);
insenEnd(head, 5); while (head == nullptr) {
cout head>data " head = head-
>next; return 0;
What will be the output of the program?
Infinite Loop
54321
1234
5432
Consider the below program, and iden fy which Opera on is performed. int solve(stmct
Node* head) if NULL) return 1; struct Node* ptr; ptr = head->next; while (ptr [Link] &&
ptr head) ptr = ptr->next; return (Otr head);
Checking for List is empty of not Checking for the list is
Circular or not count the number of elements in the list
None
To complete ✅ your Tests of Hitbullseye
and Myperfectice with highest marks.
Dm now 96464 49252
What does the following func on check for? (all necessary headers to be included and func on is called
from main) *define MAX 10 typedef struct stack mt top; int item[MAXJ
} stack; int func on(stack *s) if(s>top
== -1) return 1; else return 0; Full
stack
Invalid index
Empty stack
Infinite stack
What will be the output of the following C code snippet?
int = 2, 3}, {4, 5, int = arr; prm
("%d" + 2));
3 6
Choose a correct C++ for loop syntax.
for(initaliza on; condi on; inc/dec){ // statements }; for(declara on; condi on;
incrementopera on){ l/ statements }; for(declara on; incrementopera on; condi
on){ // statements }; for(initaliza on; condi on; incrementopera on){ // statements
};
What are access specifiers in C++?
Keywords that set the access level of class members
Func ons that determine how a class is accessed
Variables that specify the size of a class
Operators that manage class member access
In a C++ applica on, a developer implements a cache mechanism using smart pointers to manage cached
objects' memory. However, a er extended usage, the program's performance degrades significantly. What
could be a poten al reason for this performance degrada on?
Memory leaks occur, resul ng in excessive memory consump on
Smart pointer overhead, such as reference coun ng opera
ons, impacts performance
The program exceeds the maximum stack size allocated for dynamic memory
The cache mechanism encounters hash collisions, leading to increased lookup mes
In backtracking, what is the role of the "state space tree"?
It represents the en re problem space
It represents the current state of the system
It visualizes the pruning process
It is a data structure for storing solu ons
Which of the following problems cannot be solved op mally using a greedy algorithm?
Dijkstra's Shortest Path
Minimum Spanning Tree
Huffman Coding
Knapsack Problem
Which of the following best defines dynamic programming?
A programming technique for op mising code execu on speed.
A programming approach that divides a problem into smaller subproblems and solves them recursively.
A method to store and reuse previously computed results to
solve a problem more efficiently.
A process of transforming a problem into a set of mathema cal equa ons
Which data structure represents a collec on of nodes connected by edges where each node can have mul
ple child nodes?
Stack
Queues
Linked List
Graph
A text is made up of the characters a, b, c, d, e each occurring with the probability 0.11, 0.40, 0.16, 0.09
and 0.24 respec vely. The op mal Huffman coding technique will have the average length of:
2.40
2.16
2.26
2.15
A hash func on h defined h(key)=key mod 7, with linear probing, is used to insert the keys
44, 45, 79, 55, 91, 18, 63 into a table indexed from 0 to 6. What will be the loca on of key
18?
4
5 6
Which of the following standard algorithms is not Dynamic Programming based?
Bellman—Ford Algorithm for single source shortest path
Floyd Warshall Algorithm for all pairs shortest paths
0-1 Knapsack problem
Prim's Minimum Spanning Tree
A data structure in which elements can be inserted or deleted at/from both the ends but not in the middle
is? Queue
Circular queue
Dequeue
Priority queue
The KMP algorithm is par cularly efficient when searching for a pa ern within a text that:
Has a very long pa ern
Is very short
Contains no duplicate characters in the pa ern
Has a repea ng subpa ern
The average successful search me for sequen al search on 'n' items is.
n/2
(n-1)/2
(n + 1)/2
Log(n) + 1
What is the purpose of the •realloc• func on in C?
Allocates memory on the stack
Deallocates memory on the heap
Resizes the memory block previously allocated by *malloc'
or •calloc• .
Allocates memory for a constant variable
What is the output of the following C code snippet?
intarr[] = {1, 2, 3, 4, 5}; int *ptrl = arr +
2; int *ptr2 = arr; prin
("%d", ptrl - ptr2);
2
3
What is the purpose of a func on prototype in C++?
To define a func on
To declare a func on before its usage
To ini alize func on variables
To terminate a func on
What is polymorphism in C++?
The ability of a class to have mul ple constructors
The ability of a func on to perform different tasks based on
the context
The capability of crea ng many objects from a single class
The feature of combining mul ple classes into one
In C++, what is the purpose of the "namespace" keyword
in program structure?
It defines a new scope for variables and func ons to avoid
naming conflicts
It specifies the memory alloca on strategy for variables and
func ons
It declares the visibility of variables and func ons within a
program
It defines the inheritance hierarchy for classes and objects
What will be the output of the following C++ code?
#include <iostream> ustng namespace
std; mt mamo { mta= 10;
cout a if (n = 3) goto me; break;
return O; 1010 10
infinitely print 10 compile me
error
What is a 'const' member func on in C++?
A func on that can modify the object it is called on
A func on that cannot change any class member variables
A func on that is always called first
A constructor func on
What is the return type of a constructor in C++?
void
The type of the class
It has no return type
Int
In C++, what is the purpose of the "include" direc ve in
program structure?
It imports external libraries or header files into the
program.
It defines a new namespace for the program.
It specifies the entry point for program execu on.
It declares global variables and func ons for the program.
Which of the following are member dereferencing
operators in C++?
1. *
2. ::
3. _>*
4. ::* 5. _>
Only 1, 3, 4
Only 1 and 5 Only 3 and 4
only 3, 4, 5
Which of the following header file is required to use
deque container in C++?
<queue>
<deque>
<dqueue>
<cqueue>
What is the output of the following C++ code?
*include <iostream>
#mclude <queue>
usmg namespace std; int mam() {
queue<int> q;
[Link](10);
[Link](20);
[Link](30);
[Link](); cout qfront(); return 0;
10
20
30
Compila on Error
What is the correct output of the given code snippets?
*include <iostream> *include <deque> usmg
namespace std; int main() deque<int> d;
dadd(lO); da 20 for (int i = 0; i < [Link]();
i*+) { cout << d[i] return O;
10 20 30
Garbage Value
Syntax error
Run me error
What is the correct output of the given code snippets?
*include <iostream> usmg namespace std;
int main() deque<int> d;
10); dpush_back(20); d back 30 for (mt i =
O; i < [Link](); i+) { cout d[i] return O; 10
20 30
Garbage Value
Syntax error
Run me error
What will be the output of the following C++ program
snippet for dele ng the first node of a linked list?
*include <iostream> usmg namespace
std; struct Node { int data;
Node* next; void head) { if (head ==
nullptr) { Node* temp = head; head =
head->next; delete temp; int main() {
Node* head = new Node head->data = 1;
head>next = nullptr; deleteFirst(head); cout
<< head; return 0;
1 nullptr
Compila on error
What is the correct output of the given code snippets?
*include <iostream> #include <deque>
usmg namespace std; int main()
deque<int> d;
d. h fron O for (int i = O; i < [Link](); {
cout d[i] return 0; 10 20 30
20 10 30
30 10 20
Syntax error
Consider the following C++ code snippet for implemen ng
a circular queue using a linked
list:
*include <iostream> usmg namespace std;
class Node { public:
int data;
Node* next; Node(int value) { data =
value; next = nullptr class
CircularQueue { pnvate:
Node* front; Node* rear; public:
CucularQueue() { front = rear = nullptr,
bool isEmpty() { return front nullptr, bool
isFull() { return false; void enqueue(int
value) {
Node* newNode = new Node(value); if (isEmpty()) {
front = rear = newNode; rear-
>next = front; } else { rear->next = newNode•, rear
= newNode; rear->next = front; int dequeue() { if
(rsEmpty()) { cout << "Queue is empty. " << endl;
return -1, int item = front->data; if (front rear) {
delete front; front = rear = nullptr; } else { Node*
temp = front; front = front->next; rear->next = front;
delete temp; return item; int main() { CircularQueue
q;
q. enqueue( O);
q. dequeue();
q. dequeue();
q. enqueue(40);
q. dequeue(); cout << "Front element " << q dequeue() << endl, return
O;
What will be the output of the given code?
Empty Queue. Will cause compila on error
Front element: 20
Front element: 30 Front element: 40
What is a func on in C++?
A block of code that executes when the program starts
A named unit of code that can be invoked from other parts
of the program
A variable declara on
A class member
What is a constructor in C++?
A special func on used to ini alize objects of its class
A func on that destroys an object
A normal func on declared inside a class
A sta c member func on of a class
What is a class in C++?
A data type defined by the user A blueprint for
crea ng objects collec on of func ons container
for variables
What is the significance of the "backtrack" step in
backtracking algorithms?
It indicates a dead-end in the search space
It revisits previously explored solu ons
It involves undoing the most recent choice
It marks the star ng point of the algorithm
What is the me complexity of the dynamic programming
solu on for the Matrix Chain
Mul plica on problem with n matrices?
O(n)
0(nA2)
O(nA3)
O(2An)
What is the me complexity of the dynamic programming
algorithm for compu ng the nth
Fibonacci number?
O(n)
O(log n)
O(nA2)
O(2An)
The number of edges in a complete graph of n ver ces is n(n+1)/2 n(n-l)/2
nA2/2
n
The number of permuta ons of the characters in LILAC so
that no character appears in its original posi on, if the two
L's are indis nguishable, is
12
10
8
15
What is the search complexity in direct addressing?
O(n)
O(logn)
O(nlogn)
0(1)
Consider the following two problems of graph. 1) Given a
graph, find if the graph has a cycle that visits every vertex
exactly once except the first visited vertex which must be
visited again to complete the cycle. 2) Given a graph, find
if the graph has a cycle that visits every edge exactly once.
Which of the following is true about the above two
problems?
Problem 1 belongs NP Complete set and 2 belongs to P
Problem 1 belongs to P set and 2 belongs to NP Complete
set
Both problems belong to P set
Both problems belong to NP complete set
Let S be an NP-complete problem and Q and R be two other problems not known to be in NR Q is
polynomial me reducible to S and S is polynomial- me reducible to R. Which one of the following statements
is true?
R is NP-complete
R is NP-hard
Q is NP-compIete
Q is NP-hard
The "Manacher Array" or "P-array" in Manacher's
algorithm is used to:
Store palindromic substrings found in the text
Store informa on about the posi on and length of
palindromic substrings
Implement the hash func on
Keep track of the number of opera ons performed
Which of the following sor ng algorithm has the worst me
complexity of n Log n?
heap sort quick sort Inser on sort
selec on sort
What is the output of the following C code snippet?
int *ptr = arr; prin ("%d",
1
Which func on is used to free the memory allocated by the malloc func on? dealloc free
release dispose
What are variadic func ons in C++?
Func ons that can take a variable number of arguments
Func ons that return variable values
Func ons that vary in return type
Func ons that can be called in various ways
A C++ program is designed to manage a large database with extensive memory requirements. The
program dynamically allocates memory using the "new" operator to store database records. However, a er
running for a while, the program crashes due to excessive memory consump on. What could be a poten al
reason for this issue?
Memory fragmenta on causes an inability to find con guous memory blocks.
The program exceeds the maximum stack size allocated for dynamic memory.
Memory leaks occur, resul ng in con nuous alloca on of memory without dealloca on. The program
encounters a segmenta on fault due to invalid memory access. Which of the following statements
accurately describes the role of header files in C++ program structure?
Header files contain executable code that is included in the final program
Header files define the interface for func ons and classes used in a program
Header files provide the main entry point for program execu on
Header files declare global variables and func ons for the program
What will be the output of the following C++ code?
*include <iostream> usmg namespace
std; mt mam() { intn= 15;
for (; ;) cout << n; return O; error 15
infinite mes of prin ng n none of the men
oned
Which of the following is true about inline func ons in C++?
They are always faster than regular func ons
The compiler may ignore the inline request
They cannot have a loop
They are defined outside the class
How do you create an object in C++?
className objectName; objectName className;
className::objectName; new className;
Which of the following is true regarding the structure of a C++ program?
The "main" func on must be declared before any other func ons.
Func ons in a C++ program must be defined in the same order as they are called.
Variables declared inside a func on are accessible only within that func on.
C++ programs must have a class defini on even if no objects are instan ated.
What is the significance of the "return 0;" statement at the end of the "main" func on in a
C++ program?
It signifies the successful execu on of the program.
It indicates an error condi on and terminates the program.
It returns a value to the opera ng system indica ng the program's status.
It has no significance and can be omi ed without affec ng program execu on.
What is the result of the following code snippet?
*include <iostream> usmg namespace
std; int main() { int *ptr = arr, cout <<
*(ptr + 2) << endl; return 0;
1
3 4
What is the correct output of the given code snippets?
#include <iostream> #include <deque>
usmg namespace std; int main()
deque<mt> d; dpush_back(10); d h fron
20 dpop_back(); dpush_back(40);
for (int i = O; i < d-size(); iH-) { cout << d[i]
<< return
0; 10 20 40
1040
20 40
Syntax error
What is the output of the following program? public class Stack {
protected sta c final int
CAPACITY = 100; protected int size, top = 1; protected
Object stk[l; public Stack() { stk = new Object[CAPACITY],
public void push(Object item) { if(size_of_stack size) {
[Link] overflow"); return; } else { stk[top] = Item,
public Object pop()
{ if(top < 0) { return
-999;
} else {
Object ele = stk[top]; size of stack--; return ele; public class
StackDemo { public sta c void marn(String args[]) { Stack
my-Stack = new StackO; [Link](l O);
Object elementl = [Link]();
Object element2 = [Link]();
System. out.print1n(element2);
Stack is full
20
0
None of the men oned
What is the correct output of given code snippets in C++?
*include <iostream> *include <deque
usmg namespace std; int main()
deque<int> d; dpush_back(10);
d.push_back(20); dpush_back(30);
dmsefl(40); for (int i = 0; i < [Link](); i+)
{ cout d[i] return O;
10 20 30 40
10 20 40
103040
Syntax error
What is the correct output of the given code snippets?
*include *include
<deque> usmg
namespace std; int main()
dpush_back(20);
d.push_back(30); itr = d-end() itr++; dinsen(itr, 40);
for (int i
= O; i < d. size(); i-H-) { cout
<< d[i] << return O;
10 20 30 30
10 20 40 30
Garbage value
Syntax error
Consider the following C++ program snippet for coun ng the number of nodes in a linked
list:
#include <iostream> usmg namespace
std; struct Node { int data;
Node* next; mt countNodes(Node* head) { mt
count = O; while (head nullptr) { count++;
head = head; return count; int
mam() {
Node* head = new Node head->data = I
head->next = nullptr; cout <<
countNodes(head); return
O;
WHat will be the output of the program?
Infinite Loop
2
Compila on error
What is the correct implementa on of the dequeue() func on for a double-ended queue
(deque) in C++? void dequeue() {
q.pop_front(); void dequeue() {
q.pop_back(); void dequeue() {
[Link]([Link]()); void dequeue() {
q.remove_front();
There are the following statements that are given below, which of them are correct about deque container
in C++?
The deque stands for the double-ended queue.
The deque is a sequence container.
The deque is a derived container.
In the deque container, data can be inserted and deleted from both the front and back ends the side. A and
B A, C, and D
A, B, and D
C and D
Which of the following is NOT a valid way to ini alize a queue in C++?
queue<int> q; queue<int> q(5); queue<int> q =
{1 ,
2, 3}; queue<int> q(other_queue);
What is the func onality of the following code?
int func on() if (head null)
return [Link]
VALVE; mt var; Node temp = head; while
head) temp = [Link]; if (temp ==
head) { var = head. getltem(); head = null;
return var; [Link]([Link]()); var
= head. getltem(); head = head. getNext();
return var;
Choose the most appropriate answer.
Returns the data from the beginning of the list
Returns the data and deletes the node at the end of the list
Returns the data from the beginning of the list and deletes the node from the beginning of the list
Returns the data and deletes the node from the beginning of the list
In backtracking algorithms, what is the purpose of maintaining a "state vector"?
To store the final solu on
To keep track of the current state of the system
To represent the constraints of the problem
To guide the explora on of the search space
Which of the following is a drawback of the dynamic programming solu on for the 0/1
Knapsack problem?
It has exponen al me complexity
It requires exhaus ve search of all possible subsets
It does not guarantee an op mal solu on
It only works for small knapsack capaci es
The Longest Common Subsequence problem is a classic example of which type of dynamic programming
problem?
Par on problem
Op miza on problem
Shortest path problem
Subset sum problem
Which of the following is an advantage of adjacency list representa on over adjacency matrix representa
on of a graph?
In adjacency list representa on, space is saved for sparse graphs.
DFS and BSF can be done in O(V + E) me for adjacency list representa on. These opera ons take
O(VA2) me in adjacency matrix representa on. Here it is V and E are the number of ver ces and edges
respec vely.
Adding a vertex in adjacency list representa on is easier than adjacency matrix representa on.
All of the above
In the Frac onal Knapsack problem, what is the objec ve?
Maximise the total value of items taken
Minimise the total weight of items taken
Maximise the ra o of value to weight of items taken
Minimise the number of items taken
What is simple uniform hashing?
Every element has equal probability of hashing into any of the slots
A weighted probabilis c method is used to hash elements into the slots
All of the men oned
None of the men oned
What is the key property used in dynamic programming to solve the Longest Common
Subs uence roblem?
Op mal substructure
Overlapping subproblems
Greedy choice property
Subproblem decomposi on
Which of the following problems is not NP complete?
Hamiltonian circuit
Bin packing
Par on problem
Hal ng problem
Manacher's algorithm is par cularly efficient when:
There are no palindromes in the string
There is exactly one palindrome in the string
The string contains mul ple palindromic substrings
The string is very short
As part of the maintenance work, you are entrusted with the work of rearranging the library books in a
shelf in proper order at the end of each day. The ideal choice will be bubble sort inser on sort selec on
sort heap sort
Which of the following is a correct way to dynamically
allocate memory for a 2D array in c?
'int **arr = (int**)malloc(3 * sizeof(int));
'int arr[3][3] = (int*)malloc(3 sizeof(int));
'int *'arr = (int**)malloc(3 sizeof(int));
'int *'arr = (int**)malloc(3 sizeof(int));
What does the malloc func on return if it fails to allocate
memory?
Nullptr
0
-1
Excep on
What is the significance of the 'main' func on in C++?
It indicates the end of the program
It is the first func on that gets called when a program starts
It is used to define methods
It is a special class constructor
In a C++ applica on, a developer is implemen ng a custom
memory allocator to op mize memory usage. However,
during program execu on, memory corrup on issues arise,
leading to unexpected behavior and crashes. What could be
a likely cause of these memory corrup on issues?
The custom memory allocator fails to handle mul threading
scenarios effec vely.
The program exceeds the maximum stack size allocated for
dynamic memory
Memory leaks occur, resul ng in excessive memory
consump on.
The custom memory allocator incorrectly manages
memory alignment requirements.
In C++, what is the significance of the "return 0;"
statement at the end of the "main" func on in a C++
program?
It signifies the successful execu on of the program
It indicates an error condi on and terminates the program
It returns a value to the opera ng system indica ng the
program's status
It has no significance and can be omi ed without affec ng
program execu on
What will be the output of the following C++ code?
0123456789
10
012345678910 compile me error
What are member func ons in a C++ class?
Func ons defined outside the class
Func ons that operate on class data
Independent func ons
Func ons that return class objects
What is recursion in C++?
A loop in a func on
A class calling another class
A func on calling itself Overloading a func on In
C++, what is the purpose of the "extern" keyword in
program structure?
It specifies that a variable or func on is defined in another
source file.
It declares a variable or func on to have external linkage.
It defines a new class with external visibility.
It imports external libraries or header files into the
program.
What is the me complexity of finding the size of a queue in
C++?
0(1)
O(log n)
O(N)
O(n log n)
Consider the following C++ code snippet:
What does the func on in the *CircularQueue• class check
for?
Whether the queue is empty
Whether the queue is completely full
Whether the rear pointer is one posi on behind the front
pointer
Whether the queue has reached its maximum capacity
without any space for addi onal
Elements
Which operator is used for dynamic memory alloca on in
C++?
new malloc alloc alloc
mem
Given the following enqueue opera on in the
'CircularQueue• class:
What is the purpose of the '0/0' operator in the line •rear =
(rear + 1) % MAX SIZE?
It increments the rear pointer by one
It calculates the modulo opera on to ensure the rear pointer
wraps around in a circular manner
It checks if the queue is full
It resets the rear pointer to zero when it reaches the end of
the array
Consider the dequeue opera on in the 'CircularQueue'
class:
What does the condi on front == rear' represent?
Whether the queue is empty
Whether the queue is full
Whether there is only one element in the queue
Whether the rear pointer is one posi on behind the front
pointer
What will be the output of the following C++ program snippet for searching a key in a linked list? 0 1
true fals e
State the complexity of algorithm given below.
o(n)
O(logn)
0(1)
O(n logn)
Consider the following C++ program snippet for reversing
a linked list:
1
12
123
Compila on error
In C++, what is the purpose of the "placement new"
operator in memory management?
It is used to allocate memory from the stack for a new
object.
It allows the programmer to specify the memory loca on
where an object should be constructed.
t deallocates memory allocated for an object on the heap.
t automa cally manages memory alloca on and dealloca on
for objects.
In C++, which of the following correctly describes the
structure of a C++ program?
A C++ program consists of a single func on called "main"
where program execu on begins.
A C++ program consists of one or more func ons, with the
"main" func on serving as the entry point.
A C++ program must have exactly one class defini on, which acts as the main program structure.
A C++ program consists of a series of statements without
the need for func ons or classes.
What is the func onality of the given code? Choose the most
appropriate answer:
Print success if a par cular element is found
Print fail if a par cular element is not found
Print success if a par cular element is equal to 1
Print fail if the list is empty
In the "Subset Sum Problem," if we aim to find all subsets
that sum to a target value, what is the op mal backtracking
strategy?
Include only the elements that exactly meet the target sum
Include all elements and then backtrack to meet the target
sum
Exclude elements un l the target sum is reached
Include and exclude elements alternately un l the target
sum is reached
What is the output of the following code? int
find_max(int a, int b) if(a > b) retum a; return b; int
knapsack(int W, int •wt, int •val,int n) int ans[n + II[W+
1]; int itm,w; for(itm = O; itm <= n; itm++)
ans1itml[01 = O; for(w = W, w++)
for(itm = I; itm n; itm++) for(W = 1; W
W; W++)
if(wt[itm - IJ w)
= find_max(ans[itm - - - 1],
ans[itm else = anslitm – return int main() int wo =
= {60, 100, 120}, W = 50 int ans = knapsack(W, w,
v,
3); prin ("%d",ans); return O; 120
100
180 220
Consider two strings A = "qpqrr" and B = "pqprqrp". Let x
be the length of the longest common subsequence (not
necessarily con guous) between A and B and let y be the
number of such longest common subsequences between A
and B.
Then x + 10y =
33
23
43 34 Consider an
undirected random
graph of eight ver ces.
The probability that
there is an edge
between a pair of ver
ces is 1/2. What is the
expected number of
unordered cycles
Of length three?
1/8
7 8
Greedy algorithms are o en used for solving problems that
exhibit:
Overlapping subproblems
Op mal substructure
Both overlapping subproblems and op mal substructure
Neither overlapping subproblems nor op mal substructure
In simple uniform hashing, what is the search complexity?
O(n)
O(logn)
O(nlogn)
0(1)
Given the following statements: Sl : Every context-sensi ve language L is recursive S2 : There exists a
recursive language that is not context-sensi ve Which statements are true?
Only Sl is correct
Only S2 is correct
Both Sl and S2 are not correct
Both Sl and S2 are correct
Which greedy algorithm is used to solve the task
scheduling problem?
Dijkstra's Algorithm
Prim's Algorithm
Kruskal's Algorithm
Interval Scheduling Algorithm
When using Manacher's algorithm to find the longest
palindromic substring, what is th role of the "mirror"
variable?
To find the center of the longest palindrome
To compare characters in the text for equality
To improve the hashing process
To track the expansion of a palindrome around its center
The given array is arr = {1 Bubble sort is used to sort the array elements. How many itera ons will
be done to sort the array with improvised version?
2
1
To complete ✅ your Tests of Hitbullseye
and Myperfectice with highest marks.
Dm now 96464 49252