Font size
WorksheetsDSA QUIZ - 2 (17-06-23)
Total questions: 40
Worksheet time: 58mins
Which of the following items are present in the function header?
Function name only
Both function name and parameter list
parameter list only
Return value
Fill in the line of code for calculating the factorial of a number.
def fact(num):
if num == 0:
return 1
else:
return _____________________
num*fact(num-1)
(num-1)*(num-2)
num*(num-1)
fact(num)*fact(num-1)
What is the output of the following piece of code?
def test(i,j):
if(i==0):
return j
else:
return test(i-1,i+j)
print(test(4,7))
13
7
Infinite Loop
17
what is a variable defined outside all the function referred to as?
A static variable
A global variable
A local variable
An automatic variable
Pick one from the following statements to correctly complete the function body to get the output 5 in the given code snippet:
def f(number):
#missing function body
print(f(5))
return "number"
print(number)
print("number")
return number
What happens if the base condition isn’t defined in recursive programs?
Program gets into an infinite loop
Program runs once
Program runs n number of times where n is the argument given to the function
An exception is thrown
_____________ specifies how we enter data into our programs and what type of data we enter.
data type
data
datum
all of above
In ___________ data structure data items are not in sequence.
non linear
linear
non-homogeneous
all of above
What will be the postfix form of the above expression -
(A+B)∗(C∗D-E)∗F/G
None of these
A B + C D ∗ E − F G ∗ / ∗
A B + C D E ∗ − F G / ∗ ∗
A B + C D ∗ E − F G / ∗ ∗
The following postfix expression with single digit operands is evaluated using a stack:
8 2 3 ^ / 2 3 * + 5 1 * -
6,1
5,7
3,2
1,5
What is the value of the postfix expression 6 3 2 4 + – *
1
40
74
-18
User perform following operations on stack of size 5 then -
push(1);
pop();
push(2);
push(3);
pop();
push(2);
pop();
pop();
push(4);
pop();
pop();
push(5);
Overflow Occurs
Stack Operations will be performed Smoothly
Underflow Occurs
None of these
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
Example of linear data structure except
array
tree
queue
stack
A series of values stored in memory is called ___
an array
a tree
a matrix
a struct
Complex data structures built on top of linked lists, that use First-In First-Out behaviour, are called ___
vectors
strings
queues
stacks
What is a data structure?
A method of arranging data
A way of keeping data without an order?
A "stack" only
There is no formal definition for "Data Structure"
Which is the correct operation for:
"Add a item to the rear of the queue."
enQueue(item)
Append.Queue(item)
enQueue()
AddItem(EnQueue())
Select operations that can be performed on a Queue Data Structure...
isEmpty()
pop()
push()
isFull()
Append(Item)
Where would pointers be pointing if...
- Eli leaves the Queue.
- Hanna joins the Queue.
- Adam joins the Queue.
- Jason leaves the Queue.
front = 0 rear = 5
front = 1 rear = 4
front = 2 rear = 4
front = 0 rear = 4
front = 2 rear = 5
What would happen if...
deQueue()
enQueue(Hanna)
enQueue(Steve)
enQueue(Jack)
front = 1 rear = 0
*and Steve would be unable to be added to position 0.
front = 1 rear = 5
*and Jack would be unable to be added to position 0
front = 0 rear = 5
front = 0 rear = 4
front = 1 rear = 4
A Queue can only store 6 data items. The Queue is sent 4 data items: Bert, Cynthia, Cedric and Albert. Where does the "Front" pointer point if a deQueue operation is performed.
Bert
Cynthia
Cedric
Albert
A Queue can only store 6 data items. The Queue is sent 4 data items: Bert, Cynthia, Cedric and Albert. Where does the "Rear" pointer point?
0
1
2
3
a QUEUE in a computer acts just like people queuing for a bus - the first person in queue is going to be the first to get on the bus.
True
False
What advantage does a linked list have over an array?
Size of the list doesn't need to be mentioned at the beginning of the program
You can add or remove elements from the middle of the list.
The linked list doesn't have a size limit
All of these are true.
Complete the code in the red column
string info; int link;
int info; NodeType link;
int info; string link;
int info; NodeType * link;
struct node *current = start->next
what will "current" contain if it is a pointer to a variable of type struct node ?
Address of 2nd Node
Data Field of 2nd Node
Address of 1st Node
None of these
How to delete node B?
head->next=TempPtr; free(TemPtr);
free(TemPtr); head->next=TempPtr->next;
head->next=TempPtr->next;free(TemPtr)r;
free(head); head->next= TempPtr->next
How many null pointers exists in a circular linked list?
0
1
2
3
To display data of the linked list:
LinkedList *ptr; while (ptr!=NULL){ cout<<ptr->data;}
LinkedList *ptr; while(ptr!=NULL){ ptr=ptr->Next;cout<<ptr->Data};
LinkedList *ptr; while(ptr!=NULL){ ptr=ptr->Next;}
LinkedList *ptr; while(ptr!=NULL){ ptr=ptr->Next;cout<<ptr->Next;}
The situation when in a linked list START=NULL is
underflow
overflow
list full
saturated
What advantage does a linked list have over an array?
A linked list can give you the data faster
It is easier to use
A linked list is not of a fixed size
It's better
When traversing a binary tree, which diagram is post-order?
Given a sequence of number below:
50,60,40,70,45,55,30,80,65,35,25,75,85
When creating a binary search tree, what is the height of the tree?
3
4
5
6
Given a binary search tree, insert 27, 15, 63, 99, 70 and 85 (in this order) into the binary search tree. What is the post-order traversal?
5,15,27,34,47,54,63,70,72,75,83,85,88,94,99,101
72,54,34,5,27,15,47,63,70,83,75,88,85,101,94,99
15,27,5,47,34,70,63,54,75,85,99,94,101,88,83,72
15,27,5,47,34,63,54,70,75,85,99,94,101,88,83,72
none of the above
The postfix form of the expression (A+ B)*(C*D- E)*F / G is?
AB+ CD*E – FG /**
AB + CD* E – F **G /
AB + CD* E – *F *G /
AB + CDE * – * F *G /
Which of the following statement about binary tree is CORRECT?
Every binary tree is either complete or full
Every complete binary tree is also a full binary tree
Every full binary tree is also a complete binary tree
A binary tree cannot be both complete and full
