CS1037A 2010 Midterm Practice Questions
Part 1. Multiple choice questions.
1. [1 mark] The following C+ code is best described as a.
void counting_sort(int* items, int count);
a)
b)
c)
d)
e)
function declaration
global member function
function
function de
Computer Science 1037a Midterm Examination
26 October 2011
2 hours
Student Number:
Surname:
Given name:
Instructions/Notes: The examination has 14 pages and a total of 100 marks, and
consists of two parts.
Part 1 is Multiple Choice and True/False, and con
Computer Science 1037a Midterm Examination
26 October 2011
2 hours
Student Number:
Surname:
Given name:
Instructions/Notes: The examination has 14 pages and a total of 100 marks, and
consists of two parts.
Part 1 is Multiple Choice and True/False, and con
Asymptotic Complexity
(Big-O Notation)
CS 1037
Fundamentals of Computer Science II
What is a Fast Algorithm?
Takes the fewest seconds? Takes the fewest steps?
Best
case
Small
problems
Large
problems
Average
case
P
P
Worst
case
P
P
In practice, these matte
Generic Programming
(C+ Templates)
CS 1037
Fundamentals of Computer Science II
Generic Programming
Most code written w.r.t. specific type
void swap(double& a, double& b) cfw_
double temp = a;
a = b;
b = temp;
Generic is opposite of specific!
void swap(
Graphs &
Graph Search Algorithms
CS 1037
Fundamentals of Computer Science II
Graph Abstraction
A set V=cfw_v1,.,vn of nodes, and
A set E=cfw_e1,.,em of edges where each
edge ek=(vi,vj) is connects vi to vj
e1
v1 e
2
e3
v3
v2 e
4
e5
e6
v4
v5
v6
2
Graph C
Part 1. Multiple choice questions.
Circle your answers on this paper, and fill them in on the Scantron form.
1. [1 mark] In programming, dynarray is the best list structure when
a)
b)
c)
d)
e)
you need to access items in non-sequential order
you need to a
Dynamic Array Objects
CS 1037
Fundamentals of Computer Science II
A Smarter Dynamic Array
Built-in dynamic array new[] very limited
manual insert/erase/resize is hard
must remember each arrays size in separate variable
must remember to delete[] each a
Binary Trees
CS 1037
Fundamentals of Computer Science II
What is a Tree?
A tree is a graph with no cycles
two trees (a forest)
a tree
not a tree
A rooted tree is a tree with one node r
designated the root
r
Choice of root defines
ancestry relationships
Constructors, Destructors,
Operator Overloading
CS 1037
Fundamentals of Computer Science II
Some Special Functions.
A. Constructors (to set up an objects state)
Destructors (to tear down an object)
struct sound cfw_
int
size;
double* samples;
sound();
/ c
Linked Lists
CS 1037
Fundamentals of Computer Science II
You Will Learn.
A. Singly Linked List data structure
linkedlist<double> x;
x.push_front(3.1416);
x.push_front(2.1718);
B. Iterators (and inner classes in C+)
for (linkedlist<double>:iterator i = x.b
Searching & Sorting
CS 1037
Fundamentals of Computer Science II
You Will Learn.
A. Binary Search algorithm
int data[5] = cfw_ 1, 3, 4, 7, 9 ;
int index = binary_search(data,5,7); / index = 3
B. Iterative Sorting algorithms
int data[5] = cfw_ 4, 9, 1, 3, 7
Structs, References, Classes
CS 1037
Fundamentals of Computer Science II
You Will Learn.
A. Structs and why theyre useful
struct point cfw_
int x, y;
;
/ now 'point' is a type, like int
B. Pass-by-reference in C+
/ a global function
void shift_by(point& p
Stacks & Queues
CS 1037
Fundamentals of Computer Science II
Stack Data Structure
Three main operations
1. push(x) inserts item to top of stack
2. pop() erases item at top of stack
3. top() returns item at top of stack
stack<string> names;
names.push("Mik
Review: Pointers & Arrays,
Heap & Call Stack
CS 1037
Fundamentals of Computer Science II
Pointers & Arrays are Crucial
Needed to process and manage data
Appear everywhere in real C+ code
Real Life example: amplify volume effect from Audacity project
boo
Computer Science 1037a Midterm Examination
26 October 2009
2 hours
Student Number:
Surname:
Given name:
Instructions/Notes: The examination has 12 pages and a total of 100 marks, and consists of two parts.
Part 1 is Multiple Choice and True/False, and con
Computer Science 1037a Midterm Examination
25 October 2012
2 hours
Student Number:
Surname:
Given name:
Instructions/Notes: The examination has 14 pages and a total of 100 marks, and consists of two parts.
Part 1 is Multiple Choice and True/False, and con