0% found this document useful (0 votes)
10 views

QUESTIONBANK2

questions to prepare for software test

Uploaded by

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

QUESTIONBANK2

questions to prepare for software test

Uploaded by

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

A2 - Theoretical Test - Question Bank [ Part I of V ]

Iterators and Generators

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

1. Briefly describe Dictionary ADT giving details about


1. Main property of a Dictionary ADT:
Stored in Key Value pairs, so rather than searching by index you search by key
Container type: stores and removes items irrespective on contents.

2. Key operations of the Dictionary ADT


Search:
Add:
Delete:
Update:
3. Name a few applications where dictionaries are of use.
Dictionaries, to store information by person as key
2. Briefly describe a Hash Function by elaborating on the below points
1. What is its purpose?
Purpose:
2. Properties of a Hash Function

3. How to define a Hash Function

4. Give an example of a Hash Function.

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

1. Briefly describe Linear Probing in a Hash Table giving details about


1. What is Linear Probing?
2. Why and when is it used?
3. What is the basic idea behind linear probing and how is it implemented?
4. How does it handle a collision?
5. How does it handle a conflict?
2. Describe how one of the below operations work for a Hash Table which uses Linear Probing
to handle collisions and give examples. What is the best-case and worst-case complexity of
the below operations. Explain the reason for the best and worst case. No explanation no
marks.
1. search
2. add
3. delete
3. Contrast the use of Linear Probing and Separate Chaining in Hash tables. Provide at least 1
advantage and disadvantage for each.
4. Distinguish between a collision and a conflict in hashing. How are they handled in a hash
table implemented with the below collision handling techniques. Provide an example for
each.
1. Linear Probing
2. Separate Chaining
5. Define the concept of a load factor in a hash table and explain how it is calculated. How does
the load factor affects the performance of below collision handling techniques. Give an
example of how adjusting the load factor can improve the performance for each.
1. Linear Probing.
2. Separate Chaining
6. Describe the problem of clustering in a hash table that uses the below collision handling
techniques. Does it pertain to both Linear Probing and Separate Chaining collision resolution
mechanisms? Explain how it can impact the performance of a hash table.
7. Consider the following hash function: which is used in a Hash Table

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.

8. Consider the following example Python function:

o Explain what is the purpose of this function


o What is the base case for this function?
o Is it tail-recursive?
o What is the output of this function for arr = [1, 2, 3, 4, 5, 6, 7, 8]
o How does the function recurse and how does the return value change in each call?
o Write an equivalent iterative version of this function.
o What is the best- and worst-case time complexity of the recursive function? Give a
one-line scenario for each complexity with the variables defined.
9. Consider the following example Python function:
o Explain what is the purpose of this function
o What is the base case for this function?
o Is it tail-recursive?
o What is the output of this function for arr = [1, 2, 3, 4, 5, 6, 7, 8]
o How does the function recurse and how does the return value change in each call?
o Write an equivalent iterative version of this function.
o What is the best- and worst-case time complexity of the recursive function? Give a
one-line scenario for each complexity with the variables defined.
10. Consider the following example Python function:

o Explain what is the purpose of this function


o What is the base case for this function?
o Is it tail-recursive?
o What is the output of this function for arr = [1, 2, 3, 4, 5, 6, 7, 8]
o How does the function recurse and how does the return value change in each call?
o Write an equivalent iterative version of this function.
o What is the best- and worst-case time complexity of the recursive function? Give a
one-line scenario for each complexity with the variables defined.

You might also like