Final Exam Review - University of California, Santa Cruzsbrandt/13H/slides/Final... ·  ·...

15
Final Exam Review

Transcript of Final Exam Review - University of California, Santa Cruzsbrandt/13H/slides/Final... ·  ·...

Final Exam Review

Final Exam Review 2CMPS 12B, UC Santa Cruz

About this exam review

I’ve prepared an outline of the material covered in class

May not be totally complete!Exam may ask about things that were covered in class but not in this review sessionI can’t cover a ten week class in one hour!

Lacks detail

This is an interactive reviewThis review is for your benefit!If you have questions, ask themIf you don’t understand something, say so

Final Exam Review 3CMPS 12B, UC Santa Cruz

What will the exam format be like?

Multiple ChoiceNot necessarily easy

Programming questionsWrite this code (very brief)What does this code do?Where is the bug in this code?

Explain this algorithmShow how this algorithm worksHow long does this take?How could you do this better?

What is this concept?Differentiate from other conceptsExplain the concept

Questions similar to those on sample exams

Final Exam Review 4CMPS 12B, UC Santa Cruz

What material will be covered?

Final exam will be 200 pointsSome multiple choiceSome short answerThere will be 1–2 bonus questions200 points means a bit less than 1 minute per point…

Topics on the final exam may includeThe bookConcepts covered in classProgramming assignments

Algorithms usedTools used (only the required ones)

Java programming languages (Not C)

Final Exam Review 5CMPS 12B, UC Santa Cruz

Java Programming

What is an algorithm?Software Life Cycle

Problem AnalysisDesignImplementationTestModification

FundamentalsLexical elementsCommentsKeywordsIdentifiersLiteralsOperators and punctuationData Types and Variables

MethodsCalling and passing parameters

Numeric Typesbyte, short, char, int, long, float, double

Arithmetic ExpressionsOperatorsPrecedence and associativity

Statements and ExpressionsEmpty, block, Boolean expression, relational operators, comparisons

Final Exam Review 6CMPS 12B, UC Santa Cruz

Java Programming (cont.)

Conditional Statementsifif-elseswitch

case

whileforbreak and continue

Structured ProgrammingTop-down designMethod definitionpublic static void main(String[] args)returnScope of variablesRecursion

ArraysDeclaringUsingInitializingCopying1D, 2D, 3D, …

Data AbstractionClasses define typesEncapsulationData hidingpublic vs. privateConstructorsstatic vs. not staticPassing objects: referencesfinal

Final Exam Review 7CMPS 12B, UC Santa Cruz

O (n2) sorting algorithms

General conceptsUnderstanding sortingO(n2) sorts often have

Two nested loopsSimple code

Insertion sortFor each element in the unsorted set, put it in the right place in the sorted setOuter loop is over elements in the unsorted setCan be fast if elements are near their “correct” position

Selection sortFor each position in the sorted set, find the appropriate element in the unsorted setOuter loop is over positions in the sorted set

Bubble sortLoop through set exchanging adjacent elementsRepeat until set is sorted (no exchanges take place)May be fast if set is nearly sorted to begin with

Final Exam Review 8CMPS 12B, UC Santa Cruz

Divide & conquer sorting algorithms O(nlogn)

MergesortDivide array in half

Copy into new arraySort each half recursivelyMerge the two halves into the original array

Performance isO(n log n)Uses lots of memory:O(n2 log n)

AdvantagesNo worst case performanceEasy to write

DisadvantagesMemory usage

QuicksortPick a pivot elementDivide array into two halves: less than pivot and greater than or equal to pivotRecursively sort each half

Performance isUsually O(n log n)Worst case O(n2)

Prevent this by picking pivot intelligentlyPick median of 3–5 randomly chosen elements

AdvantagesSort in place (no extra array)Easy to code

Final Exam Review 9CMPS 12B, UC Santa Cruz

Non-tree Data Structures and Concepts

Linked listsSingly linked listsDoubly linked listsOperations on linked lists

InsertLookupDelete

Keeping linked lists orderedRunning time

Stacks

Queues Linear SearchBinary search

How it worksHow long it takes

Final Exam Review 10CMPS 12B, UC Santa Cruz

Exceptions

Occur when something “unusual” occursMust have a way to signal calling procedureCan’t always use return value to do thisUse an exception (in Java)

Possibility declared with “throws”Exception generated by

Creating an Exception objectingUsing a “throw” statement

Exception caught by “try … catch” statementExceptions don’t exist in C

Instead, return “illegal” valueNot always possible…

Final Exam Review 11CMPS 12B, UC Santa Cruz

Binary trees

Representing binary treesNode structureStoring data in trees

Operations on binary treesInsertionLookupDeletion

Describing binary treesSizeDepthFull binary treesBalanced binary trees

Traversing binary treesPre-orderIn-orderPost-order

Binary trees and filesWriting trees to filesReading trees from files

Using binary treesBinary search treesHuffman decoding (Assignment #4)

Running time of binary tree operations

Insertion: O (log n)Lookup: O (log n)Deletion: O (log n)

Final Exam Review 12CMPS 12B, UC Santa Cruz

Trees

Binary Search TreesSorted order

Balanced Trees2-3 Trees2-3-4 TreesRed-Black TreesAVL Trees

Final Exam Review 13CMPS 12B, UC Santa Cruz

Hash Tables

Hash functionsOperations

InsertLookupDelete

MetricsHow full?

Collision resolutionChainingRehashing

Running time

Final Exam Review 14CMPS 12B, UC Santa Cruz

C programming language

Understand the difference between C and JavaReferences vs. pointersGarbage collection vs. freeing memory explicitlyClasses (object oriented) vs. declarative

Understand how C programs are structuredHeader filesReferences to external functions

Understand C syntax and conceptsPointersArraysStructures

Final Exam Review 15CMPS 12B, UC Santa Cruz

How should I prepare for this exam?

Understand the concepts we’ve covered in classDon’t memorize

You should be able to rederive a result without memorizing the answerUnderstanding concepts will (hopefully) prevent answers that areobviously wrong

Focus on understanding the how and why

Know how to use Java well, understand CDifficult things like objects (Java), pointers & arrays (C)Understand syntax

On the examDo the questions you know first: they may take less time than the points would indicateMake educated guesses if necessary