1.4 Data Structures Flashcards
What is a list in data structures, and what are its common uses?
A list is a versatile and essential data structure used to store and manipulate ordered data. It is great for situations where you need to add, remove, or reorder items dynamically.
Common Uses:
Task Management Apps: Lists can store tasks, allowing users to add, remove, or mark tasks as complete.
Social Media Feeds: Lists can display posts in real-time, ensuring the latest content appears in the correct order.
Shopping Carts: Lists can manage items added by users, allowing easy updates or removals.
Why Use Lists?
Lists are flexible and dynamic, making them ideal for applications where the data size changes frequently.
What is an array, and when should you use it?
An array is a fixed-size, ordered collection of elements. It is best suited for situations where the size of the data is known and doesn’t change often.
Common Uses:
Mathematical Operations: Arrays store numbers for calculations like averages or trends.
Weather Apps: Arrays can store temperature readings over time for analysis.
Image Processing: Arrays represent pixel data in images, enabling efficient manipulation.
Why Use Arrays?
Arrays provide random access to elements, meaning you can quickly access any element using its index. However, their fixed size makes them less flexible than lists.
What is a stack, and how does it work?
A stack is a data structure that follows the Last-In-First-Out (LIFO) principle. This means the last item added is the first one to be removed.
Common Uses:
Undo/Redo Operations: Stacks store changes in text editors, allowing users to revert to previous states.
Browsing History: Stacks manage the order of visited web pages in browsers.
Why Use Stacks?
Stacks are simple and efficient for managing operations where the order of actions matters, like reversing or backtracking.
What is a queue, and how is it different from a stack?
A queue is a data structure that follows the First-In-First-Out (FIFO) principle. This means the first item added is the first one to be removed.
Common Uses:
Printer Jobs: Queues manage print requests in the order they are received.
Chat Applications: Queues store incoming messages to display them in the correct sequence.
Game Actions: Queues handle user actions in games, ensuring they are processed in order.
Why Use Queues?
Queues are ideal for managing tasks or data that need to be processed in the order they arrive.
What is a heap, and where is it commonly used?
A heap is a specialized tree-based data structure used for priority queues. It allows efficient access to the highest or lowest priority item.
Common Uses:
Task Scheduling: Heaps manage tasks based on their priority.
Memory Management: Heaps allocate and deallocate memory efficiently.
Why Use Heaps?
Heaps are optimized for quickly finding and removing the highest or lowest value, making them ideal for priority-based systems.
What is a tree in data structures, and what are its applications?
A tree is a hierarchical data structure used to represent data with natural relationships or hierarchies.
Common Uses:
Database Indexing: Trees like B-trees speed up search, insert, and delete operations.
AI Decision-Making: Decision trees classify data in machine learning.
File Systems: Trees organize files and directories in a hierarchical manner.
Why Use Trees?
Trees provide efficient ways to manage and search hierarchical or relational data.
What is a hash table, and how does it work?
A hash table is a data structure that uses a hash function to map keys to their corresponding storage locations. This allows for constant-time access to stored values.
Common Uses:
Search Engines: Hash tables store and retrieve indexed data based on keywords.
Caching Systems: Hash tables manage frequently accessed data for quick retrieval.
Programming Languages: Hash tables implement symbol tables for variables and functions.
Why Use Hash Tables?
Hash tables provide fast lookups, insertions, and deletions, making them ideal for applications requiring quick data access.
What is cache friendliness, and why is it important?
Cache friendliness refers to how well a data structure aligns with the CPU cache to minimize cache misses and improve performance.
Key Points:
Contiguous Memory: Arrays store elements in contiguous memory, making them cache-friendly.
Non-Contiguous Memory: Linked lists scatter elements in memory, leading to more cache misses.
Performance Impact: Cache-friendly data structures reduce access times, improving system efficiency.
Why Care About Cache Friendliness?
In performance-critical applications, choosing cache-friendly data structures can significantly speed up operations.
What is a graph, and where is it used?
A graph is a data structure that represents relationships between objects. It consists of nodes (vertices) and edges (connections).
Common Uses:
Social Networks: Graphs represent connections between users.
Recommendation Engines: Graphs suggest products or content based on relationships.
Pathfinding Algorithms: Graphs find the shortest path in maps or networks.
Why Use Graphs?
Graphs are ideal for modeling and analyzing relationships or networks.
What is a suffix tree, and why is it useful?
A suffix tree is a specialized data structure for efficiently searching strings in large documents.
Common Uses:
Text Editors: Suffix trees help find and replace text quickly.
Search Engines: Suffix trees locate all occurrences of a search term in a large text corpus.
Why Use Suffix Trees?
They provide fast and efficient string search capabilities, making them ideal for text-heavy applications.