Lecture-Wise Questions & Answers (Lectures 1–22)
Lecture 1: Introduction to Data Structures and Arrays
Q1: What are constraints?
A: Constraints define limitations or restrictions on resources of a system (like memory, disk space, or time). Efficient solutions solve problems within resource constraints.
Q2: What is lvalue?
A: Lvalue is a memory location where a value can be stored. Appears on the left-hand side of assignment. Example: int var = 7; → var is lvalue.
Q3: What is the “current” pointer?
A: A variable showing the currently focused element in an array or list. Example: current = 5 means focus is on element 5.
Q4: What is an algorithm?
A: A finite sequence of steps to solve a problem.
Q5: Role of arrays in data structures:
- Store similar data efficiently.
- Enable constant-time read/write (
O(1)), but lookup operations likefind_minmay take linear time (O(n)). - Can be multidimensional (matrix, tensor).
Q6: How many types can data be organized?
- Linear (arrays, lists)
- Non-linear/Hierarchical (trees)
Q7: Importance of data structures:
- Queue in banks, undo in editors, online shopping lists, telephone networks, image bitmaps, printer spooler, browser history.
Q8: What is a chunk?
A: A piece of memory of reasonable size.
Q9: Basic purpose of data structure:
- Organize and store data efficiently for operations like searching, deletion, insertion.
Q10: What are argc and argv?
- Command-line arguments in
main(int argc, char** argv).
Q11: Difference between data structure and algorithm:
- Data Structure: Organization of data efficiently.
- Algorithm: Steps to solve a problem.
Q12: What is efficiency?
- Solving problem within resource constraints (time, space).
Q13: What is Array Name and x?
xis array name;x[0], x[1], …access elements.
Q14: List Data Structure & Operations:
| Operation | Description |
| createList() | Create a new list |
| copy() | Copy one list to another |
| clear() | Remove all elements |
| insert(X, ?) | Insert element X at a position |
| remove(?) | Remove element at a position |
| get(?) | Get element at position |
| update(X, ?) | Replace element at position with X |
| find(X) | Check if X exists |
| length() | Return list length |
Q15: Dynamic arrays:
- Resizable array allowing addition/removal of elements. Dynamic arrays differ from statically allocated arrays.
Q16: Difference between Array and List:
| Feature | Array | List |
| Memory | Contiguous/static | Dynamic/random |
| Size | Fixed | Can grow |
| Modification | Easy | Complex |
| Addition/Deletion | Not possible after declaration | Can add/delete nodes |
Lecture 2: Linked Lists and Dynamic Memory
Q1: What are linked lists?
- Sequence of nodes where each node points to the next. Allows dynamic memory allocation.
Q2: Why use arrays for implementing lists?
- Array implementation stores elements contiguously. Limitations: fixed size → use linked memory method.
Q3: Difference between static and dynamic arrays:
| Feature | Static Array | Dynamic Array |
| Memory | Stack | Heap |
| Size | Fixed | Can be input by user |
| Example | int arr[6]; | int* arr = new int[size]; |
Q4: Difference between array and list:
| Feature | Array | List |
| Elements | Homogeneous | Heterogeneous |
| Memory | Continuous | Random |
| Size | Fixed | Can be dynamic |
Q5: How to set current position?
- Assign an index to the
currentvariable, e.g.,current = 3;.
Q6: How to shift elements left/right in array?
- Use a loop to move elements; store first/last element temporarily.
Q7: Main operations on lists: (same as Lecture 1)
Q8: Main difference between array and list:
- Array: indexed, contiguous memory, static size.
- List: abstract, nodes, dynamic size, elements linked via pointers.