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

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

A quiz for cosc 350 students, covering topics on data structures (stacks, queues, deques) and recursion. It includes multiple-choice questions and programming exercises.

Typology: Quizzes

Pre 2010

Uploaded on 08/19/2009

koofers-user-ve6
koofers-user-ve6 🇺🇸

10 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
COSC 350 Page 1 of 4 9/22/2008
COSC 350: Quiz 2
Chapter 2 & 3 and Section 7.2
1. (10 pts.) Which data structure, a stack, queue, or deque, would be the most
appropriate for each of the following?
a) Simulating people waiting for service at a bank
b) A FIFO data structure
c) Keeping track of pending operations when implementing a recursive algorithm in
a non-recursive programming language
d) Checking to see if a string is a palindrome
e) Balancing tags in an HTML document
2. (8 pts.) Identify the notation used for the following expressions and then evaluate the
expression:
a) 3 4 7 * + 2 3 * +
b) * + 3 4 + 2 2
3. (6 pts.) Write
x
x
x3
12
1+
!
+
using the same notation that was used in problem 2a:
4. (4 pts.) How is adding an item to an ordered list different from adding an item to an
unordered list?
pf3
pf4

Partial preview of the text

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

COSC 350: Quiz 2

Chapter 2 & 3 and Section 7.

  1. (10 pts.) Which data structure, a stack , queue , or deque , would be the most appropriate for each of the following? a) Simulating people waiting for service at a bank b) A FIFO data structure c) Keeping track of pending operations when implementing a recursive algorithm in a non-recursive programming language d) Checking to see if a string is a palindrome e) Balancing tags in an HTML document
  2. (8 pts.) Identify the notation used for the following expressions and then evaluate the expression: a) 3 4 7 * + 2 3 * + b) * + 3 4 + 2 2
  3. (6 pts.) Write x x x 3 2 1

using the same notation that was used in problem 2 a :

  1. (4 pts.) How is adding an item to an ordered list different from adding an item to an unordered list?
  1. (6 pts.) A recursive function is a function that calls itself. What three rules must you keep in mind, as discussed in class, when implementing a recursive function?
  2. (6 pts.) Assume you are building a linked list as described in Section 7.2 of your text. Sketch a box-pointer diagram for the list with the items “spam”, “eggs”, and “grits” before and after the item “eggs” is removed.
  3. (12 pts.) Give Python code for a recursive function that uses repeated subtraction to find the remainder with integer division. That is, write your own version of the modulo function. For example, myMod(19, 5) would subtract 5 repeatedly until it got a number less than 5 and then would return that number, in this case 4. Is your function linear- or tree-recursive?
  1. (2 4 pts.) Give a Python implementation for an ADT for a stack using Python’s built-in list data type.