Docsity

Introduction to Algorithms and Complexity Analysis, Exams of Computer Science

Toggle sidebar
bg1
Introduction to Algorithms and Complexity
Analysis
1. Which property ensures an algorithm terminates
after a finite number of steps?
⬜ Definiteness
⬜ Effectiveness
☑ Finiteness
⬜ Input
2. What is the purpose of pseudocode?
⬜ Machine-executable code
☑ Human-readable algorithm description
⬜ Programming language
⬜ Debugging tool
3. What is the time complexity of linear search on an
unsorted list of n elements?
⬜ O(log n)
☑ O(n)
⬜ O(n^2)
⬜ O(1)
4. Which searching algorithm requires the input list to
be sorted?
☑ Binary search
⬜ Linear search
⬜ Depth first search
⬜ Breadth first search
5. What is the best-case time complexity of binary
search?
☑ O(1)
⬜ O(n)
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Introduction to Algorithms and Complexity Analysis and more Exams Computer Science in PDF only on Docsity!

Introduction to Algorithms and Complexity

Analysis

  1. Which property ensures an algorithm terminates after a finite number of steps? ⬜ Definiteness ⬜ Effectiveness ☑ Finiteness ⬜ Input
  2. What is the purpose of pseudocode? ⬜ Machine-executable code ☑ Human-readable algorithm description ⬜ Programming language ⬜ Debugging tool
  3. What is the time complexity of linear search on an unsorted list of n elements? ⬜ O(log n) ☑ O(n) ⬜ O(n^2) ⬜ O(1)
  4. Which searching algorithm requires the input list to be sorted? ☑ Binary search ⬜ Linear search ⬜ Depth first search ⬜ Breadth first search
  5. What is the best-case time complexity of binary search? ☑ O(1) ⬜ O(n)

⬜ O(log n) ⬜ O(n log n)

  1. Which sorting algorithm repeatedly swaps adjacent elements if they are in the wrong order? ☑ Bubble sort ⬜ Selection sort ⬜ Insertion sort ⬜ Merge sort
  2. What is the average-case time complexity of bubble sort? ⬜ O(n) ⬜ O(log n) ☑ O(n^2) ⬜ O(n log n)
  3. In selection sort, how is the next element chosen at each step? ⬜ Randomly ⬜ Maximum element ☑ Minimum element ⬜ Median element
  4. What is the time complexity of insertion sort in the worst case? ⬜ O(n log n) ⬜ O(n) ☑ O(n^2) ⬜ O(log n)
  5. Which sorting algorithm divides the list into sublists and conquers each recursively? ⬜ Bubble sort ⬜ Selection sort

☑ Divide and Conquer ⬜ Brute force

  1. Which algorithm design technique is based on solving smaller overlapping subproblems? ⬜ Divide and Conquer ⬜ Greedy ☑ Dynamic Programming ⬜ Backtracking
  2. What is the key difference between a greedy algorithm and dynamic programming? ⬜ Both pick globally optimal choices ⬜ Dynamic programming solves subproblems independently ☑ Dynamic programming solves overlapping subproblems carefully ⬜ Greedy always solves problems optimally
  3. Which algorithm finds the minimum spanning tree in a graph? ⬜ Dijkstra’s Algorithm ⬜ Floyd Warshall ☑ Kruskal’s Algorithm ⬜ Bellman-Ford
  4. What search strategy explores all neighbors of a node before moving deeper? ⬜ Depth First Search (DFS) ☑ Breadth First Search (BFS) ⬜ Binary Search ⬜ Linear Search
  5. The function f(n)=3n2+2n+1f(n) = 3n^2 + 2n + 1f(n)=3n2+2n+1 has a Big-O complexity of:

⬜ O(n) ⬜ O(1) ☑ O(n^2) ⬜ O(log n)

  1. Which of the following is NOT a characteristic of a good algorithm? ⬜ Finiteness ⬜ Definiteness ⬜ Effectiveness ☑ Ambiguity
  2. In a binary search algorithm, the input size reduces by what factor in each step? ⬜ 1/ ☑ 1/ ⬜ 1/ ⬜ 1/
  3. What does the term “stable sorting algorithm” mean? ⬜ Uses less memory ⬜ Runs in O(n) time ☑ Equal elements maintain relative order ⬜ Machine-specific sorting
  4. Which sorting algorithm is known for being stable? ⬜ Quick sort ⬜ Heap sort ☑ Bubble sort ⬜ Selection sort
  5. What does the following pseudocode do?

⬜ Combining results ⬜ Solving the problem directly ☑ Breaking the problem into smaller subproblems ⬜ Backtracking

  1. Which of the following searching algorithms is NOT suitable for linked lists? ☑ Binary search ⬜ Linear search ⬜ Depth first search ⬜ Breadth first search
  2. What is the output after binary search for key 7 in array ?testbook+ ☑ Index 3 ⬜ Index 1 ⬜ Index 4 ⬜ Not found
  3. Which step involves combining solutions of subproblems in divide and conquer? ⬜ Divide ⬜ Conquer ☑ Combine ⬜ Initialize
  4. What is the worst-case complexity of insertion sort? ⬜ O(log n) ⬜ O(n log n) ☑ O(n^2) ⬜ O(n)
  5. What property makes binary search efficient? ⬜ Unsorted list

⬜ Random access ☑ Sorted list ⬜ Linked list

  1. What is the key feature of a recursive algorithm? ⬜ Runs in constant time ⬜ Uses loops only ☑ Calls itself with smaller inputs ⬜ Does not terminate
  2. Which algorithm sorts an array by repeatedly selecting the smallest element and moving it to the front? ⬜ Bubble sort ☑ Selection sort ⬜ Merge sort ⬜ Quick sort
  3. What does the “Big-O” of O(1) mean? ⬜ Constant time ⬜ Linear time ⬜ Logarithmic time ⬜ Quadratic time
  4. Which of the following sorts is NOT comparison- based? ⬜ Quick sort ⬜ Merge sort ⬜ Heap sort ☑ Counting sort
  5. Which searching algorithm can be used on unsorted data? ☑ Linear search ⬜ Binary search

⬜ Breadth first search ⬜ Depth first search

  1. Which condition must hold true for binary search? ⬜ Array is unsorted ⬜ Array elements are unique ☑ Array is sorted ⬜ Array length is prime
  2. For a problem solved by dynamic programming, the recurrence relation represents: ⬜ All subproblems solved independently ⬜ Maximum subproblem size ☑ Relationship between problem and subproblems ⬜ Input size
  3. Which algorithm technique tries all possible solutions to find the correct solution? ⬜ Greedy ⬜ Dynamic Programming ⬜ Divide and Conquer ☑ Backtracking
  4. Which of the following sorts is fastest on average? ⬜ Bubble sort ⬜ Selection sort ☑ Quick sort ⬜ Insertion sort
  5. In algorithm analysis, what does “space complexity” refer to? ⬜ Time taken by algorithm ⬜ Size of input

☑ Extra memory needed during execution ⬜ Number of lines of code

  1. Which of these algorithms uses a priority queue? ⬜ BFS ⬜ DFS ☑ Dijkstra’s algorithm ⬜ Linear search