# The Joy Of Computing Using Python Week 5 : Assignment 1 | NPTEL | Answers July 2023

## Which is the fastest sorting algorithm?

a. Bubble Sort
b. Bucket Sort
c. Quick Sort
d. Insertion Sort

c. Quick Sort

In practice, Quick Sort is usually the fastest sorting algorithm. Its performance is measured most of the time in O(N × log N). Bucket Sort is also a fast sorting algorithm, but it is generally used for sorting elements that are uniformly distributed over a range. In terms of performance, Insertion Sort tends to perform better than Bubble Sort and Selection Sort for small datasets, while Bubble Sort and Selection Sort may perform better than Insertion Sort for larger datasets or datasets that are partially sorted. Here is a summary of the time complexity of some popular sorting algorithms, from slowest to fastest

Bubble sort: O(n^2)
Revised bubble sort: O(n^2)

Selection sort: O(n^2)
Insertion sort: O(n^2) in the worst and average cases, O(n) in the best case
Quick sort: O(n*logn)
Merge sort: O(n*logn)

## How can you remove all items from a dictionary?

a. dict.clear()
b. del dict
c. dict.remove_all()
d. dict.pop()

a. dict.clear()

To remove all items from a dictionary in Python, you have a few options.

dict.clear(): This method is used to remove all key-value pairs from a dictionary. It doesn't delete the dictionary itself but leaves it empty, ready to be filled with new items.

del dict: Using the del statement followed by the dictionary name deletes the entire dictionary from memory, making it no longer accessible.

dict.pop(): The pop() method in a dictionary is generally used to remove a specific key-value pair based on the provided key. However, if you call dict.pop() without specifying a key, it will raise an error because the method requires a key argument.

Out of these options, using dict.clear() is the most straightforward way to remove all items from a dictionary while keeping the dictionary structure intact.

## What happens if you try to add a new key to a dictionary that already exists?

a. The key and its associated value will be updated.
b. The key and its associated value will be added.
c. The key will be added, but the associated value will remain unchanged.
d. An error will occur.

a. The key and its associated value will be updated.

If you try to add a new key to a dictionary that already exists, the key and its associated value will be updated.
In other words, if the key already exists in the dictionary, the value associated with that key will be replaced with the new value. If the key does not exist in the dictionary, a new key-value pair will be added. Here is an example of how to add a new key to a dictionary:

my_dict = {"apple": 2, "banana": 3, "orange": 4}
my_dict["apple"] = 5
print(my_dict) # Output: {"apple": 5, "banana": 3, "orange": 4}
In this example, the key "apple" already exists in the dictionary, so its associated value is updated from 2 to 5.

## Which of the following is true about dictionaries?

a. There can be multiple same keys.
b. Every value must be unique.
c. Every key must be unique.
d. We can’t get every key from the dictionary.

c. Every key must be unique.

In dictionaries, every key must be unique, meaning you can't have two identical keys in the same dictionary. However, the values associated with these keys can be the same. This is because dictionaries use keys to uniquely identify and access their corresponding values.

## What is the syntax to create a dictionary?

a. D = []
b. D = {}
c. D = ()
d. D = dictionary()

b. D = {}

To create a dictionary in Python, you can use the following syntax: D = {}
This syntax creates an empty dictionary using a set of curly braces {}

You can also create a dictionary with initial key-value pairs by including them inside the curly braces.

## What will be the output of the following code?

```d = {'a':20,'b':30,'c':50}
print(d.items())```
a. ‘a’ ‘b’ ‘c’
b. 20 30 50
c. ('a', 20), ('b', 30), ('c', 50)
d. (‘a’, ‘b’, ‘c’) (20, 30, 50)

c. ('a', 20), ('b', 30), ('c', 50)

## In the Monte Hall Problem, what is the probability of winning if you switch doors after the host reveals a goat behind one of the other doors?

a. 1/3
b. 1/2
c. 2/3
d. 3/4

c. 2/3

The Monty Hall Problem is a probability puzzle where you are presented with three doors, behind one of which is a valuable prize, and behind the other two are goats. After you choose a door, the host, who knows what's behind each door, opens one of the remaining doors that has a goat behind it. At this point, you have the option to either stick with your original choice or switch to the other unopened door. The question is, what is the probability of winning if you switch doors after the host reveals a goat behind one of the other doors? The answer is that the probability of winning if you switch doors is 2/3.
This is because when you initially choose a door, there's a 1/3 chance that you've picked the door with the prize behind it, and a 2/3 chance that the prize is behind one of the other two doors. When the host reveals a goat behind one of the remaining doors, the initial probabilities don't change.
The door you initially chose still has a 1/3 chance of having the prize, but the combined chance that the prize is behind one of the other two doors is still 2/3. Now, when you decide to switch doors, you're effectively choosing the combined chance of the two doors that you didn't originally pick. And since that combined chance is 2/3, switching doors gives you a 2/3 probability of winning the prize.

In summary, the probability of winning if you switch doors after the host reveals a goat behind one of the other doors in the Monty Hall Problem is 2/3.

## In the Monte Hall Problem, what is the probability of winning if you do not switch doors after the host reveals a goat behind one of the other doors?

a. 1/3
b. 1/2
c. 2/3
d. 3/4

a. 1/3

In the Monty Hall Problem, if you do not switch doors after the host reveals a goat behind one of the other doors, the probability of winning is 1/3

## What is the name of the game show that the Monte Hall Problem was based on?

a. Jeopardy
b. Wheel of Fortune
c. The Price is Right
d. Let's Make a Deal

d. Let's Make a Deal

The name of the game show that the Monte Hall Problem was based on is "Let's Make a Deal"
The show originated in the United States in 1963 and has since been produced in many countries
The format of the show involves selected members of the studio audience, referred to as "traders", making deals with the host
In most cases, a trader will be offered something of value and given a choice of whether to keep it or exchange it for a different item
The program's defining game mechanism is that the other item is hidden from the trader until that choice is made

## Which module in Python can be used for Speech to Text conversion?

a. SpeechRecognition
b. PyAudio
c. Wave
d. all of the above

a. SpeechRecognition

The module in Python that can be used for Speech to Text conversion is the SpeechRecognition module

### |All Assignment: The Joy of Computing using Python - Course | NPTEL

Disclaimer:
"This page contains multiple choice questions (MCQs) related to The Joy of Computing using Python. The answers to these questions are provided for educational and informational purposes only.These answers are provided only for the purpose to help students to take references. This website does not claim any surety of 100% correct answers. So, this website urges you to complete your assignment yourself."