[go: up one dir, main page]

0% found this document useful (0 votes)
5 views3 pages

Data Types and Structures

The document discusses various data types and structures in Python, highlighting the importance of data structures for efficient data management. It explains the differences between mutable and immutable types, lists and tuples, and the functionality of dictionaries and sets. Additionally, it covers concepts such as hash tables, data integrity, and the advantages of using different data structures in specific scenarios.

Uploaded by

Sai krishna
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Data Types and Structures

The document discusses various data types and structures in Python, highlighting the importance of data structures for efficient data management. It explains the differences between mutable and immutable types, lists and tuples, and the functionality of dictionaries and sets. Additionally, it covers concepts such as hash tables, data integrity, and the advantages of using different data structures in specific scenarios.

Uploaded by

Sai krishna
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Data Types and Structures Questions

1.What are data structures, and why are they important?


-​ Data structures are used to store ,manage,and retrieve data
effectively. These data structures define how data is accessed and
manipulated and effect the overall performance of program
2. Explain the difference between mutable and immutable data
types with examples.
-​ Mutable types can be changed even after creation,eg: a list ,dict
and set whereas the immutable types cannot be changed once
they are created,eg: a tuple.
3. What are the main differences between lists and tuples in
Python?
-​ In python the lists are mutable and tuples are immutable,tuples
can be used as keys in a dictionary whereas list cannot be used in
that way,list uses memory and tuples are memory efficient.
4.Describe how dictionaries store data
-​ Dictionaries store data as key-value pairs. Keys are hashed and
are mapped to memory locations using a hash table.
5. Why might you use a set instead of a list in Python?
-​ Python set offers unique features like automatically removing
duplicates and is highly useful when order of elements doesn't
matter.
6.What is a string in Python, and how is it different from a list?
-​ In python a string is immutable and a list is mutable and list can
store values of any type.
7. How do tuples ensure data integrity in Python?
-​ In python since tuples are immutable i.e.,their data cannot be
changed ,this ensures that the data is protected from any sort of
modifications.
8. What is a hash table, and how does it relate to dictionaries in
Python?
-​ A hash table is a data structure that maps keys to values using a
hash function. The dictionaries are implemented as hash tables in
python language.
9. Can lists contain different data types in Python?
-​ Yes ,the list can have different types of data structures (Or) the list
can store heterogeneous data structures.
10.Explain why strings are immutable in Python.
-​ In python the strings are immutable as they allow for safety and
anysort of modification,the strings also allow for performance
optimization and hashability.
11.What advantages do dictionaries offer over lists for certain
tasks?
-​ The dictionaries offer more structured way of storing data when
compared with lists ,dictionaries also provide key-value based
access which provides more meaning to the data.
12. Describe a scenario where using a tuple would be preferable
over a list.
-​ Since tuples are immutable they can be used to prevent data
modification and security whereas a list cannot be used for this
purpose.
13.How do sets handle duplicate values in Python?
-​ In python the sets automatically removes duplicate value if they
exist.
14.How does the “in” keyword work differently for lists and
dictionaries?
-​ In lists the “in” keyword checks if a value exist or not whereas in
dictinaries it checks for the key value.
15.Can you modify the elements of a tuple? Explain why or why not
-​ No,tuples are immutable, once they are created they cannot be
changed.
16.What is a nested dictionary, and give an example of its use
case?
-​ Nested dictionary contains another dictionary as a value.
17.Describe the time complexity of accessing elements in a
dictionary.
-​ The average case time complexity is O(1)
-​ Worst case time complexity is On)
18.In what situations are lists preferred over dictionaries?
-​ The lists are preferred over dictionaries when the
-​ Order of data matter
-​ Duplicate smatter
-​ When key value based data is not needed
-​ When storing iterated is important.
19.Why are dictionaries considered unordered, and how does that
affect data retrieval?
-​ The dictionaries does not maintain any insertion order and are
accessed via keys(not position). And it does not affect the data
retrieval process.
20.Explain the difference between a list and a dictionary in terms of
data retrieval.
-​ List retrieve data by position(index values) whereas dictionary
retrieve data by key .

You might also like