



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Main points of this past exam are: Much Memory, Linear Search, Function Receives, Color Images, Memory Compared, List of Elements, Dynamic Array
Typology: Exams
1 / 7
This page cannot be seen from the preview
Don't miss anything!
Duration: 1:00 - 2:15 pm
Name:
(1.1) T F Binary search is always faster than linear search.
(1.2) T F When an array is passed to a function, the function receives a copy of the array (call by value).
(1.3) T F Changes in the implementation of a class should not require changes in an application that uses the class.
(1.4) T F The running time of RetrieveItem (sorted lists) is O(N)
(1.5) T F An objective way to compare two algorithms is by comparing their execution (i.e., machine) times.
(1.6) T F Color images take up twice as much memory compared to gray-level images.
(1.7) T F An O ( logN ) algorithm is slower than an O ( N ) algorithm.
(1.8) T F The most appropriate structure to print a list of elements in reverse order is the Queue.
(1.9) T F The parameter to a copy constructor must be passed by reference.
(1.10) T F The running time of the program fragment shown below is O ( N )
sum = 0; for(i=0; i<N; i++) { if(i > j) sum = sum + 1; else { for(k=0; k<N; k++) sum = sum - 1; } }
(2.3) Give the C++ statements for the dynamic allocation of an array with 3 rows and 5 columns. Draw a diagram that shows the structure of the dynamic array in memory.
(2.4) In programming assignment 1, you implemented a function that takes an image and shrinks it by a given factor. Describe in simple words how the shrink function works (no code). Assuming N x N images, give the running time of the function in terms of N , using big-O notation. Justify your answer.
(2.5) What are the differences between "call by value" and "call by reference"?
(2.6) Demonstrate the binary search algorithm on the list (array-based) shown below. The element we want to retrieve is 55 (note that I am not asking you to write down the code; just include some figures that show the values of first , last and mid indices at each itera- tion).
6
5
4
3
2
1
0^12
31
44
54
96
100
200
MergeLists(SortedType list1, SortedType list2, SortedType& result)
Function: Merges two sorted lists into one sorted list. Precondition: list1 and list2 have been initialized. Postconditions: result is a sorted list that contains all of the items from list1 and list (no duplicates)