CS MCQs

Arrays and Linked Lists MCQs, Set 1 of 1

  1. Q1. What is the time complexity of accessing an array element by its index?

    • A.O(1)(correct answer)
    • B.O(log n)
    • C.O(n)
    • D.O(n log n)

    Array elements sit in contiguous memory, so the address is computed directly from the index.

  2. Q2. In a singly linked list, each node stores data and a pointer to the:

    • A.Previous node
    • B.Next node(correct answer)
    • C.Head node
    • D.Last node

    A singly linked list only links forward, from each node to the next one.

  3. Q3. What is the worst-case time to search for a value in an unsorted singly linked list of n nodes?

    • A.O(1)
    • B.O(log n)
    • C.O(n)(correct answer)
    • D.O(n²)

    In the worst case you visit every node once.

  4. Q4. Which operation is faster on a linked list than on an array?

    • A.Random access by index
    • B.Binary search
    • C.Inserting at the beginning(correct answer)
    • D.Finding the maximum value

    Inserting at the head only changes a pointer (O(1)); an array must shift every element (O(n)).

  5. Q5. In a doubly linked list, each node has pointers to:

    • A.Only the next node
    • B.Only the previous node
    • C.Both the next and previous nodes(correct answer)
    • D.The head and the tail

    Two pointers per node let you move forwards and backwards.

  6. Q6. What is the index of the first element of an array in C or Java?

    • A.0(correct answer)
    • B.1
    • C.-1
    • D.Depends on the compiler

    C, Java and most C-style languages use zero-based indexing.

  7. Q7. In a circular linked list, the last node points to:

    • A.NULL
    • B.The first node(correct answer)
    • C.Itself
    • D.The middle node

    The list wraps around, so the last node links back to the first.

  8. Q8. What is the amortized time to append an element to the end of a dynamic array?

    • A.O(1)(correct answer)
    • B.O(log n)
    • C.O(n)
    • D.O(n²)

    Occasional resizing costs O(n), but averaged over many appends each one costs O(1).

  9. Q9. How many elements does the 2D array int a[3][4] hold?

    • A.7
    • B.12(correct answer)
    • C.3
    • D.4

    3 rows × 4 columns = 12 elements.

  10. Q10. What is the main disadvantage of a linked list compared to an array?

    • A.It has a fixed size
    • B.No direct access by index(correct answer)
    • C.It cannot store duplicates
    • D.Inserting at the head is slow

    To reach the k-th node you must walk from the head, which takes O(k) time.

  11. Q11. In row-major order, element a[i][j] of an array with C columns is stored at offset:

    • A.i * C + j(correct answer)
    • B.j * C + i
    • C.i + j
    • D.i * j

    Skip i full rows of C elements, then move j places along the row.

  12. Q12. What marks the end of a singly linked list?

    • A.A pointer to the head
    • B.A NULL pointer(correct answer)
    • C.A pointer to itself
    • D.A pointer to the middle node

    The last node’s next pointer is NULL (null or None in other languages).

All Arrays and Linked Lists sets