Home
Subjects
Textbook solutions
Create
Study sets, textbooks, questions
Log in
Sign up
Upgrade to remove ads
Only $35.99/year
Science
Computer Science
Data Structures
CS261 - Data Structures - Midterm
STUDY
Flashcards
Learn
Write
Spell
Test
PLAY
Match
Gravity
Terms in this set (34)
Big O Notation
Used in computer science to describe the performance or complexity of an algorithm. Big-O specifically described the worst-case scenario, and can be used to describe the execution time required or the space used (e.g. in memory or on disk) by an algorithm.
O(1)
Constant complexity in Big O notation, the fastest
O(n!)
Factorial complexity in Big O notation, the slowest
Last
usable
time Complexity
O(n log n)
What to look for in O(1) complexity (3 things)
1. Does not include loops based on input size.
2. Is not recursive
3. does not call any functions which scale with input size
What to look for in O(log(n)) complexity (3 things)
1. Has a loop where the loop counter is divided by a constant
2. Moves markers that represent the start or end of a segment of a list so that the working list is divided by a constant at every step
3. Traverses once through a data structure that stores data in a branching hierarchy (like a binary tree)
What to look for in O(sqrt(n)) (fractional time) complexity (2 things)
1. Has a loop where the loop counts up to the square root of n
2. Each iteration takes O(1) time
What to look for in O(n) complexity (1 thing)
Contains a loop that does constant time work and is based directly on the input size.
What to look for in O(n*log(n)) (linearithmic time) complexity (3 things)
1. Has an outer loop that is based on n
2. Also has an inner loop or recursive call that follow the rules of O(log n) time complexity
3. Has an outer loop that is like an O(log n) function but then has an inner loop that loops on all the elements in the input
What to look for in O(n^2) (quadratic time) complexity (1 thing)
Has nested O(n) loops, assuming the code in the innermost loop runs in constant time
What to look for in O(2^n) (exponential time) complexity (1 thing)
A recursive call which decrements a count by a constant factor and calls itself more than once
General Rules for Determining Big O Complexity (4)
1. For loops: running time of the statements therein *
2. Nested loops: work inside out, figure out the inner loop and multiply by the outer loops.
3. Consecutive Statements - only count the maximum of them
4. if/else: time of the test plus the larger of the two alternatives.
Arrays two Basic Operations
Editing the value at a particular index
Reading the value at a particular index
Basic Differences between C array and Python List (4)
Arrays only store one type of data
Arrays basically only have two operations
The size of an array must be declared when it is created at compile time
The size of an array cannot be changed at run time
To Implement a Dynamic Array, what needs kept track of ? (3)
Data - the underlying data storage array
size - the number of elements currently stored in array
capacity - the total number of elements the underlying data storage array has space for (before it must be resized)
Main Advantage of Linked Lists
No need to resize like in dynamic array... elements may be added to the front or back in constant time.
Simple Linear Linked List Components (2)
Value - what is the node?
Next - What is the node pointing to next?
Doubly linked list difference versus singly linked
Also keeps track of previous value
Typical Linked List Operations (4)
1. Get by Value
2. Get by Index
3. Add
4. Remove
A Stack uses a "_ _ _ _" order
Last In First Out order
Typical Stack Operations (3)
1. Push - pushes item to top of stack
2. Pop - pops item off the top of stack and returns value.
3. Peek or top - Returns value of the top of the stack without removing it.
A Queue uses a "_ _ _ _" order
First In First Out order
Typical Queue Operations (2)
1. Enqueue - adds something to back of the queue
2. Dequeue - removes something from front of the queue and returns the value
What Time Should Stack Operations be Implemented in?
Constant Time O(1)
What Data Structures does a Binary Search Work in? Why?
Dynamic array or static Array
Data must be able to be randomly accessed
Iterator
Allows us to visit items in a collection one by one
(Quiz 2) What is the big-O execution time for the dynamic array internal method resize()?
O(n)
When resizing new array must be creating and old array must be copied over.
(Quiz 2) When do we need to increase the capacity of the underlying data storage array (i.e. data) in order to make space for the new element?
when size == capacity
(Quiz 2) True or False. The order in which elements are placed into the Bag ADT is important.
False, bag ADT is when insertion order is irrelevant
(Quiz 2) Which of the following provides best speed for a dynamic array?
Inserting and removing at the beginning
Inserting and removing at the end
Inserting and removing at any index
Inserting at end but removing at the beginning
Inserting and removing at the beginning
(Quiz 2) Suppose the size of the dynamic array is n, and we want to insert an element into the array. What is the maximum number of elements we have to move?
n, worst case we traverse the whole dynamic array
Dynamic Array Operations, Big O Time Complexity
Getting or setting the value at a particular index (___________)
Iterating over the elements in order (___________)
Inserting or removing an element in the middle of the array (___________)
Inserting or removing an element at the end of the array (____________)
O(1)
O(n)
O(n)
Amortized O(1)
ADT Definition
Abstract Data type (ADT) is a type (or class) for objects whose behavior is defined by a set of value and a set of operations.
(Quiz 1) Determine the big O complexity of the following function:
def example( n ):
count = 0
for i in range( n ) :
for j in range( 125 ) :
count += 1
return count
O(n), while the loop is nested, the second nested loop does not depend on the input (n), therefore it is O(n)
Sets with similar terms
Data Structures Exam I
169 terms
CS 066 Final Exam
77 terms
CRC CISP 400 C++ Quiz 4
66 terms
Data Structures
223 terms
Sets found in the same folder
CS261 - Module 4 - BST Trees
35 terms
CS261 - Module 5 - AVL Trees
15 terms
Final Exam Study Guide Web Dev 290
6 terms
CS261 - Module 5 - Heaps and PQueues
20 terms
Other sets by this creator
Technical Interview Terminology
16 terms
Algorithms CS325 - Final Exam Cumulative
50 terms
Algorithms Midterm thru Final CS325 OSU
38 terms
Algorithms CS325 - Cumulative Midterm Terms
24 terms