Bird
0
0
DSA Cprogramming~10 mins

Linked List vs Array When to Choose Which in DSA C - Interactive Comparison Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare an array of 5 integers.

DSA C
int numbers[[1]];
Drag options to blanks, or click blank then click option'
A0
B10
C5
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using zero as size which creates an empty array.
Forgetting to specify the size.
2fill in blank
medium

Complete the code to create a new node in a linked list.

DSA C
struct Node* newNode = (struct Node*) malloc(sizeof([1]));
Drag options to blanks, or click blank then click option'
ANode
Bstruct
Cint
Dmalloc
Attempts:
3 left
💡 Hint
Common Mistakes
Using sizeof(int) which is too small.
Using sizeof(struct) which is invalid.
3fill in blank
hard

Fix the error in the code to correctly insert a node at the beginning of a linked list.

DSA C
newNode->next = [1];
head = newNode;
Drag options to blanks, or click blank then click option'
Anext
BnewNode
CNULL
Dhead
Attempts:
3 left
💡 Hint
Common Mistakes
Setting next to newNode causes a cycle.
Setting next to NULL loses the rest of the list.
4fill in blank
hard

Fill both blanks to complete the code that prints all elements of an integer array.

DSA C
for(int i = 0; i [1] n; i[2]) {
    printf("%d ", arr[i]);
}
Drag options to blanks, or click blank then click option'
A<
B<=
C++
D--
Attempts:
3 left
💡 Hint
Common Mistakes
Using <= causes out-of-bounds access.
Using -- causes infinite loop.
5fill in blank
hard

Fill all three blanks to complete the code that creates a linked list node and sets its data and next pointer.

DSA C
struct Node* node = (struct Node*) malloc(sizeof([1]));
node->data = [2];
node->next = [3];
Drag options to blanks, or click blank then click option'
ANode
Bvalue
CNULL
Dint
Attempts:
3 left
💡 Hint
Common Mistakes
Using sizeof(int) instead of Node.
Forgetting to set next to NULL.