Chapter 11. Programming Flashcards
What are primitive data types?
- Basic data types provided by a programming language.
- Examples: Integer, Float, Boolean, Character.
What is the difference between an integer and a float?
- Integer: A whole number without a decimal point.
- Float: A number with a fractional part, represented with a decimal point.
What is a Boolean data type?
- A data type that can hold one of two values: True or False.
- Used in logical operations and control structures.
What is a character data type?
- A single letter, number, or symbol enclosed in single quotes.
- Represents text in programming.
What are composite data types?
- Data types that can store multiple values or a collection of items.
- Examples: Arrays, Lists, Tuples.
What is an array?
- A collection of elements, all of the same data type, stored in contiguous memory locations.
- Accessed using an index.
What are the advantages of using arrays?
- Fast access to elements using indices.
- Efficient in terms of memory usage for fixed-size collections.
What is a linked list?
- A linear data structure where each element (node) points to the next.
- Allows for dynamic memory allocation and efficient insertions/deletions.
What is the difference between a singly linked list and a doubly linked list?
- Singly linked list: Each node points to the next node only.
- Doubly linked list: Each node points to both the next and previous nodes.
What is a stack?
- A linear data structure that follows the Last In, First Out (LIFO) principle.
- Common operations: Push (add), Pop (remove).
What are the applications of a stack?
- Used in expression evaluation, function call management, undo operations in software.
What is a queue?
- A linear data structure that follows the First In, First Out (FIFO) principle.
- Common operations: Enqueue (add), Dequeue (remove).
What are the differences between a queue and a stack?
- Queue: FIFO structure, elements are added at one end and removed from the other.
- Stack: LIFO structure, elements are added and removed from the same end.
What is a priority queue?
- A data structure where each element has a priority.
- Elements with higher priority are dequeued before elements with lower priority.
What is a hash table?
- A data structure that maps keys to values using a hash function.
- Provides fast access to elements based on key.
What are the common uses of hash tables?
- Implementing associative arrays, caches, and sets.
- Used for fast data retrieval.
What is a binary tree?
- A hierarchical data structure where each node has at most two children (left and right).
- Used in searching, sorting, and hierarchical data representation.
What is the difference between a binary search tree and a balanced binary tree?
- Binary search tree: Left child is less than the parent, right child is greater.
- Balanced binary tree: Maintains a balanced height to ensure efficient operations.
What is a graph?
- A collection of nodes (vertices) connected by edges.
- Can be directed or undirected, weighted or unweighted.
What are the types of graphs in data structures?
- Directed graph: Edges have a direction.
- Undirected graph: Edges have no direction.
- Weighted graph: Edges have weights/costs associated with them.
What is a tuple in programming?
- An ordered collection of elements that can be of different data types.
- Immutable, meaning its elements cannot be changed after creation.
What is a set in data structures?
- An unordered collection of unique elements.
- Supports operations like union, intersection, and difference.
What are the differences between a list and a tuple?
- List: Mutable, can be modified after creation.
- Tuple: Immutable, cannot be modified after creation.
What is a dictionary in programming?
- A collection of key-value pairs where each key is unique.
- Allows fast lookup, addition, and deletion of key-value pairs.
What are the advantages of using a dictionary over a list?
- Provides faster lookup times for key-value pairs.
- Suitable for associative data where fast access is required.