Introduction to Computer Science

Quiz 5 Study Guide

This page contains a list of things you should know before taking Quiz 5. If you have any questions as to the correct answers to any of these questions, please let me know.

Files

Recent labs have made thorough use of files. You should know how to open and close a file, how to retrieve its contents, and how to work with strings.

Exercises

Write the following Python functions. Attempt to do so without the aid of a computer whenever possible.

Searching

We spent a week discussing the process of searching through a list in class. You should know linear and binary search algorithms and be able to write them as Python code. You should be able to explain the advantages and disadvantages of each. You should understand these algorithms well enough to debug them.

Exercises

Answer the following questions.

Write the following Python functions. Attempt to do so without the aid of a computer whenever possible.

Sorting

We spent a week discussing the process of sorting a list of values. Lab 08 required you to sort a data file. You should know at least the Selection Sort and Bubble Sort algorithms and be able to write them as Python code. (Ideally, you should also understand Insertion Sort.) You should understand these algorithms well enough to debug them.

Exercises

Complete the following tasks.

def swap(lst,i,j):
  temp = lst[i]
  lst[j] = lst[i]
  lst[i] = lst[j]

def bubble(lst):
  for i in range(len(lst)-1):
    if lst[i] < lst[i+1]:
    swap(lst,i,i+1)
    
def bubble_sort(lst):
  for i in range(len(lst)):
    bubble(lst)