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

CS 302 midterm UPDATED Exam Questions and CORRECT Answers

Rating
-
Sold
-
Pages
0
Grade
A+
Uploaded on
29-04-2025
Written in
2024/2025

CS 302 midterm UPDATED Exam Questions and CORRECT Answers In the context of data structures, why would using a language with the Standard Template Library (STL) be advantageous? - CORRECT ANSWER - Suppose I wanted to implement a sequence container by using an linked list using a single pointer (e.g., front). What would be the complexity in terms of Big-O for the following operations: - Locate an element based on its value - Insert an element in the front - Insert an element in the back - CORRECT ANSWER insert front = O(1) insert back = O(n) - locate = O(n

Show more Read less
Institution
CS302
Course
CS302









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

Written for

Institution
CS302
Course
CS302

Document information

Uploaded on
April 29, 2025
Number of pages
Unknown
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

Content preview

CS 302 midterm UPDATED Exam Questions
and CORRECT Answers
In the context of data structures, why would using a language with the Standard Template
Library (STL) be advantageous? - CORRECT ANSWER -


Suppose I wanted to implement a sequence container by using an linked list using a single
pointer (e.g., front). What would be the complexity in terms of Big-O for the following
operations:
- Locate an element based on its value
- Insert an element in the front

- Insert an element in the back - CORRECT ANSWER - locate = O(n)
insert front = O(1)
insert back = O(n)


Describe one operation where a doubly linked list would have a better time complexity when
compared to the same operation applied on a more "generic" singly linked list? - CORRECT
ANSWER - adding, removing, accessing data is all O(1) compared to O(n) for singly
linked lists


Trace the execution of insertion sort for an array containing {9, 6, 0, 0, 7}, i.e., show the contents
of the array after each iteration of the sorting algorithm. - CORRECT ANSWER - Initial
Array:
[9, 6, 0, 0, 7]


Iteration 1:
Compare 6 with 9
[6, 9, 0, 0, 7]


Iteration 2:
Compare 0 with 9

, Compare 0 with 6
[0, 6, 9, 0, 7]


Iteration 3:
Compare 0 with 9
Compare 0 with 6
Compare 0 with 0 (first 0) and shift the first 0 to the right.
[0, 0, 6, 9, 7]


Iteration 4:
Compare 7 with 9
Compare 7 with 6
[0, 0, 6, 7, 9]


Final Sorted Array:
[0, 0, 6, 7, 9]


quick sort is another, but more complicated example, of a divide and conquer algorithm. Explain
what happens during the partitioning phase of the algorithm and why the choice of a pivot is
important for efficiency. If it helps, think of the best and worse case pivots and how they affect
the big-Oh of this sorting method. - CORRECT ANSWER -


merge sort is the prototypical example of a divide and conquer algorithm. In your own words,
explain what happens during the divide portion of the algorithm and what happens during the
conquer phase of merge sort. Finally, in your own words why is this an O(n log n) algorithm? -
CORRECT ANSWER - in the divide phase, the array is recursively split into subarrays
until each contains 1 element. conquer mergers the subarrays recursively while maintaining the
sorted order of the elements. The time complexity is log(n) for division and O(n) during merge,
so the overall time complexity is O(n log n)

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.
MGRADES Stanford University
View profile
Follow You need to be logged in order to follow users or courses
Sold
1071
Member since
1 year
Number of followers
102
Documents
68976
Last sold
18 hours ago
MGRADES (Stanford Top Brains)

Welcome to MGRADES Exams, practices and Study materials Just think of me as the plug you will refer to your friends Me and my team will always make sure you get the best value from the exams markets. I offer the best study and exam materials for a wide range of courses and units. Make your study sessions more efficient and effective. Dive in and discover all you need to excel in your academic journey!

3.8

170 reviews

5
73
4
30
3
45
2
8
1
14

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