EmSAT Achieve (UAE) · Computer Science

Algorithms and Python Programming

26 practice questions, each with the answer and an explanation.

Practise Algorithms and Python Programming now

Random questions from this topic, one at a time. You see the answer and the explanation straight after each one.

All 26 questions

  1. What is the output of the following Python expression: [x**2 for x in range(6) if x % 2 != 0]?
  2. What is the worst-case time complexity of searching for an element in a balanced binary search tree (AVL tree) containing n nodes?
  3. What will be printed by the following Python code snippet?

    def func(val, lst=[]):
    lst.append(val)
    return lst

    print(func(1))
    print(func(2))
  4. Which abstract data structure operates on a First-In, First-Out (FIFO) ordering principle?
  5. What is the return value of executing the recursive Python function `mystery(4)`?

    def mystery(n):
    if n <= 1:
    return 1
    return n * mystery(n - 1)
  6. What is the worst-case time complexity of the standard QuickSort algorithm when the chosen pivot is consistently the smallest or largest element?
  7. In Python, which of the following built-in data types is immutable?
  8. What is the output of the Python expression: 'UnitedArabEmirates'[6:10]?
  9. How many comparisons does binary search make in the worst case to determine if a target value is present in a sorted array of 1,024 elements?
  10. What data structure is utilized internally by the runtime call stack to manage nested subroutine execution and local variable scope?
  11. What is the output of the following Python code snippet?

    x = {1: 'a', 2: 'b'}
    y = x.get(3, 'default')
    print(y)
  12. Which sorting algorithm is guaranteed to have a worst-case time complexity of O(n log n) and is classified as a stable sorting algorithm?
  13. What is the result of evaluating `bool([]) or bool('False') and not bool(0)` in Python?
  14. In graph theory, which algorithm is used to find the shortest path from a single source vertex to all other vertices in a weighted graph with non-negative edge weights?
  15. What is the time complexity of looking up a value by its key in a Python dictionary under average operational conditions?
  16. What will be the output of executing the following Python list operations?

    a = [1, 2, 3]
    b = a
    b.append(4)
    print(len(a))
  17. What is the purpose of the base case in a recursive function?
  18. What does the following Python function compute for a positive integer n?

    def mystery(n):
    count = 0
    while n > 0:
    count += n & 1
    n >>= 1
    return count
  19. What is the space complexity of an iterative binary search algorithm implemented without recursion on an array of size n?
  20. Which Python keyword is used to handle exceptions and guarantee execution of cleanup code regardless of whether an exception occurred?
  21. What is the output of `list(filter(lambda x: x > 10, [5, 12, 8, 20, 10]))` in Python?
  22. What is the worst-case time complexity of inserting an element into a singly linked list at the head position?
  23. What does the Python expression `'abc' * 3` evaluate to?
  24. What algorithmic design paradigm is employed by MergeSort and QuickSort?
  25. What will be printed by the following Python code snippet?

    x = [1, 2, 3]
    y = [4, 5, 6]
    print([a + b for a, b in zip(x, y)])
  26. What is the primary difference between a stack and a queue data structure?

Ready for the full EmSAT Achieve (UAE) test?