#2 Arrays, Linked Lists, Selection Sort
#2 Arrays, Linked Lists, Selection Sort
Lists, and
Selection Sort
Data Structures and Algorithms
Objectives:
Memory is used to
store information,
such as data and
programs, for
immediate use in a
computer.
Memory
Memory can be
compared to a set of
drawers. Each
drawer can hold one
item. If you need to
store 2 items, you’ll
need 2 drawers.
Memory
An array’s length is
the number of
elements stored in
that array.
Types of Arrays
An array can be
single dimensional
or multi-
dimensional
(sometimes called a
matrix)
Arrays in Memory
Similarly, adding
new items to the
array can be difficult
if the space in the
memory is limited.
Arrays in Memory
• Array – Insertion
Operation
• Array – Deletion
Operation
• Array – Search
Operation Hands-On Demo
Linked Lists
• Insertion at
Beginning, Ending,
and at Given Position
• Linked List Deletion
Hands-On Demo
Suppose you are making an app
for taking customer orders in a
restaurant. The app needs to
store a list of orders. Servers
keep adding orders to this list,
and chefs take orders off the list
and make them. Would you use
an array or linked list to
implement this order queue?
Practice Time
Selection Sort
Selection Sort
Selection sort is a
simple and efficient
sorting algorithm that
works by repeatedly
selecting the smallest (or
largest) element from the
unsorted portion of the
list and moving it to the
sorted portion of the list.
Selection Sort
The entire sorting algorithm will take O(n * n) time or O(n2) time.
Selection Sort
Algorithm
(tutorialspoint.com)
• Selection Sort
Implementation
Hands-On Demo
References