Data Structures & Algorithms - Midterm Summary
Data Foundations & ADTs
Data vs. Information:
Data: Raw facts without intrinsic meaning.
Process: Organize and interpret raw data.
Information: Meaningful result obtained after processing.
Data Structure: A method of organizing values so storage and operations can be performed efficiently.
Classification:
Linear: Array, Linked List, Stack, Queue.
Non-Linear: Tree, Graph.


Abstract Data Type (ADT):
ADT specifies what operations can be performed (behavior).
Implementation specifies how data is stored (e.g., Stack ADT implemented via Array or Linked List).
Algorithms & Pseudocode
Valid Algorithm Criteria:
Definiteness: Clear, unambiguous steps.
Finiteness: Must terminate after a finite number of steps.
Input: Zero or more quantities entering.
Output: One or more quantities leaving.
Effectiveness: Operations are basic enough to be doable.
Flowchart Symbols: Start/End, Input/Output, Process, Decision, and Control Arrows.
Pseudocode: Expresses logic clearly using structured constructs (
IF,FOR,WHILE,READ,PRINT) independent of exact language syntax.
Array Operations & Complexity
Array Rule: Elements share one declared type and occupy contiguous memory locations.
Indexing: Zero-based indexing; for elements, valid indices range from to .
Capacity vs. Logical Size:
Physical Capacity: Total memory cells allocated.
Logical Size: Number of elements currently used.
Time Complexities:
Index Access: Direct access, .
Traversal & Linear Search: Scans elements sequentially, .
Append: Add at logical end, (assuming available physical capacity).
Middle Insertion / Deletion: Requires element shifting, .
Update: Replaces value at valid index without shifting, .
Bubble Sort: After one complete ascending pass, the maximum value settles at the far-right index.
Dynamic Memory Management
Pointers: Store memory addresses rather than direct objects.
&(Address-of operator): Retrieves memory address of a variable.*(Dereference operator): Accesses value stored at a pointer address.
Dynamic Allocation:
new int[n]: Allocates contiguous block on the Heap at runtime.delete[] ptr: Releases dynamically allocated array memory. Matchesnew[]withdelete[].nullptr: Marks pointers explicitly as pointing to nothing post-release.
Memory Model:
Call Stack: Stores function call frames, parameters, local variables.
Heap / Free Store: Dynamic memory allocation (
new, dynamic arrays, nodes).
Linked Lists
Singly Linked List Node: Contains
DATAfield andNEXTpointer.Pointers:
head: Always points to the first node; losingheadresults in loss of list access.current: Used for list traversal (current = current->next).
List Operations:
Insert at Beginning:
new->next = head; head = new;Insert at End:
tail->next = new; new->next = nullptr;Middle Insertion/Deletion: Adjust link pointers between prior and next nodes before deleting/inserting.
List Variations:
Doubly Linked List: Contains
NEXTandPREVpointers for bidirectional traversal.Circular Linked List: Final node points back to
head; traversal stops upon returning to start node rather than encounteringnullptr.
Stacks & Queues
Stack (LIFO):
Operations:
Push(adds atTOP),Pop(removes fromTOP),Peek(readsTOPwithout removing).Array Stack Empty State:
top = -1. After pushes with no pops,top = m - 1.
Queue (FIFO):
Operations:
Enqueue(inserts atREAR),Dequeue(removes fromFRONT).Empty State:
FRONT = -1,REAR = -1.
Circular Queue:
Solves linear queue space wastage by wrapping array indices.
Wrap-around formula: .
Priority Queue:
Elements are processed by priority rather than arrival sequence.
High priority values are dequeued first when higher numbers represent higher priority.