Data Structure and Algorithm

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Topics Covered: Queue : FIFO data structure.

First-In
First-Out. A collection design for
1. Basic Data Structures
holding elements prior processing
2. Big O Notation linear data structure.
3. Searching algorithms
add = enqueue, offer()
4. Sorting algorithms
5. Graphs remove = dequeue, poll()
6. Trees
Where are queues useful?
Data Structure : a named location 1. Keyboard Buffer (letters should appear
on the screen in the order they're pressed)
that can be used to store and
organize data. 2. Printer Queue (Print jobs should be
completed in order)
3. Used in LinkedLists, PriorityQueues,
Algorithm : a collection of steps Breadth-first search

to solve a problem.
Priority Queue : a FIFO data
structure that serves elements
stack : a LIFO data structure. Last- with the highest priorities first
In First-Out stores objects into a before elements with lower
sort of “vertical tower” priority.
push() to add to the top.
pop() to remove from the top. LinkedList : stores Nodes in 2
parts (data + address) Nodes are
Uses of stacks? in non-consecutive memory
1. undo/redo features in text editors locations.
2. moving back/forward through browser history
Elements are linked using
3. backtracking algorithms (maze, file directories)
pointers.
4. calling functions (call stack)
Advantages? Big O Notation : “how code slows as
data grows.”
1. Dynamic Data Structure
( allocates needed memory while
running). 1. Describes the performance of an
2. Insertion and Deletion of Nodes algorithm as the amount of data
is easy. 0(1) increases.
3. No/Low memory waste. 2. Machine independent(# of steps
to completion)
Uses? 3. Ignore smaller operations 0(n+1)
1. Implements stacks/Queues -> 0(n)
2. GPS Navigation
3. Music Playlist

small data set: LinkedList = BAD


large data set + lots of searching:
LinkedList = BAD
large data set + lots of
inserting/deleting: LinkedList = GOOD

ArrayList : is a re-sizable array, also


called a dynamic array. It grows its size
to accommodate new elements and
shrinks the size when the elements
are removed. ArrayList internally uses
an array to store the elements.
Linear Search : Iterate through a collection
one element at a time.
Disadvantages :
 Slow for large data set
Advantages :
 fast for searches of small to medium
data sets
 does not need to sorted
 useful for data structures that do not
have random access (Linked List)

0(1) = constant time Binary Search : search algorithm that finds


the position of a target value within a
 Random access of an element in
sorted array. Half of the array is eliminated
an array
during each “step“.
 Inserting at the beginning of
linkedlist
0(log n) = logarithmic time
 Binary search
0(n) = linear time
 Looping through elements in an array
 Searching through a linkedlist
0(n log n) = quasilinear time
 Quicksort
 Mergesort
 Heapsort
0(n^2) = quadratic time
 Insertion sort
 Selection sort
 Bubblesort
0(n!) = factorial time
 Travelling salesman problem

You might also like