Have a question?
Message sent Close

CS 2150 Final Master Study Guide

Sandra Watson
1 student enrolled
0 reviews
  • Description
  • Full Document

Master Study Guide CS 2150

Program and Data Representation (CS 2150)

Differences of References and Pointers
● Pointers: stores a memory address of another object, can be a primitive type or a class
type every address bit is 32 bits long
○ * pointer will point to the pointee (the value that you want/need), the pointer is
○ pointers need to be initialized to NULL so that there is not a runtime error
○ anytime the new is not used the compiler will de-allocate it for you, other words
be sure to explicitly delete your “new’s”
● References: a memory address that keeps track of a “thing”
○ Created like pointer but with &
■ Address cannot change
■ Must be initialized upon declaration
■ Has implicit dereferencing
○ Static vs dynamic memory allocation
■ Static – know at compile time how much memory is used, so compiler
puts in assembly opcodes to allocate that much memory on the stack
■ Dynamic does not
○ New returns a pointer to newly created “thing”
○ Why were references put into C++ when there were already pointers?
■ References are better for parameter passing and return types
○ Dereferencing is implied with each use – you can assign a reference to an int
with references because it automatically assumes that you are talking about the
thing that it is pointing to
● Why are references not useful as variables inside subroutines?
● How can a pointer cause a seg fault but not a reference?
○ A pointer can cause a seg fault if it is a dangling pointer or if where it’s pointing
to gets messed up but since a reference doesn’t point and it is automatically
assumed where it’s pointing…it won’t cause that seg fault
■ this answer gets real questionable towards the end
● What happens when you use the new keyword for a pointer?
○ Returns a pointer to a newly created “thing”
● Can you call delete on this pointer?
○ As long as the object in question was dynamically allocated.

Other Questions

● What method does C++ automatically provide

● What is a memory hole?

● Functions

● What is the purpose of the destructor?

● What is the purpose of overloading the operator = () method?

● How is this different from the copy constructor?

● What does the friend keyword do in C++

● Why does the C++ compiler have such a hard time determining errors with template code?

● What is Abstract Data Types

■ Why use an iterator?

● Why do we like big Theta over big Oh and big Omega?

● Three reasons why you would not want to use trees as a data structure

● Describe the splay() algorithm used in splay trees

● Traversal – left child will always be printed out before the right child

● Why are red-black trees faster than AVL trees?

● What is the best way to handle deletes in a hash table?

● Why are linked lists always used for the separate chaining buckets over a more efficient data structure such as a balanced binary tree?

● Why did we bother learning IBCM in this course?

● What is the purpose of cache in the memory hierarchy?

● While loops in IBCM

● What is the difference between C++ references and pointers at assembly level?

● What could prevent buffer overflow attacks?

● When might you not push ebp onto the stack as an activation record?

● Three different types of optimizations that that can be made in assembly:

● What are the 6 things the x86 calling convention places on the stack in order

● Why are parameters passed in reverse order?

● By convention, what registers can be modified by either the callee or the caller?

● Where does the return value go after a subroutine is called?

● What are the rules for addressing memory?

● Why does C++ use a different naming convention than C?

● Why can you not access memory twice in a single instruction?

● Code that has the same effect as push and pop

● What are all the parts in an activation record?

● What are all the steps in a callers prologue? epilogue? callee’s prologue? callee’s epilogue?

● Write a C++ function that returns the 13th bit of a passed int parameter.

● When don’t we want to use trees?

Questions for Final

● Convert -35.5 to 32-bit IEEE 754 floating point notation, and put your answer in littleEndian.

● Why did we insist that you program in Linux this semester?

● Write the minimum value, in both hex and decimal (i.e., base-10), of a signed 32-bit
integer (you can leave the decimal value as a formula). Do the same for the maximum
value (both in hex and decimal/formula).S 2150 final exam, fall 2014

● Why do we prefer to use big-Theta instead of big-Oh?

● For the three primary operations of a hash table (insert, delete, and find), give their bigTheta running time and briefly explain why.

● Explain the removal algorithm for a value from a binary search tree.

● List three problems that can occur with multiple inheritance – specifically, problems that
do not occur with single inheritance.

● List three new features of C++.

● Other than syntax, list the three differences between references and pointers.

● Briefly, what is the difference between a priority queue and a binary heap?

● Why introduce references in C++ when it already had pointers

● For an unweighted graph, we can either use Dijkstra’s algorithm to find the shortest path,
or breadth-first search. Which is faster? Why?

● Write an x86 subroutine that operates the same as the following C++ subroutine:

● Write a C++ code snippet (not a full program) that will cause a segmentation fault.

● List three assembly-level optimizations that g++ makes when compiling (and optimizing)
code into assembly:

● We’ve talked about the vector class throughout the semester. What would the fields of such a class be?

● Consider a priority queue implemented with data structures other than a binary heap.List three such data structures, and the associated big-Theta run time for each of the three primary priority queue operations.

● Briefly define the structure and ordering properties for a binary min-heap.

● Why is the expected running time for insert into a min-heap constant?

● Why would we want to create a method template in C++?

● Briefly describe what the #ifndef / #define / #endif pre-processor commands do, and briefly explain how they work.

● Briefly describe exactly how a vector’s running time for insert() amortizes to Θ(1), even though some operations will be linear.

● Why does C++ treat array base names as constant pointers?

● Briefly describe the difference between shared multiple inheritance and replicated
multiple inheritance.

● Briefly describe how the C++ compiler implements dynamic dispatch in the programs it

● Briefly describe three new features of C++

● Briefly, what is the difference between a priority queue and a binary heap?

● Why is the running time of findMin() for a min-heap ALWAYS constant?

● While the running time of a binary heap’s insert() method is Θ(log n), the expected
running time is constant. Briefly, why?

● What are the three types of shortest path algorithms for a map?

● Give three reasons why we store a heap as an array rather than dynamically allocated
heap nodes (AKA why use array over pointers).

○ List the steps in the C calling convention’s caller prologue.

○ List the steps in the C calling convention’s callee prologue.

○ List the steps in the C calling convention’s caller epilogue.

○ List the steps in the C calling convention’s callee epilogue.




CS 2150 Final Master Study Guide


NOTE: Please check the details before purchasing the document.