Docsity

COSC 350 Quiz 1: Data Structures and Algorithms - Prof. Joseph D. Sloan, Quizzes of Data Structures and Algorithms

Toggle sidebar
bg1
COSC 350 Page 1 of 4 2/2/2009
COSC 350: Quiz 1 Name _____________________
Through Section 4.2
1. (15 pts.) Which data structure, a stack, queue, or deque, would be the most
appropriate for each of the following?
a) Holding activation records for subroutine calls
b) A LILO data structure
c) Keeping track of partial paths that need to be searched with a breadth-first search
strategy
d) Simulating a deck of cards where cards are dealt from the top of the deck and all
returned cards are added to the bottom of the deck
e) Simulating a ticket-line at the theater where people either, a) arrive, enter the line,
see it is too long, and leave before anyone else arrives, or, b) arrive, enter the line,
and wait until it is their turn to buy a ticket leaving the line once the ticket is
bought
2. (6 pts.) Rewrite (a+b)*(c+d) – e in:
a) prefix notation
b) postfix notation
3. (6 pts.) Evaluate the following:
a) + * + 1 2 3 4 * 5
b) 1 2 3 4 * + * 5 +
pf3
pf4

Partial preview of the text

Download COSC 350 Quiz 1: Data Structures and Algorithms - Prof. Joseph D. Sloan and more Quizzes Data Structures and Algorithms in PDF only on Docsity!

COSC 350: Quiz 1 Name _____________________

Through Section 4.

  1. (15 pts.) Which data structure, a stack , queue , or deque , would be the most appropriate for each of the following? a) Holding activation records for subroutine calls b) A LILO data structure c) Keeping track of partial paths that need to be searched with a breadth-first search strategy d) Simulating a deck of cards where cards are dealt from the top of the deck and all returned cards are added to the bottom of the deck e) Simulating a ticket-line at the theater where people either, a) arrive, enter the line, see it is too long, and leave before anyone else arrives, or, b) arrive, enter the line, and wait until it is their turn to buy a ticket leaving the line once the ticket is bought
  2. (6 pts.) Rewrite (a+b)*(c+d) – e in: a) prefix notation b) postfix notation
  3. (6 pts.) Evaluate the following: a) + * + 1 2 3 4 * 5 b) 1 2 3 4 * + * 5 +
  1. (4 pts.) Use the base-conversion algorithm from the text to convert 11110 to base 7.
  2. (8 pts.) Rewrite the following code using a recursive function def myIndex(lst, item): at = 0 while not item == lst[at]: at = at + 1 return at
  3. (10 pts.) Write a recursive function to double each item on a list of numbers. For example, double[1,2,3,4,5] would return [2,4,6,8,10].
  1. In this problem you will develop an implementation for a Deque. a) (7 pts.) Give an ADT for a Deque. b) (14 pts.) Give a Python class definition for your ADT using Python’s built-in list data type. Pledged: ________________________________________________________________