Lecture 5 Flashcards
What is List?
A list is a sequence of zero or more data items
Size can grow or shrink
Items can be accessed, inserted, or deleted at any position in a list
The total number of items is said to be the length of the list
What are the two types of Lists?
Array and LinkList
What is an Array?
An Array is a structure of fixed-size that can hold a collection of similar items
Elements are indexed (from 0)
Maintain insertion order of elements
What is an Arraylist?
ArrayList is a variable-length Collection class. They can increase or decrease the size dynamically
What is a Linked List?
Maintain the insertion order of elements
Elements are not indexed – when searching, start with the head and work your way through
O(n)
What is a Stack?
Its items are added and deleted on a last-in-first-out (LIFO) basis
To add an item to a stack, you push an item onto the top
To remove an item from the top you pop it
What are Queues?
Items inserted at one end (the rear)
Items deleted at the other end (the front)
A queue is a FIFO type data structure
The items are deleted in the same order as they were added
On a first-in-first-out basis
ENQUEUE (insertion)
DEQUEUE (deletion)
What are hash tables?
A Hash table or Hash Map is a data structure that maps a Key to a Value
A special function called a Hash Function performs this mapping
This function usually maps the key to an index in an array
Key and value could be any type of data structure!
How to implement Hash Tables
1) An initial set of space is allocated in the array
2) The hash function maps the key to an array index
3) The function should map within the array bounds
What is A collision in has tables?
Collision: Two things with different hash codes could be mapped to the same index
name 1 real ife application of Lists
Stacks
Queues
Hash Tables
Lists-Often used to implement other data structures e.g. queues and stacks
Stacks- reverse a string
Queues-printer queues
Hash Tables-address table
Examples of Graph data structure?
Road Maps
Relationships- Family trees
What is a Graph?
A graph is a collection of nodes (vertices) which
maybe connected in pairs by line segments called
edges
How do you define a Graph?
A graph G = (V,E) is composed of:
V: a set of vertices or nodes
E: a set of edges or lines connecting the vertices in V
An edge e=(u,v) is a connection between the vertices u and v
Define a binary Tree
A binary tree is a special type of tree where the maximum number of children is two
Trees are usually ordered from the top to the bottom and left to right
Trees are very fast to search
E.g. Binary search