CPSC_1160_Practice_Final_Exam
.docx
keyboard_arrow_up
School
Langara College *
*We aren’t endorsed by this school
Course
1160
Subject
Computer Science
Date
Apr 3, 2024
Type
docx
Pages
2
Uploaded by BailiffWildcat2224
CPSC 1160 Algorithms and Data Structures I: Practice Final Exam
Part 1: Multiple Choice Questions
1.
Algorithm Complexity: What is the time complexity of a binary search algorithm in the worst case?
A) O(n)
B) O(log n)
C) O(n log n)
D) O(n^2)
2.
Data Structures: Which data structure uses LIFO (Last In, First Out) principle?
A) Queue
B) Stack
C) Linked List
D) Array
3.
C++ Syntax: Which of the following is the correct way to declare a dynamic array in C++?
A) int* arr = new int[10];
B) int arr[10];
C) int* arr = int[10];
D) int arr = new int[10];
Part 2: Short Answer Questions
4.
Recursion: Write a recursive function in C++ that calculates the factorial of a given number.
5.
Algorithm Analysis: Explain the difference between time complexity and space complexity in algorithms.
Part 3: Coding Problems
6.
Sorting Algorithm: Implement the Merge Sort algorithm in C++.
7.
Data Structure Implementation: Write a C++ program to implement a singly linked list with functions to add and delete nodes.
8.
Advanced Coding Problem: Write a C++ program that uses a recursive function to find all the combinations of a given string.
Part 4: Theory Questions
9.
Q1: Explain the concept of a binary tree and its applications.
10. Q2: Describe the process of memory management in C++ and the role of constructors and destructors.
Instructions for the Exam
Allocate time wisely to each section of the exam.
For coding problems, ensure that your code compiles and runs as expected.
Provide clear and concise answers for theory and short answer questions.
Check your work for errors before submitting the exam.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Related Questions
1. Calculate BIG-O for the following code segment:
while(n>1){
n=n/2;
}
2. Name the TYPE of algorithm used to traverse a binary tree.
3. Name the components of a recursive algorithm.
arrow_forward
Computer science question 1
arrow_forward
As compared to alternative data structures like a linked list or an array, the advantages of a binary search tree become immediately obvious.
arrow_forward
programming language.
> DynamicList
+capacity : int //initialized to 10
+ add(int index, Object o): boolean
+ remove(int index): boolean
B2. Determine how many times the output statement is displayed
in each of the following fragments. Whether the algorithm is
O(n) or O(n²).
a) for (int i=0; i
arrow_forward
Data structure
arrow_forward
The best data structures in terms of asymptotic time complexities for performing the following operations respectively are
CONCATENATION (A, B): Concatenate all elements of A and B together
Insert(T, key): Insert key to T
Delete (T, key): Delete key from T if present
Search (T, key): Returns true if key is present in T
Stack, Binary Search Tree, Sorted Array, Linked List
Linked List, Stack, Binary Search Tree, Sorted Array
Linked List, Stack, Sorted Array, Binary Search Tree
Stack, Linked List, Sorted Array, Binary Search Tree
arrow_forward
Circular Lists
A linear list is being maintained circularly in an array c[0…n-1] with front, and rear set up as for circular queues.
a)Calculate the time complexity of your algorithms for b) and c).
b)Write an algorithm to delete the k-th element in the list.
c)Write an algorithm to insert an element y immediately after the k-th element.
arrow_forward
Q 10
Please explain your answers
arrow_forward
SEE MORE QUESTIONS
Recommended textbooks for you
Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning
Related Questions
- 1. Calculate BIG-O for the following code segment: while(n>1){ n=n/2; } 2. Name the TYPE of algorithm used to traverse a binary tree. 3. Name the components of a recursive algorithm.arrow_forwardComputer science question 1arrow_forwardAs compared to alternative data structures like a linked list or an array, the advantages of a binary search tree become immediately obvious.arrow_forward
- programming language. > DynamicList +capacity : int //initialized to 10 + add(int index, Object o): boolean + remove(int index): boolean B2. Determine how many times the output statement is displayed in each of the following fragments. Whether the algorithm is O(n) or O(n²). a) for (int i=0; iarrow_forwardData structurearrow_forwardThe best data structures in terms of asymptotic time complexities for performing the following operations respectively are CONCATENATION (A, B): Concatenate all elements of A and B together Insert(T, key): Insert key to T Delete (T, key): Delete key from T if present Search (T, key): Returns true if key is present in T Stack, Binary Search Tree, Sorted Array, Linked List Linked List, Stack, Binary Search Tree, Sorted Array Linked List, Stack, Sorted Array, Binary Search Tree Stack, Linked List, Sorted Array, Binary Search Treearrow_forwardCircular Lists A linear list is being maintained circularly in an array c[0…n-1] with front, and rear set up as for circular queues. a)Calculate the time complexity of your algorithms for b) and c). b)Write an algorithm to delete the k-th element in the list. c)Write an algorithm to insert an element y immediately after the k-th element.arrow_forwardQ 10 Please explain your answersarrow_forwardarrow_back_iosarrow_forward_ios
Recommended textbooks for you
- Systems ArchitectureComputer ScienceISBN:9781305080195Author:Stephen D. BurdPublisher:Cengage Learning
Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning