Midterm Exam Questions - Data Structures - Spring 2008 | CSCI, Exams of Data Structures and Algorithms

Material Type: Exam; Class: DATA STRUCTURES; Subject: Computer Science; University: Indiana University - Bloomington; Term: Spring 2008;

Typology: Exams

2013/2014

Uploaded on 05/07/2014

mdegges
mdegges 🇺🇸

4

(3)

14 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Spring 2008 C343 Midterm Name:
1. a) (5 points) Give an advantage that an array has over a linked list.
b) (5 points) Give an advantage that a linked list has over an array.
2. a) (10 points) Find reasonable constants c, n0to show that 2n+nlog10(10n)O(log10 n). Show your
work.
b) (10 points) Consider the following ”proof” that
n
!
i=1
3nO(n)
n
!
i=1
3n=3n+3n+... +3n
=O(n)+O(n)+... +O(n)
Given two functions that are each O(n), their sum is also O(n). Therefore, the claim is true.
What is wrong with this argument?
1
pf3
pf4

Partial preview of the text

Download Midterm Exam Questions - Data Structures - Spring 2008 | CSCI and more Exams Data Structures and Algorithms in PDF only on Docsity!

Spring 2008 C343 Midterm Name:

  1. a) (5 points) Give an advantage that an array has over a linked list. b) (5 points) Give an advantage that a linked list has over an array.
  2. a) (10 points) Find reasonable constants c, n 0 to show that 2n + n log 10 (10n) ∈ O(log 10 n). Show your work. b) (10 points) Consider the following ”proof” that ∑^ n i= 3 n ∈ O(n) ∑^ n i= 3 n = 3n + 3n + ... + 3n = O(n) + O(n) + ... + O(n) Given two functions that are each O(n), their sum is also O(n). Therefore, the claim is true. What is wrong with this argument?
  1. a) (10 points) Prove the following identity. Do not use induction. ∑^ n i= ai^ = 1 − an+ 1 − a ∀ a $= 1 b) (5 points) Why is the above identity not true when a = 1?
  2. (10 points) Suppose we would like to write an iterator for a binary tree which iterates over the nodes of the tree. Explain briefly how a stack might be used to do this. It is not necessary to write any code; instead, focus on describing the algorithm. Remember, an iterator must support the next() and hasNext() methods.
  1. (5 points) Suppose you are given two dictionary implementations, one which uses a binary search tree and one which uses a linked list. Explain why the binary search tree implementation will allow faster searches than the linked list implementation will.
  2. (20 points) Write a Java implementation of the Queue interface which is based on a pair of stacks. Make it as efficient as possible. You do not need to implement the stack. public interface Stack { public void push(T item); public T pop(); public T peek(); public boolean isEmpty(); } public class ArrayStack implements Stack {...} public interface Queue { public void enqueue(T item); public T dequeue(); public boolean isEmpty(); }