Data Structure and Algorithm Flashcards
What is a data structure?
A data structure is a format for arranging, processing, accessing, and storing data. It is designed to organize data for specific uses, making it easier for users to access and manipulate the data they need.
What is Big-O notation?
Big-O notation describes the performance or complexity of an algorithm, indicating the worst-case scenario for how the running time grows as the input size increases.
What are the types of time complexity in Big-O notation?
O(1): Constant time complexity (operation takes the same time regardless of input size).
O(n): Linear time complexity (time grows linearly with input size).
O(log n): Logarithmic time complexity (time grows logarithmically, dividing the search interval).
O(n²): Squared time complexity (time grows quadratically as input size increases).
What is an array data structure?
An array is a data structure containing items of similar data types. It allows for efficient access to elements using indices.
What is a linked list?
A linked list is a linear data structure where each element (node) contains two items: the data and a reference to the next node. It is dynamic and can grow/shrink in size as needed.
What is the difference between stacks and queues?
Stacks follow Last-In-First-Out (LIFO). Operations: push (add element), pop (remove element).
Queues follow First-In-First-Out (FIFO). Operations: enqueue (add element), dequeue (remove element).
What is a HashMap?
A HashMap stores key-value pairs, where each key is hashed to a hash code for efficient access.
What is a tree data structure?
A tree is a hierarchical data structure with nodes connected by edges. Each node contains a value and may have child nodes. A binary tree is a special type of tree where each node has at most two children.
What is O(1) complexity in an algorithm?
O(1), or constant time complexity, refers to operations that take a fixed amount of time regardless of the size of the input.
How does a binary search tree (BST) work?
A binary search tree allows inserting numbers and searching for specific values. Each node has at most two children, with the left child being less than the parent node, and the right child being greater. It allows efficient searching, insertion, and deletion.
What is the purpose of a queue?
A queue is used for handling data in a First-In-First-Out (FIFO) order, which is ideal for scheduling tasks, managing resources, or processing data streams.
What is the push operation in a stack?
The push operation adds an element to the top of the stack in a Last-In-First-Out (LIFO) order.
What is the pop operation in a stack?
The pop operation removes the top element from the stack, adhering to the Last-In-First-Out (LIFO) principle.
What does enqueuing mean in a queue?
Enqueuing means adding an element to the end of the queue, following the First-In-First-Out (FIFO) order.
What does dequeuing mean in a queue?
Dequeuing means removing an element from the front of the queue, adhering to the First-In-First-Out (FIFO) principle.