Data Structures Course Outline Notes
Data Structures Course Outline Notes
Notes
Simplified Notes with C++ Code
Examples
Introduction to Data Structures
• Definition: A data structure is a way to
organize and store data efficiently.
• Types: Linear (e.g., arrays, linked lists) and
Non-linear (e.g., trees, graphs).
Linear and Non-Linear Data
Structures
• Linear: Array, Stack, Queue, Linked List.
• Non-Linear: Tree, Graph.
Static and Dynamic Data Structures
• Static: Size is fixed (e.g., array).
• Dynamic: Size can change (e.g., linked list).
Abstraction and Abstract Data
Types (ADT)
• Abstraction: Hiding complex details, showing
only essential features.
• ADT: Data structure defined by behavior (e.g.,
Stack with push/pop).
Arrays and Operations
• Definition: Collection of items stored at
contiguous memory locations.
• Operations: Accessing elements, updating
values, and iteration.
• C++ Code:
• #include <iostream>
• using namespace std;
• int main() {
Stack (LIFO) and Queue (FIFO)
• Stack:
• Operations: Push, Pop, Peek.
• C++ Code:
• #include <iostream>
• #include <stack>
• using namespace std;
• int main() {
• stack<int> s;
Linked Lists
• One-way Linked List: Nodes are connected in
one direction.
• C++ Code:
• #include <iostream>
• using namespace std;
• struct Node {
• int data;
• Node* next;
Trees
• Binary Tree: Each node has a maximum of two
children.
• C++ Code:
• #include <iostream>
• using namespace std;
• struct Node {
• int data;
• Node* left;
Polish Notation (Prefix, Postfix)
• Prefix: Operators are before operands, e.g.,
+AB.
• Postfix: Operators are after operands, e.g.,
AB+.
Heaps
• Definition: A special Tree-based data structure
that satisfies the heap property.
• Heap Sort: Sorting technique using heap
properties.
Hashing
• Definition: Mapping data to a unique index.
• Applications: Hash tables.
• C++ Code:
• #include <iostream>
• #include <unordered_map>
• using namespace std;
• int main() {
• unordered_map<string, int> hash_table;
Graphs
• Definition: Collection of nodes connected by
edges.
• Types: Directed, Undirected.
Memory Management and
Garbage Collection
• Memory Management: Process of managing
memory allocation.
• Garbage Collection: Reclaims memory from
objects no longer in use.
• C++ Code:
• int* ptr = new int; // Allocate memory
• delete ptr; // Free memory