NEW
Font size
WorksheetsDS QUIZ-1 (CSE-42)
Total questions: 16
Worksheet time: 19mins
What is the time complexity of the following code:
int a = 0, i = N;
while (i > 0) {
a += i;
i /= 2;
}
O(Nlog N)
Consider the following C program :
#include < stdio.h >
int main () {
int arr [] = {1,2,3,4,5,6,7,8,9,0,1,2,5};
int *p = arr+4;
printf ("%d\n", p[1]);
return 0;
}
The number that will be displayed on execution of the program is?
2
What would be output ?
55
Which of the following is/are true
calloc() allocates the memory and also initializes the allocates memory to zero, while memory allocated using malloc() has random data.
calloc() takes two arguments, but malloc takes only 1 argument.
Both malloc() and calloc() return \'void *\' pointer.
All of the above
A 2-D array A[4.....7, -1.....3] requires 2 bytes of storage space for each element. if the array is stored in row major form having base address 100, then address of A[6,2] will be...?
126
116
What are the elements present in the array of the following C code?
int array[5] = {5};
5, (garbage), (garbage), (garbage), (garbage)
(garbage), (garbage), (garbage), (garbage), 5
An array of similar data types which themselves are a collection of dissimilar data type are ___________
Linked list
Array of Structure
Which of the following statements is false?
In static allocation, memory cannot be resized at runtime
In dynamic allocation, unused memory must be explicitly freed by programmer
Static allocation uses stack memory
Dynamic allocation uses stack memory
If you allocate memory using malloc() but forget to call free(), it may cause:
Consider a 1000 × 1000 matrix with only 1000 non-zero elements. Which storage is more efficient?
Normal 2D array representation
Sparse matrix representation (triplet)
Both are equally efficient
Depends on the compiler
In the worst case, the number of comparisons needed to search a singly linked list of length n for a given element is
The following C function takes a simply-linked list as input argument. It modifies the list by moving the last element to the front of the list and returns the modified list. Some part of the code is left blank.
Node* move_to_front(Node head) {
if ((head == NULL) || (head->next == NULL)) {
return head;
}
Node* prev = NULL;
Node* temp = head;
while (temp->next != NULL) {
prev = temp;
temp = temp->next;
}
// Fill in the missing code here
return head;
}
Choose the correct alternative to replace the blank line.
The following C function takes a single-linked list of integers as a parameter and rearranges the elements of the list. The function is called with the list containing the integers 1,2,3,4,5,6,7 in the given order. What will be the contents of the list after the function completes execution?
void rearrange(struct node *head) {
if (head == NULL || head->next == NULL)
return;
struct node* temp = head;
struct node* temp1 = head->next;
while (temp1 != NULL) {
int swap = temp->value;
temp->value = temp1->value;
temp1->value = swap;
temp = temp1->next;
if (temp != NULL){
temp1 = temp->next;
else
temp1 = NULL;
}
}
To Insert a node after a given node ptr. Fill in the blanks.
struct node* newNode = (struct node*)malloc(sizeof(struct node));
newNode->data = x;
newNode->next = ptr->next;
newNode->prev = ______; // Blank 1
if (ptr->next != NULL)
ptr->next->prev = ______; // Blank 2
ptr->next = newNode;
Blank 1: ptr,
Blank 2: newNode
Blank 1: prev,
Blank 2: newNode
Blank 1: NULL,
Blank 2: newNode
Blank 1: newNode
Blank 2: prev
Let SLLdel be a function that deletes a node in a singly-linked list given:
a pointer to the node to be deleted, and
a pointer to the head of the list.
Similarly, let DLLdel be another function that deletes a node in a doubly-linked list, given:
a pointer to the node to be deleted, and
a pointer to the head of the list.
Let n denote the number of nodes in each of the linked lists.
Which one of the following statements is TRUE about the worst-case time complexity of SLLdel and DLLdel?
On a scale of 1 to 5, how would you rate your Data Structures professor?
1
