chapter

    Linear Data Structures Notes for Cmi M.sc. and Ph.d. Computer Science

    Linear Data Structures notes for CMI M.Sc. and Ph.D. Computer Science: 39 study cards covering concepts, formulas, shortcuts and exam traps, plus solved pract

    Linear Data Structures notes

    Contiguous memory and constant time access

    Intuition

    Contiguous memory and constant time access

    An array is a contiguous block of memory storing elements of fixed size, enabling constant time random access independent of array size.

    The problem it solves

    Imagine a one dimensional array of one hundred integers starting at address one thousand. Each integer occupies exactly four bytes of contiguous physical memory. You can find the tenth integer instantly by calculating its exact offset. Processors use this predictable spacing to fetch data efficiently into cache lines.

    The physical analogy stops being valid when memory is fragmented. Arrays require strictly contiguous physical memory addresses to maintain this access speed.

    The idea made exact
    is the starting memory address is the zero based index is the byte length of one element

    Address calculation for multi-dimensional arrays

    Derivation

    Address calculation for multi-dimensional arrays

    We map a two dimensional array into one dimensional memory using row major storage.

    10 rows 20 columns bytes
    Numbered steps
    1. Count full rows preceding row . This count equals . Rows before each contain all columns.
    2. Multiply this count by the column dimension twenty. This gives the total elements in all preceding full rows.
    3. Count elements in the current row before column . This count equals . Only columns before contribute.
    4. Add the results of step two and step three. This sum is the total number of elements preceding .
    5. Multiply this sum by the element size four. Converts element count to byte offset.
    6. Add the base memory address one thousand. Shifts offset to absolute memory address.
    Final formula
    CHECK

    Set and . The offset becomes zero and the address correctly equals one thousand.

    Confusing search time with insertion time in sorted arrays

    WRONG BELIEF

    Inserting an element into a sorted array takes logarithmic time.

    WHY IT FEELS RIGHT

    Binary search finds the correct insertion position quickly.

    SMALLEST COUNTEREXAMPLE

    The array contains elements ten, twenty and thirty. We want to insert fifteen into this sorted array. Binary search finds index one after two comparisons. Shifting twenty and thirty to the right requires two memory moves. The shifting step takes time proportional to the array size.

    COUNTER RULE

    Finding a position is logarithmic but shifting elements is linear. The maximum of these two operations dictates the total time complexity.

    HOW IT SHOWS UP IN OPTIONS

    Options list logarithmic time for insertion. Other options list linear time for searching the sorted array. Both options confuse the search phase with the modification phase.

    36 more cards in this chapter

    Free preview ends here

    Login to view the complete notes

    Creating an account is free. You get the rest of this chapter, step-by-step solutions, and a study plan built around the topics you are actually weak at.

    Explore complete test series, official past papers, and chapter-wise study tools.

    Why MastersUp

    Personalised first. High quality throughout.

    Most platforms hand everyone the same content. Here the content moves with your performance, topic by topic.

    Built around you, not around a syllabus PDF

    Every answer you give moves your topic-level intelligence rate. The next question, the next revision card and tomorrow's plan all change with it.

    Revision that hits your weak spots

    We only revise topics you have actually attempted and are still below the safe bar on — never the same chapter on repeat.

    Questions calibrated to the real exam

    Each question carries a measured toughness. You are served a rung above your current level, so practice keeps stretching you.

    Notes written for recall, not for volume

    Full lesson cards for first study, curated short-note cards for the last mile — with derivations, traps and exam patterns marked.

    One place for everything

    Notes, chapter practice, previous-year questions, test series and full-length papers — all feeding one picture of your preparation.

    Honest progress

    No vanity streaks. Progress here means chapters mastered and accuracy that held up on harder questions.

    Unlock the whole course

    Full notes and short notes, the complete question bank with worked solutions, mock tests, full-length papers, and an adaptive plan that rebuilds itself as you improve.

    Linear Data Structures Notes for CMI M.Sc. and Ph.D. Computer Science

    Linear Data Structures notes for CMI M.Sc. and Ph.D. Computer Science: 39 study cards covering concepts, formulas, shortcuts and exam traps, plus solved practice questions.

    Contiguous memory and constant time access

    Intuition

    Contiguous memory and constant time access

    An array is a contiguous block of memory storing elements of fixed size, enabling constant time random access independent of array size.

    The problem it solves

    Imagine a one dimensional array of one hundred integers starting at address one thousand. Each integer occupies exactly four bytes of contiguous physical memory. You can find the tenth integer instantly by calculating its exact offset. Processors use this predictable spacing to fetch data efficiently into cache lines.

    The physical analogy stops being valid when memory is fragmented. Arrays require strictly contiguous physical memory addresses to maintain this access speed.

    The idea made exact
    is the starting memory address is the zero based index is the byte length of one element

    Address calculation for multi-dimensional arrays

    Derivation

    Address calculation for multi-dimensional arrays

    We map a two dimensional array into one dimensional memory using row major storage.

    10 rows 20 columns bytes
    Numbered steps
    1. Count full rows preceding row . This count equals . Rows before each contain all columns.
    2. Multiply this count by the column dimension twenty. This gives the total elements in all preceding full rows.
    3. Count elements in the current row before column . This count equals . Only columns before contribute.
    4. Add the results of step two and step three. This sum is the total number of elements preceding .
    5. Multiply this sum by the element size four. Converts element count to byte offset.
    6. Add the base memory address one thousand. Shifts offset to absolute memory address.
    Final formula
    CHECK

    Set and . The offset becomes zero and the address correctly equals one thousand.

    Confusing search time with insertion time in sorted arrays

    WRONG BELIEF

    Inserting an element into a sorted array takes logarithmic time.

    WHY IT FEELS RIGHT

    Binary search finds the correct insertion position quickly.

    SMALLEST COUNTEREXAMPLE

    The array contains elements ten, twenty and thirty. We want to insert fifteen into this sorted array. Binary search finds index one after two comparisons. Shifting twenty and thirty to the right requires two memory moves. The shifting step takes time proportional to the array size.

    COUNTER RULE

    Finding a position is logarithmic but shifting elements is linear. The maximum of these two operations dictates the total time complexity.

    HOW IT SHOWS UP IN OPTIONS

    Options list logarithmic time for insertion. Other options list linear time for searching the sorted array. Both options confuse the search phase with the modification phase.

    Address mapping with non-zero lower bounds

    PROBLEM

    A three dimensional array has dimensions ten by twenty by thirty. Lower bounds are one, two and zero for the three dimensions. Element size is four bytes and base address is one thousand. Find the address of element five, ten, fifteen in column major order.

    FIRST INSTINCT

    Use the standard row major formula and ignore lower bounds.

    TRAP REVEAL

    Column major reverses the dimension multipliers completely. Lower bounds shift the calculated indices before multiplication.

    Show the elegant path
    1. Column major means the first dimension varies fastest. Dimension sizes are ten, twenty and thirty. Strides are $1$, $D_1 = 10$, $D_1 \times D_2 = 200$.
    2. Offset for dimension one is five minus one which equals four. Contributes $4 \times 1 = 4$ elements.
    3. Offset for dimension two is ten minus two multiplied by ten. This gives eighty elements from the second dimension.
    4. Offset for dimension three is fifteen minus zero multiplied by ten and twenty. This gives three thousand elements from the third dimension.
    5. Total element offset is four plus eighty plus three thousand. This sum equals three thousand and eighty four.
    6. Byte address is one thousand plus four multiplied by three thousand eighty four. The final address is thirteen thousand three hundred thirty six.

    CHECK: The minimum element gives an offset of zero and address one thousand.

    More notes in this unit