QUESTIONBANK2
QUESTIONBANK2
1. Define the concept of an iterator and explain how it works. Then, describe a scenario where
and how iterators are helpful. Finally, explain what needs to be done to make an iterator class
in Python.
2. Define the concept of an iterable in Python and explain how it works. Then, provide
examples of intrinsic Python iterable classes and describe how they are used. Finally, explain
the difference between an iterable and an iterator in Python, and provide an example to
illustrate the difference.
3. What are the key points one has to keep in mind when making a class iterable (classes and
methods to use)?
4. In Python, what do you need to do in order to augment your collection of elements with an
iterator?
5. If implemented properly in Python, how should your iterator inform Python that there are no
more elements in the collection to iterate through?
6. What is a generator in Python, and how is it different from an iterator?
7. How can you use the yield keyword to create a generator function in Python?
8. What are the advantages of using generators over lists or other iterable objects in Python?
9. How can you use the for loop to iterate over an iterator or generator in Python?
10. Consider the following Python generator function called mystery . What does this function
do? Analyze the time complexity of its single run in terms of the input size n. How does the
use of the yield keyword and the conditional statement affect the output of the function?
Provide some examples of input values and their corresponding output values. Finally,
explain some potential use cases for this generator function.
Linked ADTs
1. What is the complexity of a given operation on a given Linked ADT? Examples: push/pop
operation on a linked stack, append/serve operation on a linked queue, etc.
2. Give a summary of what Abstract Data Types are, and explain what their main advantages
and disadvantages are. Exemplify your explanation.
3. Given a simple arithmetic expression provided to you by your instructor, show how a stack-
based calculator computes its result. Show all the states of the stack until it computes the final
result. The expression should be given in the postfix notation stored as a list.
Example expression: [1, 2, +, 3, 4, +, -].
4. Summarise the main advantages and disadvantages of linked ADTs vs their array-based
counterparts.
5. What is the difference between a stack and a queue? Can you provide an example of a
scenario where a stack would be more appropriate than a queue and vice versa?
6. How can you use a stack to check if a string of parentheses is balanced? Can you provide an
example of a balanced and an unbalanced string?
7. What is the time complexity of the push(), pop(), peek(), and __len__() operations in a linked
stack? How do they compare to the time complexity of the same operations in an array-based
stack?
8. What does the function below do? And also, what is its complexity (best and worst case)?
With respect to what should it be analysed?
9. What does the function below do? And also, what is its complexity (best and worst case)?
With respect to what should the complexity be analyzed?
10. What does the function below do? And also, what is its complexity (best and worst case)?
With respect to what should the complexity be analyzed?
A2 - Theoretical Test - Question Bank [ Part II of V ]
Dictionary ADT, Hash Tables, Separate Chaining
3. Give an example of a good/bad hash function targeting string-typed keys. Explain what it is
good/bad.
4. What is a collision? How can it be resolved? Name 2 collision handling techniques studied in
the unit. Provide one line describing them.
5. Briefly describe Separate Chaining giving details about
1. What is Separate Chaining
2. Why is it used?
3. How is it implemented?
4. What data structures can be used to implement separate chaining?
6. Describe how each of the below operations work for a Hash Table which uses separate
chaining to handle collisions and give examples. What is the best-case and worst-case
complexity of one of the below operations? Explain the reason for the best and worst case. No
explanation no marks.
o search
o add
o delete
A2 - Theoretical Test - Question Bank [ Part III of V ]
Hash Tables - Linear Probing, Load Factor
which has linear probing implemented (with a standard probe step size of 1). Also, consider
the following strings:
Calculate and state the hash value of the above strings. Explain and show how they are
inserted into the table (using the same order of insertion). State what happens when you
search for the strings "python", "java" and "program".
8. Consider the following array in a LinearProbeHashTable:
A2 - Theoretical Test - Question Bank [ Part IV of V ]
1. Briefly describe the concept of recursion in Computer Science by
o Providing a definition of recursion in your own words;
o Providing an example and explaining how it works;
o Explaining what is the base case and recursive case of the example given.
2. Contrast the operation of recursion and iteration in Computer Science. Analyze the
advantages and disadvantages of using recursion over iteration in Computer Science. Provide
an example and explain the reasoning behind your answers.
3. Can a recursive function be reimplemented by means of iteration? If yes, how? Give an
example.
4. Can an iterative function be reimplemented by means of recursion? If yes, how? Give an
example.
5. Briefly describe the concept of tail recursion by
o Providing an example and explaining how it works;
o Describing how tail recursion works and how it differs from regular recursion.
6. Define the concepts of recursion and iteration and explain how they differ in terms of their
properties:
o Provide at least one advantage and disadvantage of using recursion compared to
iteration,
o Provide examples to support your points.
7. Analyze the python code provided below and determine whether it is tail recursive or not.
Explain your reasoning.
Finally, if the provided function is not tail recursive, explain how it could be modified to use
tail recursion. If tail recursive, explain what makes it tail recursive.