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
  1. 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

  1. 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

  1. Which data structure is used to store key-value pairs? A) Arrays B) Tables C) Linked lists D) Dictionaries

Answer: D) Dictionaries

  1. 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

  1. 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

  1. 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

  1. Which of the following data structures is most similar to a table? A) Arrays B) Stacks C) Queues D) Linked lists

Answer: A) Arrays

  1. 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

  1. 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

  1. 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
  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  6. 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.

  7. 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.

  8. 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.

  9. 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.

  10. 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.

Tables and dictionaries are two important data structures used in computer programming and database management. A table is a collection of data organized into rows and columns, much like a spreadsheet. Each row represents a unique record or data point, while each column represents a specific attribute or characteristic of that data. Tables can be used to store and manage large amounts of data in a structured way, making it easy to search, sort, and retrieve information. Dictionaries, on the other hand, are a type of associative array that store data in key-value pairs. Each key is unique and associated with a specific value, allowing for quick and easy retrieval of data based on the key. Dictionaries are commonly used in programming for tasks such as counting occurrences of specific elements, tracking data dependencies, and storing configurations. Hash tables are a specific type of dictionary that use a hash function to map keys to indices in an array. This allows for constant-time lookup of values based on the associated key, making them highly efficient for tasks such as caching and indexing. In database management, tables are a central component of relational databases, which store data in tables that are linked together through key relationships. Common operations performed on tables include adding, updating, and deleting data, as well as searching and sorting data based on specific criteria. In text processing, dictionaries and tables are often used to store and search for words and phrases. Tries, a tree-based data structure, can also be used to store and search for words in text. Efficient management and manipulation of tables and dictionaries can have a significant impact on the performance and functionality of a computer program or database. As such, developers and database administrators must carefully consider the appropriate data structures to use for each task, as well as optimizing their implementation to ensure optimal performance.