Back to all Computer Science topics
Topic 6.2Computer Science SL20 flashcards

Data structures

Practice Flashcards

Flip cards to reveal answers
Card 1 of 206.2.1
6.2.1
Question

What is the difference between a static and a dynamic data structure?

Click to reveal answer

Track your progress — Sign up free to save your progress and get smart review reminders based on spaced repetition.

All Flashcards in Topic 6.2

Below are all 20 flashcards for this topic. Sign up free to track your progress and get personalized review schedules.

6.2.15 cards

Card 1comparison
Question

What is the difference between a static and a dynamic data structure?

Answer

A static structure has its size fixed when it is created, in one contiguous block of memory. A dynamic structure grows and shrinks while the program runs, taking more memory only when it needs it.

Card 2concept
Question

Why is reading a position in a static array fast?

Answer

Everything sits in one block with items of equal size, so the address of item 20 is simply the start plus twenty item-widths. It is one calculation, with nothing searched for — O(1).

Card 3concept
Question

What does a dynamic structure cost when it grows?

Answer

When it outgrows its block it must claim a bigger one and copy everything across. That single operation is expensive, but it happens rarely, so the average cost of adding an item stays low.

Card 4concept
Question

When should you choose a static structure?

Answer

When the size is genuinely fixed — twelve months, seven days, sixty-four squares — or when a very large amount of data is scanned repeatedly and both speed and predictable memory matter.

Card 5concept
Question

Why is a fixed-size array wrong for an unknown number of items?

Answer

You must guess a maximum. Guess too small and it overflows or silently discards data; guess too large and most of the memory is never used — with still no guarantee the guess was enough.

6.2.25 cards

Card 6concept
Question

How are items in a list addressed?

Answer

By position, starting at 0. A list of four items has positions 0, 1, 2 and 3, so asking for position 4 is an error — the commonest list bug there is.

Card 7definition
Question

How do you add to and remove from a dynamic list?

Answer

append adds at the end, insert(position, value) adds anywhere and shifts the rest along. remove(value) takes out the first match, and pop() removes the last item and gives it back.

Card 8concept
Question

Why must you not remove items while looping over a list?

Answer

Removing shifts everything after it down one place while the loop counter moves up, so items get skipped silently. Build a new list instead, or loop over a copy.

Card 9definition
Question

What is a 2D list and how is it addressed?

Answer

A list whose items are themselves lists — a grid. It is addressed [row][column], always in that order: grid[1][2] is row 1, column 2.

Card 10concept
Question

Why does visiting every cell of a grid need a nested loop?

Answer

The outer loop gives you each row, which is itself a list; the inner loop reaches the individual values inside it. That is also why scanning a grid is O(rows × columns).

6.2.35 cards

Card 11definition
Question

What is a stack?

Answer

A structure that allows adding and removing at one end only, the top. The last item put in is the first taken out — last in, first out, or LIFO.

Card 12definition
Question

What are the four stack operations?

Answer

push adds an item on top; pop removes the top item and returns it; peek returns the top item without removing it; isEmpty says whether there is anything in the stack at all.

Card 13concept
Question

Why are all stack operations O(1)?

Answer

Every operation touches only the top. Nothing is shifted along and nothing is searched for, so the cost is the same whether the stack holds three items or three million.

Card 14example
Question

Give three uses of a stack.

Answer

Undo, where the most recent action must be reversed first; the call stack, since function calls unwind in reverse order; and checking that brackets match, because the most recent opening bracket must close first.

Card 15concept
Question

What causes a stack overflow?

Answer

A stack that keeps growing with nothing being popped until it runs out of memory — usually a function that calls itself with no way to stop.

6.2.45 cards

Card 16definition
Question

What is a queue?

Answer

A structure added to at one end and taken from at the other: items join at the back and leave from the front. The first item in is the first out — first in, first out, or FIFO.

Card 17definition
Question

What are the four queue operations?

Answer

enqueue adds an item at the back; dequeue removes the item at the front and returns it; front returns the next item out without removing it; isEmpty says whether anyone is waiting.

Card 18concept
Question

Why is a plain list a poor implementation of a queue?

Answer

Removing from the front of a list shifts every remaining item down one place, which is O(n) every time. A proper queue structure removes from the front in constant time.

Card 19concept
Question

What one question chooses between a stack and a queue?

Answer

Does the most recent item matter most, or the one that has waited longest? Most recent means a stack; longest waiting means a queue.

Card 20example
Question

Give three uses of a queue.

Answer

Print jobs, so they print in the order sent; process scheduling, where round robin takes the front process and returns it to the back; and buffering data such as keystrokes or network packets, which must be handled in arrival order.

Want smart review reminders?

Sign up free to track your progress. Our spaced repetition algorithm will tell you exactly which cards to review and when.

Start Free
IB Computer Science SL Topic 6.2 Flashcards | Data structures | Aimnova