0% found this document useful (0 votes)
6 views3 pages

Khadijah Assignment

The document contains a series of questions and answers related to algorithms and data structures for a CPS317 assignment. Key topics include shortest path algorithms, sorting techniques, time complexities, and data structure operations. Notable answers include Dijkstra’s algorithm for shortest paths and O(1) time complexity for inserting into a LinkedList.

Uploaded by

frw8k4ny6w
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)
6 views3 pages

Khadijah Assignment

The document contains a series of questions and answers related to algorithms and data structures for a CPS317 assignment. Key topics include shortest path algorithms, sorting techniques, time complexities, and data structure operations. Notable answers include Dijkstra’s algorithm for shortest paths and O(1) time complexity for inserting into a LinkedList.

Uploaded by

frw8k4ny6w
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/ 3

AHMED KHADIJAH ABIDEMI.

S122202023

CUAB 2024/2025 CPS317 ASSIGNMENT.

1. Which of the following algorithms are used to find the shortest path from a source node to all
other nodes in a weighted graph?

A. Djikstra’s algorithm

B. BFS

C. PRIMS

D. Krushkal's Algorithm

Answer: A- Djikstra’s algorithm.

2. What is the maximum number of swaps that can be performed in the Selection Sort algorithm?

A. n-1

B. n

C. 1

D. n-2

Answer: A- n-1.

3. What is the technique called in which it does not require extra memory for carrying out the
sorting procedure?

A. Stable

B. Unstable

C. In-place

D. In-partition

Answer: C- In-place.

4. What is the time complexity of the binary search algorithm?

A. O(n)

B. O(1)

C. O(log2n)

D. O(logn2)
Answer: C- O(log2n)

5. What is the time complexity of the following code snippet in C++?


void solve() {
string s = "scaler";
int n = s.size();
for(int i = 0; i < n; i++) {
s = s + s[i];
}
cout << s << endl;
}
A. O(n)

B. O(n2)

C. O(1)

D. O(login)

Answer: B- O(n2)

6. What is the time complexity to insert an element to the front of a LinkedList(head pointer
given)?

A. O(n)

B. O(1)

C. O(logn)

D. O(nlogn)

Answer: B- O(1)

7. What should be considered when designing an algorithm?

A. If the software is used correctly

B. If the hardware is used correctly

C. If there is more than one way to solve the problem

D. All of the above are correct

Answer: D- All of the above are correct

9. When a pop() operation is called on an empty queue, what is the condition called?

A. Overflow

B. Underflow

C. Syntax error
D. Garbage value

Answer: B- Underflow

10. Which of the following data structure is used to perform recursion?

A. Linked list

B. Array

C. Queue

D. Stack

Answer: D- Stack.

You might also like