Data Structures 2 Flashcards
Explain the binary search algorithm.
An iterative algorithm by which a sorted list can be searched. The iteration consists of choosing the midpoint between the first and last item on the list, comparing that item to the item being searched for, and then establishing a new list to be searched once the item is decided to be in front of or behind the midpoint item.
What are the three big ideas that we will be learning about in the Data Structures course?
- Organizing data properly helps build efficient solutions to problems.2. Types of data structures and ideas about them. 3. Abstraction is a key tool.
Definition: Abstraction
The considering of something as a general quality or characteristic instead of a specific instance.
What is an ADT?
An ADT, or abstract data type, is a description of an object (or set of objects) together with a set of operations that can be performed on the object.
What two operations are associated with a basic integer counter ADT?
Increment and get value (initialization is implicit in the definition of the ADT).
What is a stack and what are its operations?
A stack is an ADT that is a type of list. The only part of the list that is accessibly by the user is the top of the list. Its operations include: pop, which deletes top element; top, which returns the top element; and push, which puts a new element on the top of the list.
Definition: activation record
The record of information saved while a method call is performed in the registers. Its purpose is to make sure there is no overwriting of information that is needed in the calling routine. The paper is put on the top of the stack of other papers of other calling routines that might be open.
What does CPU stand for?
Central Processing Unit. Or, in other words the processor.
What is a primitive type and how is it designated?
It is a data type that has a certain amount of memory set aside for it, and it is those memory cells that hold the actual object. Whenever it is then called by the program, the actual entity is looked up. It is designated by a lower case type, e.g. int, double.
What is an object type and how is it designated?
An object type is a data type that has a pointer in memory that points to where the actual memory that stores the object is located. Whenever the object is referenced, it goes through this pointer first. You can create multiple pointers to one object without constructing any new objects.
What does overloading refer to?
Overloading a class indicates that there are multiple constructors that are in the class.
What are helper methods and how are they designated?
Helper methods are methods within a class that are only called by other methods in the class and that aren’t available fore the user to use. They are labeled as private.
What is an orphan?
It is an object in memory that is no longer reachable by the program because all pointers to it have been deleted or changed to reference another object. Orphans and other extraneous data is periodically and systematically erased by the computer.
What is the stack?
A special place inside memory that stores temporary variables created in each function. Once the function running exits, any information it stored on the stack is freed (deleted). The computer manages the stack memory for you, and you can access anything on the stack quickly, but there is a size limit to what you put there.
What is the heap and what is a risk associated with using it too much?
The heap is a larger area in memory that, in C, you manage and organize yourself with the functions malloc(), calloc(), and free() to allocate and deallocate space in the heap. If you fail to deallocate memory when you’re not using it any more, you may get a memory leak, which means some data stored in the heap is set aside and cannot be accessed any longer. However, data in the heap is not deleted when a function is exited.
What is an interface and what is a benefit to using one?
An interface specifies and lists the variables and methods that a class must implement. A benefit of using interfaces is that they can be used to simulate multiple inheritance.
Does the main method always have to be inside a class in Java?
Yes.
What does the extends keyword do in Java?
Extends is used after a subclass declaration to refer to a different superclass that it is inheriting.
What does DOS stand for? What is MS-DOS?
Disk Operating System. Sometimes used as shorthand for MS-DOS (Microsoft Disk Operating System), which is the standard operating system for IBM PC (IBM Personal Computer).
What are the defining properties of a queue ADT?
A queue ADT is a line of objects. Objects are pushed in at one end of the queue and popped at the other end. It is a last in, last out data structure.
What are the defining properties of a deque ADT?
A deque is a data structure that is like a line of objects, like a queue, but that can push and pop objects at both ends of the line.
What are the defining properties of a bag ADT?
A bag is (usually) a collection of one type of object, and it is unordered and unindexed, and you can access any object in the bag if you know for which instance you are looking.
What are two reasons you might want to use an explicit iterator instead of a for each loop?
If you want to use the remove method of the iterator interface, or if you don’t want to iterate through all of the elements of the collection.
Algorithmic efficiency of selection sort? When does it happen?
O(n^2) worst case is when it is backwards sorted and you have to visit every element each time to find the smallest one
Algorithmic efficiency of insertion sort? When does it happen?
O(n^2) happens when it is already sorted and you have to visit every item in new array to find next element’s place
Algorithmic efficiency of bubble sort? When does it happen?
O(n^2) worst case is when you have to go through n passes of the algorithm, that is, there is at least one swap every run
Algorithmic efficiency of mergesort?
O(NlogN) levels of recursion: log N, then how much work to merge each level? have to look at every item in each level: N.
Algorithmic efficiency of quicksort?
O(N^2) at worst, expected to be O(NlogN)
What is one pass of quick sort?
Choose median of three pivot (what the median is of the set of the first element, middle element, & last element), swap it with whatever is at the end of the array. Then approach from either end until you find two elements that are out of place with respect to the pivot, swap them. Repeat until you meet in the middle, then put pivot back quicksort the two sets to left and right of original pivot.
What are the defining properties of a valid minimum binary heap?
Each parent has a smaller priority value than its child, and it is a complete binary tree, which means every level is filled all the way except for possibly the last, which is only filled from left to right.
How do you perform an insert in a binary heap PQ?
Put it in at the first empty spot in the tree, then bubble it up as far as it needs to go.
How do you perform a remove in a binary heap PQ?
Take out the root, replace it with the last (lowest priority) item and allow this item to bubble down however far it needs to go.