100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Exam (elaborations)

Foundations of Algorithms Exam Questions and Correct Answers Latest Update 2024 (Graded A+)

Rating
-
Sold
-
Pages
10
Grade
A+
Uploaded on
06-12-2024
Written in
2024/2025

Foundations of Algorithms Exam Questions and Correct Answers Latest Update 2024 (Graded A+) What is Quick Sort? - Answers divide-and-conquer sorting algorithm that sorts elements by selecting a "pivot" and partitioning the array into elements less than and greater than the pivot. What is the average time complexity of Quick Sort for random input? - Answers O(n log n) QS What is the worst-case time complexity of Quick Sort for random input? - Answers O(n^2) QS What is the best-case time complexity of Quick Sort for random input? - Answers O(n log n) QS How does Quick Sort choose a pivot? - Answers various ways: first element, last element, random element What are the steps of the Quick Sort algorithm? - Answers Choose a pivot. Partition the array into elements less than and greater than the pivot. Recursively apply Quick Sort to the subarrays. partitioning process in Quick Sort - Answers Recursion in Quick Sort allows the algorithm to sort the smaller subarrays created by the partitioning process until the base case (array of size 0 or 1) is reached. common use case for Quick Sort - Answers sorting large datasets due to its average-case efficiency and good cache performance. Three functions required for quicksort - Answers swap, partition and quicksort Insertion Sort - Answers sorting algorithm that builds a sorted array one element at a time by inserting elements from the unsorted portion into the correct position in the sorted portion. best-case time complexity of Insertion Sort - Answers O(n) (when the array is already sorted). IS average and worst-case time complexity of Insertion Sort - Answers O(n²) (for random order and reverse order respectively) IS basic steps of Insertion Sort - Answers Start from the second element. Compare it with elements in the sorted portion (to its left). Shift larger elements to the right. Insert the current element in its correct position. Repeat until the array is sorted. some common use cases for Insertion Sort - Answers Efficient for small data sets and as a part of more complex algorithms like Hybrid Sorts. Merge Sort - Answers divide-and-conquer sorting algorithm that recursively splits an array into halves, sorts each half, and merges the sorted halves back together. time complexity of Merge Sort - Answers O(nlogn) basic steps of Merge Sort. - Answers Divide the array into two halves. Recursively sort each half. Merge the sorted halves back into a single sorted array. some common use cases for Merge Sort - Answers Suitable for large datasets, external sorting (when data doesn't fit in memory), and linked lists How is Merge Sort different from Quick Sort - Answers Merge Sort consistently runs in O(n log n) time, while Quick Sort can degrade to O(n²) in the worst case. Merge Sort uses extra space; Quick Sort sorts in place. How does mergesort go? - Answers Divides arrays into subarrays and works backwards, merging it all back together Heap - Answers specialized tree-based data structure that satisfies the heap property, either as a max-heap or a min-heap. max-heap - Answers complete binary tree where each node's value is greater than or equal to its children's values. min-heap - Answers complete binary tree where each node's value is less than or equal to its children's values. How are heaps typically implemented? - Answers using arrays, where for a node at index iii, its left child is at 2i+1 and right child is at 2i+2 time complexity for inserting an element into a heap - Answers O(log n), due to the need to maintain the heap property after insertion. time complexity to build a heap from an array - Answers O(n) primary use of heaps in algorithms - Answers min-heap = priority queues max-heap = heapsort difference between a binary heap and a binary search tree (BST) - Answers binary heap maintains a specific ordering based on parent-child relationships, while a BST maintains order based on in-order traversal properties. Heap-sort - Answers comparison-based sorting algorithm that uses a binary heap data structure to sort elements time complexity of Heap Sort - Answers O(nlogn) HS What are the main steps of Heap Sort? - Answers Build a max-heap from the input array. Extract the maximum element from the heap and place it at the end of the array. Re-heapify the remaining elements. Repeat until all elements are sorted. How do you build a max-heap - Answers Start from the last non-leaf node and call heapify on each node, moving up to the root. common use cases for Heap Sort - Answers scenarios where memory space is limited or when you need guaranteed O(nlog⁡n)O(n log n)O(nlogn) performance. What are the left & right values for heapify - Answers 2i + 1 for right, 2i for left Binary Search - Answers Used for sorted arrays & liiosts, repeated divides search space in half to find target Best time complexity of Binary Search - Answers O(1) Worst time complexity of Binary Search - Answers O(nlogn) Steps of Binary Search - Answers 1) Set pointers at start & end of array 2) find the middle ((low + high) / 2) 3) Compare with target If arr[mid] > target in binary search, what would you do? - Answers high = mid + 1 Linear Search - Answers checks each element in list sequentially until target value is found or reaches end Best Time complexity linear search - Answers O(1) Worst Time Complexity Linear Search - Answers O(n) Steps of Linear Search - Answers 1) Start from first element 2) Compare curr value to target value 3) if curr == target, return index 4) if not, continue

Show more Read less
Institution
Foundations Of Algorithms
Course
Foundations of Algorithms









Whoops! We can’t load your doc right now. Try again or contact support.

Written for

Institution
Foundations of Algorithms
Course
Foundations of Algorithms

Document information

Uploaded on
December 6, 2024
Number of pages
10
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

Content preview

Foundations of Algorithms Exam Questions and Correct Answers Latest Update 2024 (Graded A+)



What is Quick Sort? - Answers divide-and-conquer sorting algorithm that sorts elements by selecting a
"pivot" and partitioning the array into elements less than and greater than the pivot.

What is the average time complexity of Quick Sort for random input? - Answers O(n log n) QS

What is the worst-case time complexity of Quick Sort for random input? - Answers O(n^2) QS

What is the best-case time complexity of Quick Sort for random input? - Answers O(n log n) QS

How does Quick Sort choose a pivot? - Answers various ways: first element, last element, random
element

What are the steps of the Quick Sort algorithm? - Answers Choose a pivot.

Partition the array into elements less than and greater than the pivot.

Recursively apply Quick Sort to the subarrays.

partitioning process in Quick Sort - Answers Recursion in Quick Sort allows the algorithm to sort the
smaller subarrays created by the partitioning process until the base case (array of size 0 or 1) is reached.

common use case for Quick Sort - Answers sorting large datasets due to its average-case efficiency and
good cache performance.

Three functions required for quicksort - Answers swap, partition and quicksort

Insertion Sort - Answers sorting algorithm that builds a sorted array one element at a time by inserting
elements from the unsorted portion into the correct position in the sorted portion.

best-case time complexity of Insertion Sort - Answers O(n) (when the array is already sorted). IS

average and worst-case time complexity of Insertion Sort - Answers O(n²) (for random order and reverse
order respectively) IS

basic steps of Insertion Sort - Answers Start from the second element.

Compare it with elements in the sorted portion (to its left).

Shift larger elements to the right.

Insert the current element in its correct position.

Repeat until the array is sorted.

, some common use cases for Insertion Sort - Answers Efficient for small data sets and as a part of more
complex algorithms like Hybrid Sorts.

Merge Sort - Answers divide-and-conquer sorting algorithm that recursively splits an array into halves,
sorts each half, and merges the sorted halves back together.

time complexity of Merge Sort - Answers O(nlogn)

basic steps of Merge Sort. - Answers Divide the array into two halves.

Recursively sort each half.

Merge the sorted halves back into a single sorted array.

some common use cases for Merge Sort - Answers Suitable for large datasets, external sorting (when
data doesn't fit in memory), and linked lists

How is Merge Sort different from Quick Sort - Answers Merge Sort consistently runs in O(n log n) time,
while Quick Sort can degrade to O(n²) in the worst case. Merge Sort uses extra space; Quick Sort sorts in
place.

How does mergesort go? - Answers Divides arrays into subarrays and works backwards, merging it all
back together

Heap - Answers specialized tree-based data structure that satisfies the heap property, either as a max-
heap or a min-heap.

max-heap - Answers complete binary tree where each node's value is greater than or equal to its
children's values.

min-heap - Answers complete binary tree where each node's value is less than or equal to its children's
values.

How are heaps typically implemented? - Answers using arrays, where for a node at index iii, its left child
is at 2i+1 and right child is at 2i+2

time complexity for inserting an element into a heap - Answers O(log n), due to the need to maintain the
heap property after insertion.

time complexity to build a heap from an array - Answers O(n)

primary use of heaps in algorithms - Answers min-heap = priority queues

max-heap = heapsort

difference between a binary heap and a binary search tree (BST) - Answers binary heap maintains a
specific ordering based on parent-child relationships, while a BST maintains order based on in-order
traversal properties.

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
TutorJosh Chamberlain College Of Nursing
View profile
Follow You need to be logged in order to follow users or courses
Sold
332
Member since
1 year
Number of followers
16
Documents
28211
Last sold
1 day ago
Tutor Joshua

Here You will find all Documents and Package Deals Offered By Tutor Joshua.

3.6

53 reviews

5
18
4
14
3
12
2
0
1
9

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions