0% found this document useful (0 votes)
15 views11 pages

Final Exam Data Structure

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)
15 views11 pages

Final Exam Data Structure

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/ 11

First Semester

DATA STRUCTURES AND ALGORITHMS


Final Exam
2022-2023
Name: _______________________ Course & Year: _____________ Date: _______Score: ___

Test I: Direction: Read each statement carefully. Select the correct letter that best suits your
answer by shading the corresponding circle on the answer sheet provided.

1. Entries in a stack are "ordered." What is the meaning of this statement?


A. A collection of Stacks can be sorted.
B. Stack entries may be compared with the '<' operation.
C. The entries must be stored in a linked list.
D. There is a first entry, a second entry, and so on.

2. The operation for adding an entry to a stack is traditionally called:


A. add
B. append
C. insert
D. push

3. The operation for removing an entry from a stack is traditionally called:


A. delete
B. peek
C. pop
D. remove

4. Which of the following stack operations could result in stack underflow?


A. is_empty
B. pop
C. push
D. Two or more of the above answers

5. Which of the following applications may use a stack?


A. A parentheses balancing program
B. Keeping track of local variables at runtime
C. Syntax analyzer for a compiler
D. All of the above

6. Consider the following pseudocode:

declare a stack of characters


while (there are more characters in the word to read)
{
read a character
push the character on the stack
}
while (the stack is not empty)
{
pop a character off the stack
write the character to the screen
}
What is written to the screen for the input "carpets"?
A. serc
B. carpets
C. steprac
D. ccaarrppeettss

7. Here is an INCORRECT pseudocode for the algorithm which is supposed to determine whether a
sequence of parentheses is balanced:

declare a character stack


while (more input is available)
{
read a character
if (the character is a '(')
push it on the stack
else if (the character is a ')' and the stack is not empty)
pop a character off the stack
else
print "unbalanced" and exit
}
print "balanced"

Which of these unbalanced sequences does the above code think is balanced?
A. ((())
B. ())(())
C. (()()))
D. (()))()

8. Consider the usual algorithm for determining whether a sequence of parentheses is balanced. What is
the maximum number of parentheses that will appear on the stack at any one time when the algorithm
analyzes: (()(())(()))?
A. 1
B. 2
C. 3
D. 4
E. 5 or more

9. Consider the usual algorithm for determining whether a sequence of parentheses is balanced. Suppose
that you run the algorithm on a sequence that contains 2 left parentheses and 3 right parentheses (in some
order). What is the maximum number of parentheses that will ever appear on the stack at one time during
the computation?
A. 1
B. 2
C. 3
D. 4
E. 5 or more

10. Suppose we have an array implementation of the stack class, with ten items in the stack stored at
data[0] through data[9]. The CAPACITY is 42. Where does the push method place the new entry
in the array?
A. data[0]
B. data[1]
C. data[9]
D. data[10]

11. Consider the implementation of the Stack using a partially-filled array. What goes wrong if we try to
store the top of the Stack at location [0] and the bottom of the Stack at the last used position of the
array?
A. Both peek and pop would require linear time.
B. Both push and pop would require linear time.
C. The Stack could not be used to check balanced parentheses.
D. The Stack could not be used to evaluate postfix expressions.

12. In the linked list implementation of the stack class, where does the push method place the new entry
on the linked list?
A. At the head
B. At the tail
C. After all other entries that are greater than the new entry
D. After all other entries that are smaller than the new entry

13. In the array version of the Stack class, which operations require linear time for their worst-case
behavior?
A. is_empty
B. peek
C. pop
D. push when the stack is below capacity
E. None of these operations require linear time.

14. In the linked-list version of the Stack class, which operations require linear time for their worst-case
behavior?
A. is_empty
B. peek
C. pop
D. push
E. None of these operations require linear time.

15. What is the value of the postfix expression 6 3 2 4 + - *?


A. Something between -15 and -100
B. Something between -5 and -15
C. Something between 5 and -5
D. Something between 5 and 15
E. Something between 15 and 100

16. Here is an infix expression: 4 + 3 * (6 * 3 - 12). Suppose that we are using the usual Stack
algorithm to convert the expression from infix to postfix notation. What is the maximum number of
symbols that will appear on the stack at one time during the conversion of this expression?
A. 1
B. 2
C. 3
D. 4
E. 5

17. One difference between a queue and a stack is:


A. Queues require linked lists, but stacks do not.
B. Stacks require linked lists, but queues do not.
C. Queues use two ends of the structure; stacks use only one.
D. Stacks use two ends of the structure, queues use only one.

18. If the characters 'D', 'C', 'B', 'A' are placed in a queue (in that order) and then removed one at a time, in
what order will they be removed?
A. ABCD
B. ABDC
C. DCAB
D. DCBA

19. Which of the following expressions evaluates to true with approximate probability equal to P? (P is a
double and 0≤P≤10 \leq P \leq 10≤P≤1).
A. Math.random() < P
B. Math.random() > P
C. Math.random() < P * 100
D. Math.random() > P * 100

20. Suppose we have a circular array implementation of the queue class, with ten items in the queue
stored at data[2] through data[11]. The current capacity is 42. Where does the insert method place
the new entry in the array?
A. data[1]
B. data[2]
C. data[11]
D. data[12]

21. Consider the implementation of the Queue using a circular array. What goes wrong if we try to keep
all the items at the front of a partially-filled array (so that data[0] is always the front)?
A. The constructor would require linear time.
B. The getFront method would require linear time.
C. The insert method would require linear time.
D. The isEmpty method would require linear time.

22. In the linked list implementation of the queue class, where does the insert method place the new entry
on the linked list?
A. At the head
B. At the tail
C. After all other entries that are greater than the new entry
D. After all other entries that are smaller than the new entry

23. In the circular array version of the Queue class, which operations require linear time for their worst-
case behavior?
A. getFront
B. insert when the capacity has not yet been reached
C. isEmpty
D. None of these operations require linear time.

24. In the linked-list version of the Queue class, which operations require linear time for their worst-case
behavior?
A. getFront
B. insert
C. isEmpty
D. None of these operations require linear time.
25. If data is a circular array of CAPACITY elements, and rear is an index into that array, what is the
formula for the index after rear?
A. (rear % 1) + CAPACITY
B. rear % (1 + CAPACITY)
C. (rear + 1) % CAPACITY
D. rear + (1 % CAPACITY)

26. I have implemented the queue with a circular array, keeping track of front, rear, and
manyItems (the number of items in the array). Suppose front is zero, and rear is one less than the
current capacity. What can you tell me about manyItems?
A. manyItems must be zero.
B. manyItems must be equal to the current capacity.
C. manyItems could be zero or the capacity, but no other values could occur.
D. None of the above.

27. I have implemented the queue with a linked list, keeping track of a front node and a rear node
with two reference variables. Which of these reference variables will change during an insertion into a
NONEMPTY queue?
A. Neither changes
B. Only front changes
C. Only rear changes
D. Both change

28. I have implemented the queue with a linked list, keeping track of a front node and a rear node
with two reference variables. Which of these reference variables will change during an insertion into an
EMPTY queue?
A. Neither changes
B. Only front changes
C. Only rear changes
D. Both change

29. Suppose getFront is called on a priority queue that has exactly two entries with equal priority.
How is the return value of getFront selected?
A. One is chosen at random.
B. The one which was inserted first.
C. The one which was inserted most recently.
D. This can never happen (violates the precondition).

30. An array of queues can be used to implement a priority queue, with each possible priority
corresponding to its own element in the array. When is this implementation not feasible?
A. When the number of possible priorities is huge.
B. When the number of possible priorities is small.
C. When the queues are implemented using a linked list.
D. When the queues are implemented with circular arrays.

31. Suppose that a binary taxonomy tree includes 8 animals. What is the minimum number of NONLEAF
nodes in the tree?
A. 1
B. 3
C. 5
D. 7
E. 8
32. There is a tree in the box at the top of this section. What is the order of nodes visited using a pre-order
traversal?
A. 1 2 3 7 10 11 14 30 40
B. 1 2 3 14 7 10 11 40 30
C. 1 3 2 7 10 40 30 11 14
D. 14 2 1 3 11 10 7 30 40

33. There is a tree in the box at the top of this section. What is the order of nodes visited using an in-order
traversal?
A. 1 2 3 7 10 11 14 30 40
B. 1 2 3 14 7 10 11 40 30
C. 1 3 2 7 10 40 30 11 14
D. 14 2 1 3 11 10 7 30 40

34. There is a tree in the box at the top of this section. What is the order of nodes visited using a post-
order traversal?
A. 1 2 3 7 10 11 14 30 40
B. 1 2 3 14 7 10 11 40 30
C. 1 3 2 7 10 40 30 11 14
D. 14 2 1 3 11 10 7 30 40

35. Consider this binary search tree:

14
/ \
2 16
/ \
1 5
/
4

Suppose we remove the root, replacing it with something from the left subtree. What will be the new
root?
A. 1
B. 2
C. 4
D. 5
E. 16

Test II Direction: Read and understand the set of sentences in each given number. Choose the correct
letter of the correct answer.

a. Both statements are true


b. Both statements are false
c. First statement is true but the second statement is false
d. First statement is false but the second is true

36. 1. Bubble Sort is an adaptive sorting algorithm


2. Bubble Sort is a stable sorting algorithm

37. 1. Hashing is a technique used to map data of arbitrary size to fixed-size values, usually for fast data
retrieval.
2. Interpolation search is an efficient search algorithm for uniformly distributed data.
38. 1. Binary search can only be applied to sorted arrays or lists.
2. In most programming languages, the names of processing items can contain letters, numbers,
underscores, punctuation, characters and spaces.

39. 1. Linear search is the most efficient algorithm for searching in all cases.
2. Linear search can only be applied to arrays and not to linked lists.

40. 1. A Stack Follows the first-In-First-Out principle


2. Stack can only be implemented using arrays and not linked lists.

41. 1. Linear interpolation always passes through the known data points.
2. Interpolation methods are always stable and accurate regardless of the distribution of data points

41. 1. Linear interpolation always passes through the known data points.
2. Interpolation methods are always stable and accurate regardless of the
distribution of data
points. C
42. 1. In a queue, elements can be accessed and removed from any position, not
just the front
2. Queue is often used in the First-In-First-out search algorithm. D

43. 1. Binary search can be applied to unsorted datasets and still maintain its
efficiency. D
2. The length of an array is determined by the number of elements it can contai

41. 1. Linear interpolation always passes through the known data points.
2. Interpolation methods are always stable and accurate regardless of the distribution of data points.

42. 1. In a queue, elements can be accessed and removed from any position, not just the front
2. Queue is often used in the First-In-First-out search algorithm.

43. 1. Binary search can be applied to unsorted datasets and still maintain its efficiency.
2. The length of an array is determined by the number of elements it can contain.

44. 1. Enqueue operation in a queue adds an element to the rear of the queue.
2. Dequeue operation in a queue can be performed from any position within the queue.

45. 1. Stacks are often used in implementing function calls and recursion in programming
2. A stack allows access to elements in the middle without popping the entire stack.

46. 1. Quick Sort is an example of a Divide and Conquer algorithm.


2. Merge Sort is not a stable sorting algorithm.

47. 1. A linked list can grow dynamically without requiring a pre-defined size.
2. A doubly linked list can be traversed only in one direction.

48. 1. A binary tree is a tree where each node can have at most three children.
2. In a complete binary tree, every level, except possibly the last, is completely filled.

49. 1. Depth-first search uses a stack data structure for its implementation.
2. Breadth-first search uses a stack instead of a queue for its implementation.
50. 1. A hash table is a data structure that supports constant-time complexity for search, insert, and delete
operations in the average case.
2. Hash collisions in hash tables can be resolved using techniques like chaining and open addressing.
Answer Key

1. D. There is a first entry, a second entry, and so on.

2. D. push

3. C. pop

4. B. pop

5. D. All of the above

6. C. steprac

7. A. ((())

8. D. 4

9. C. 3

10. D. data[10]

11. B. Both push and pop would require linear time.

12. A. At the head

13. E. None of these operations require linear time.

14. E. None of these operations require linear time.

15. C. Something between 5 and -5

16. D. 4

17. C. Queues use two ends of the structure; stacks use only one.

18. A. ABCD

19. A. Math.random() < P

20. D. data[12]

21. C. The insert method would require linear time.

22. B. At the tail

23. D. None of these operations require linear time.

24. E. None of these operations require linear time.

25. C. (rear + 1) % CAPACITY

26. C. manyItems could be zero or the capacity, but no other values could occur.

27. C. Only rear changes

28. D. Both change

29. A. One is chosen at random.

30. A. When the number of possible priorities is huge.

31. B. 3

32. A. 1 2 3 7 10 11 14 30 40

33. A. 1 2 3 7 10 11 14 30 40

34. C. 1 3 2 7 10 40 30 11 14
35. B. 2

36. A

37. A

38. A

39. B

40. B

41. C

42. D

43. D

44. C

45. C

46. C

47. C

48. D

49. C

50. A

You might also like