Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Dimensional Array - Data Structures - Solved Exam, Exams of Data Structures and Algorithms

Main points of this past exam are: Dimensional Array, Image Processing, Computer Vision, Dynamic Data, Code Fragment, Function Definition, Function Prototype

Typology: Exams

2012/2013

Uploaded on 04/07/2013

seshu_lin3
seshu_lin3 🇮🇳

4

(3)

59 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 308 Data Structures
Spring 2003 - Dr. George Bebis
Midterm
Duration: 1:00 - 2:15 pm
Name:
1. True/False (5 pts each) To get credit, you must give brief reasons for your answers !!
(1.1) TFAn objective way to compare two algorithms is by comparing their execution (i.e.,
machine) times.
(1.2) TFThe running time of InsertItem (unsorted lists) is O(N)
(1.3) TFSuppose Ais declared as int A[5];. If the base address of the array is 100 and integers
take up 4 bytes, the address of A[2] is 110.
(1.4) TFGiven the declaration int x=5, *ptr; then the statement *ptr = &x; in main() will cause
an error.
(1.5) TFImage processing and computer vision is the same thing.
pf3
pf4
pf5

Partial preview of the text

Download Dimensional Array - Data Structures - Solved Exam and more Exams Data Structures and Algorithms in PDF only on Docsity!

CS 308 Data Structures

Spring 2003 - Dr. George Bebis

Midterm

Duration: 1:00 - 2:15 pm

Name:

  1. True/False (5 pts each) To get credit, you must give brief reasons for your answers !!

(1.1) T F An objective way to compare two algorithms is by comparing their execution (i.e., machine) times.

(1.2) T F The running time of InsertItem (unsorted lists) is O(N)

(1.3) T F Suppose A is declared as int A[5];. If the base address of the array is 100 and integers take up 4 bytes, the address of A[2] is 110.

(1.4) T F Given the declaration int x=5, *ptr; then the statement *ptr = &x; in main() will cause an error.

(1.5) T F Image processing and computer vision is the same thing.

  1. Multiple choice (5 pts each)

(2.1) The order of adding 1 to each element in a one dimensional array of N integers.

(a) O (1) (b) O( logN ) (c) O ( N ) (d) O ( NlogN ) (e) O ( N^2 )

(2.2) Which of the following C++ class member functions should be provided if class objects point to dynamic data?

(a) a destructor (b) a constructor (c) a copy-constructor (d) a and b above (e) a, b, and c above

(2.3) To use the template construct, you must put which of the following expressions before the class definition?

(a) class template (b) <template, class, ItemType> (c) template (d) <template >

(2.4) Given the function definition

void Twist(int& a, int b) { int c;

c = a + 2; a = a * 3; b = c + a; }

what is the output of the following code fragment that invokes Twist?

r = 1; s = 2; t = 3; Twist(t, s); cout << r << ’ ’ << s << ’ ’ << t << endl;

(3.3) Demonstrate the binary search algorithm on the list (array-based) shown below. The ele- ment to be retrieved is 10 ( Note: I do not want the code).

6

5

4

3

2

1

0

31

44

54

96

30

220

101

6

5

4

3

2

1

0

31

44

54

96

30

220

101

6

5

4

3

2

1

0

31

44

54

96

30

220

101

6

5

4

3

2

1

0

31

44

54

96

30

220

101

6

5

4

3

2

1

0

31

44

54

96

30

220

101

INIT ITER 1 ITER 2 ITER 3 ITER 4

(3.4) In programming assignment 1, you implemented an algorithm to compute the negative of an image. Describe in simple words how this algorithm works. What is its complexity using big- O notation? Justify your answer.

(3.5) Is the linked-list implementation of a queue always more efficient (in terms of memory) than the array-based implementation? Why or why not?

  1. Code (15 pts) Implement a client function called copyStack that copies the contents of one stack into another. The function must have two arguments of type StackType, one for the source stack and one for the destination stack. The order of the elements in the two stacks must be iden- tical. The specification of StackType is given below (please note that no copy constructor is pro- vided).

template class StackType { public: StackType(); ˜StackType(); void MakeEmpty(); bool IsEmpty() const; bool IsFull() const; void Push(ItemType); void Pop(ItemType&); private: NodeType* topPtr; };