CptS 122 – Data Structures                                                                                                                

 

Exam 1 Review Guide

 

This document will serve as a guide to help you prepare for the first midterm exam in CptS 122. You will find information about the exam format and topics you are expected to review within this guide.

 

What to Bring?


Your WSU ID


Two sharp pencils


Calculators and notes can not be used during the exam!


  

Exam Timeframe

 

Please be aware that, because you will be taking the exam during a normal lecture period, time will be extremely tight for the exam. You will be allowed to start the exam at 12:10 pm sharp. If you show up late to class, you will have less time to take the exam. You must hand your exam in by 1:00 pm. sharp. Note that, when you hand in your exam, you will be required to present your WSU ID.

 

Exam Format

 

Expect the exam to look like an hour version of quizzes, with a few more involved problems that are more in the spirit of a lab exercise. The exam will consist of some concepts questions and programming problems. For the concept section of the exam, expect true-false, fill-in-the-blank, and/or short-answer questions similar to those found on the quizzes. Some of these may be similar to the questions found at the end of chapters in your textbook! For the programming problem section of the exam, I will present you with programming problems, and you will be expected to write syntactically-correct C code solutions that exercise good design. Note that your solutions do not have to be documented!

 

Exam Coverage

 

The exam covers the first six weeks of the semester, chapter 5 (Functions), chapter 7 (Pointers), chapter 8 (Characters & Strings) and chapter 12 (Data Structures) of the Deitel and Deitel C How to Program textbook.

 

Chapter 12: C Data Structures

o      For ADT think: “specification”; for data structure think: “implementation”

o      Nodes for linked lists, stacks, queues, and binary search trees (BSTs) require self-referential structures

 

o      isEmpty ( ) - returns an integer or enumerated Boolean type; true for an empty list, false for non-empty list

o       insertAtFront ( ) – allocates a node dynamically; initializes it to the data passed in; inserts the node at the front of the list only; returns true or false for successful or unsuccessful insertion, respectively

o       insertAtBack ( ) - allocates a node dynamically; initializes it to the data passed in; inserts the node at the back or end of the list only; returns true or false for successful or unsuccessful insertion, respectively

o       insertInOrder ( ) - allocates a node dynamically; initializes it to the data passed in; inserts the node in the list in ascending or descending order only; returns true or false for successful or unsuccessful insertion, respectively

o       deleteNode ( ) – de-allocates a node dynamically; returns true if node was de-allocated, false otherwise

o       printList ( ) – prints out the data in each node of the list; may be printed iteratively or recursively

 

o      isEmpty ( ) - returns an integer or enumerated Boolean type; true for an empty stack, false for non-empty stack

o       push ( ) - allocates a node dynamically; initializes it to the data passed in; inserts the node at the top of the stack only; returns true or false for successful or unsuccessful insertion, respectively

o       pop ( ) - de-allocates a node at the top of the stack dynamically; returns true if node was de-allocated, false otherwise; NOTE: some variations of pop ( ) will return the data in the node found at the top of the stack, instead of true or false

o       top ( ) or peek ( ) – returns the data found in the top node of the stack; nodes are not affected (removed)

o       printStack ( ) - prints out the data in each node of the stack; may be printed iteratively or recursively

 

o       isEmpty ( ) - returns an integer or enumerated Boolean type; true for an empty queue, false for non-empty queue

o       enqueue ( ) - allocates a node dynamically; initializes it to the data passed in; inserts the node at the tail/back of the queue only; returns true or false for successful or unsuccessful insertion, respectively

o       dequeue ( ) - de-allocates a node at the head/front of the queue dynamically; returns the data in the node found at the head/front of the queue; NOTE: some implementations may also return true or false for successful or unsuccessful removal of a node from the head/front

o       printQueue ( ) - prints out the data in each node of the queue; may be printed iteratively or recursively

 

o       How to define a treeNode

§         A treeNode has data and two pointers to treeNodes – these pointers keep track of left and right subtrees

o       How nodes are inserted into a BST

§         Based on values – if value of new node is less than current node it’s placed to left;  otherwise it’s placed to right; duplicated may or may not be added to the tree

o       By nature items in BST are organized

o       makeNode ( ) – allocates a node dynamically; initializes the node; returns a pointer to the dynamic node

o       For example:

§         Converting infix expression to postfix expressions (stack)

§         Keeping tack of print jobs (queue)

§         Storing personal contact information (list)

o       Think: lost pointer to dynamically allocated memory; can’t access the memory anymore, but memory has is still allocated by system

o       We check to see if lists are empty inside our corresponding removal functions

§         Some implementations add preconditions to deleteNode ( ), pop ( ), and dequeue ( ) stating structure is not empty

 

Other Topics

1.     A char * needs to point to some allocated memory; this memory may be allocated dynamically or via another automatic local variable

2.     A str[] has memory associated with it; str refers to the address of the 0th element in the array

3.     A char *str[] is an array of pointers; where each pointer could refer to dynamically allocated memory or automatic local variable memory

4.     A str[][] may be considered an array of strings or a 2-D array of characters; all required memory is allocated upfront; str[] (one index specified) refers to the start of the corresponding row

 

Recommended Strategy for Preparing for the Exam

 

    I recommend that you use the following activities and materials to prepare for the exam:

    1. Review quizzes and lab exercises: These may well be your best resource. An excellent learning activity would be to retake the quizzes and review

       the lab exercises.

   2. Lecture slides and example code: Study the lecture slides and example code.

   3. Read the textbook: Read or re-read chapter 12 (Data Structures) in your textbook.