Linear Data Structures and Algorithms Flashcards

(50 cards)

1
Q

What is an algorithm?

A

A finite, well-defined sequence of computational steps to solve a specific problem.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

List the five characteristics of an algorithm.

A

Finiteness, Definiteness, Input, Output, Effectiveness.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a computational problem?

A

A relationship between inputs and outputs, defined by preconditions and postconditions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the difference between an algorithm and a program?

A

An algorithm is conceptual; a program is its implementation in a programming language.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does it mean for an algorithm to be correct?

A

It is sound (valid results) and complete (guaranteed results for all valid inputs).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the RAM model?

A

A theoretical machine that assumes constant-time operations and infinite memory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Why is the RAM model useful?

A

It simplifies algorithm analysis by abstracting hardware complexities.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Define the term “effective” in the context of algorithms.

A

Each operation is basic and executable in finite time.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the purpose of pointer arithmetic in arrays?

A

To enable operations like indirect addressing (A[A[i]]).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Describe the difference between zero-based and one-based indexing.

A

Zero-based indexing starts at 0 (e.g., Java), while one-based indexing starts at 1.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is time complexity?

A

A measure of the number of operations an algorithm performs relative to input size.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the best-case complexity of insertion sort?

A

O(n), when the array is already sorted.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the worst-case complexity of insertion sort?

A

O(n^2), when the array is sorted in reverse order

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is mathematical induction?

A

A method of proving statements for all natural numbers by establishing a base case and an inductive step.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the invariant condition in insertion sort?

A

At each step, the subarray before the current element is sorted.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What does it mean for an algorithm to terminate?

A

It completes in a finite number of steps.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the role of preconditions in algorithm analysis?

A

They define valid input conditions for the algorithm to run correctly.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What are the steps of the insertion sort algorithm?

A

Pick an element, find its correct position, shift larger elements, and insert it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is the role of postconditions in algorithms?

A

They specify what must be true after the algorithm completes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

How can the runtime of an algorithm be analyzed?

A

By counting operations or steps in the RAM model.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What is an ADT?

A

Abstract Data Type - A specification of operations on data without detailing implementation.

21
Q

What are creators, observers, and mutators in ADTs?

A

Creators initialize data, observers query data, and mutators modify data.

22
Q

List the main operations of a stack.

A

push, pop, and peek.

23
Q

What is a queue, and what are its main operations?

A

A FIFO data structure with enqueue and dequeue operations.

24
How is a stack implemented using an array?
Using a fixed-size array and a pointer to track the top element.
25
What is a stack overflow?
Adding an element to a full stack.
26
What is a stack underflow?
Removing an element from an empty stack.
27
How are queues implemented using arrays?
Using circular arrays with head and tail pointers.
28
What is the difference between ADTs and data structures?
ADTs define functionality; data structures provide concrete implementations.
29
Why is data abstraction important?
It hides implementation details, allowing flexibility in modifying underlying structures.
30
How does insertion sort work conceptually?
By iteratively inserting elements into their correct positions in a sorted subarray.
31
What is the role of invariants in sorting algorithms?
They ensure the partial correctness of the algorithm at every step.
32
Why is insertion sort inefficient for large datasets?
Its worst-case complexity is quadratic.
33
What is the difference between bubble sort and insertion sort?
Bubble sort repeatedly swaps adjacent elements; insertion sort shifts elements to insert.
34
Why is merge sort preferred for larger datasets?
It has a better time complexity of O(nlogn).
35
What is the divide-and-conquer approach in merge sort?
Divide the array, sort each half recursively, and merge them.
36
Describe a key advantage of merge sort.
It guarantees O(nlogn) performance for all inputs.
37
What is the disadvantage of merge sort compared to quicksort?
Merge sort requires additional memory for merging.
38
What is the stability of a sorting algorithm?
Whether it preserves the relative order of equal elements.
39
What is a static data structure?
A data structure with a fixed size, like arrays.
40
What is a dynamic data structure?
A data structure that can grow or shrink in size, like linked lists.
41
How is a singly linked list implemented?
Using nodes with data and a reference to the next node.
42
What are the advantages of dynamic data structures?
Flexibility and efficient memory usage.
43
What is a circular queue?
A queue where the end wraps around to the front.
44
How is a stack implemented using a linked list?
Using a reference to the top node, where push and pop operate.
45
What is the difference between stacks and queues?
Stacks are LIFO, while queues are FIFO.
46
What is a priority queue?
A queue where elements are dequeued based on priority.
47
How does pointer arithmetic enable efficient data access?
By allowing direct computation of element addresses.
48
What is the key disadvantage of static arrays?
Their size must be known at allocation time.
49
Why do Java developers wear glasses?
Because they can’t C#!... haha