38 Lecture
CS301
Midterm & Final Term Short Notes
Table and Dictionaries
Tables and dictionaries are data structures used in computer programming for storing and retrieving data. A table is a collection of data organized in rows and columns, much like a spreadsheet. In programming, tables are often used to store larg
Important Mcq's
Midterm & Finalterm Prepration
Past papers included
Download PDF
- Which data structure is best suited for storing large amounts of data that can be easily searched and sorted? A) Arrays B) Tables C) Linked lists D) Trees
Answer: B) Tables
- Which data structure is best suited for storing configuration data or creating lookup tables? A) Arrays B) Tables C) Linked lists D) Trees
Answer: B) Tables
- Which data structure is used to store key-value pairs? A) Arrays B) Tables C) Linked lists D) Dictionaries
Answer: D) Dictionaries
- In a dictionary, what does the key represent? A) The value being stored B) The position in memory where the value is stored C) The identifier used to retrieve the value D) The data type of the value being stored
Answer: C) The identifier used to retrieve the value
- Which of the following is not a common operation performed on a dictionary? A) Adding a new key-value pair B) Removing a key-value pair C) Sorting the dictionary D) Updating the value of an existing key-value pair
Answer: C) Sorting the dictionary
- Which of the following is true about tables? A) They can only store numeric data B) They are similar to linked lists C) They are often used to store large amounts of data D) They cannot be searched or sorted
Answer: C) They are often used to store large amounts of data
- Which of the following data structures is most similar to a table? A) Arrays B) Stacks C) Queues D) Linked lists
Answer: A) Arrays
- Which of the following is an advantage of using a dictionary over a table? A) Dictionaries can store more data than tables B) Dictionaries are easier to search and sort than tables C) Dictionaries are more efficient for storing numerical data D) Dictionaries are more flexible for storing data in key-value pairs
Answer: D) Dictionaries are more flexible for storing data in key-value pairs
- Which of the following is an example of a key-value pair in a dictionary? A) "John", "Doe" B) "apple", 3.99 C) "red", "blue", "green" D) 123, "456"
Answer: B) "apple", 3.99
- Which data structure would be best suited for storing a list of items in the order they were added? A) Arrays B) Tables C) Linked lists D) Dictionaries
Answer: C) Linked lists
Subjective Short Notes
Midterm & Finalterm Prepration
Past papers included
Download PDF
What is a table, and how is it different from an array? Answer: A table is a data structure that consists of rows and columns, much like a spreadsheet. It is different from an array in that the rows and columns can be of different sizes and data types.
How are dictionaries used in programming, and what are some common operations performed on them? Answer: Dictionaries are used in programming to store key-value pairs. Common operations performed on them include adding new key-value pairs, removing existing ones, and updating the values associated with a given key.
What is a hash table, and how does it work? Answer: A hash table is a data structure that uses a hash function to map keys to indices in an array. The values associated with each key are then stored in the corresponding index of the array.
How does the efficiency of searching and inserting elements in a hash table compare to other data structures? Answer: Searching and inserting elements in a hash table can be done in constant time, making it very efficient. However, the efficiency can be impacted by the quality of the hash function used.
How are tables used in databases, and what are some common operations performed on them? Answer: Tables are used in databases to store large amounts of data in a structured way. Common operations performed on them include adding new rows or columns, deleting existing ones, and querying the data to retrieve specific information.
What is a trie, and how is it used in text processing? Answer: A trie is a tree-based data structure that is used to store and search for words in text processing. It works by breaking down words into their individual characters and representing them as nodes in the tree.
How can a table be sorted, and what is the efficiency of sorting? Answer: A table can be sorted by using an algorithm such as quicksort or mergesort. The efficiency of sorting depends on the size of the table and the specific algorithm used.
What is a dictionary lookup, and how is it performed? Answer: A dictionary lookup is the process of retrieving the value associated with a given key in a dictionary. It is performed by using the key to search the dictionary and returning the corresponding value.
How do hash collisions impact the efficiency of a hash table? Answer: Hash collisions occur when multiple keys map to the same index in the array used by the hash table. This can slow down search and insert operations, as additional steps must be taken to resolve the collision.
How does the efficiency of searching and inserting elements in a binary search tree compare to other data structures? Answer: Searching and inserting elements in a binary search tree can be done in logarithmic time, making it more efficient than linear search but less efficient than hash tables.