Bird
0
0
DSA Cprogramming~10 mins

Array Insertion at Beginning in DSA C - Interactive Practice

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

Complete the code to shift elements right before inserting at the beginning.

DSA C
for(int i = n - 1; i >= [1]; i--) {
    arr[i + 1] = arr[i];
}
Drag options to blanks, or click blank then click option'
A1
B0
Cn
D-1
Attempts:
3 left
💡 Hint
Common Mistakes
Starting the loop from 1 instead of 0 causes missing the first element.
Using n instead of 0 causes out-of-bound errors.
2fill in blank
medium

Complete the code to insert the new element at the beginning of the array.

DSA C
arr[[1]] = new_element;
Drag options to blanks, or click blank then click option'
An
B1
C0
Dn-1
Attempts:
3 left
💡 Hint
Common Mistakes
Inserting at index n or n-1 overwrites the last element.
Inserting at index 1 misses the true beginning.
3fill in blank
hard

Fix the error in the loop condition to correctly shift elements for insertion.

DSA C
for(int i = n - 1; i [1] 0; i--) {
    arr[i + 1] = arr[i];
}
Drag options to blanks, or click blank then click option'
A>
B<
C<=
D>=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' causes the loop to never run.
Using '<=' causes incorrect shifting direction.
4fill in blank
hard

Fill both blanks to correctly shift elements and insert at the beginning.

DSA C
for(int i = n - 1; i [1] [2]; i--) {
    arr[i + 1] = arr[i];
}
Drag options to blanks, or click blank then click option'
A>=
B>
C0
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' and 1 misses shifting the first element.
Using '<' or '<=' causes wrong loop direction.
5fill in blank
hard

Fill all three blanks to complete the insertion function at the beginning of the array.

DSA C
void insertAtBeginning(int arr[], int n, int new_element) {
    for(int i = n - 1; i [1] [2]; i--) {
        arr[i + 1] = arr[i];
    }
    arr[[3]] = new_element;
}
Drag options to blanks, or click blank then click option'
A>=
B0
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' without '=' misses shifting the first element.
Inserting at index other than 0 overwrites wrong element.