Slide 1

Slide 1 text

GETTING STARTED WITH DATA STRUCTURES Adora Nwodo

Slide 2

Slide 2 text

@adoranwodo Hi, I’m Adora! Software Engineer Author Digital Creator

Slide 3

Slide 3 text

A data structure is a particular way of organizing data in a computer so that it can be used effectively. @adoranwodo

Slide 4

Slide 4 text

@adoranwodo

Slide 5

Slide 5 text

@adoranwodo

Slide 6

Slide 6 text

Arrays Linked Lists Stacks Queues Binary Trees Binary Search Trees @adoranwodo Heaps Hash Tables Graphs Matrices Tries B-Trees N-ary Trees

Slide 7

Slide 7 text

Arrays @adoranwodo

Slide 8

Slide 8 text

An array is a finite collection of elements of the same type. @adoranwodo

Slide 9

Slide 9 text

★ Arrays are zero indexed. This means that an array with n elements is indexed from 0 to n-1. ★ An array has a fixed size. When creating an array, you specify the number of elements the array has. That’s it’s size. ★ Arrays are mutable. Meaning their state or data can be changed. @adoranwodo

Slide 10

Slide 10 text

var numbers = new int[] {12 , 8, 5, 78}; @adoranwodo 12 8 78 5 0 1 2 3

Slide 11

Slide 11 text

When we make an API request to fetch data, ife we are getting more than one record, they will usually be returned as a JSON array. When we get the valid JSON array as a response, we can perform whatever action we want on the data. @adoranwodo API RESPONSES REAL LIFE USES OF ARRAYS /* The example below shows looping through a valid API response and printing out the data */ var response = GetAllPendingTransactions(); foreach (var transaction in response) { Console.WriteLine(transaction.Id); Console.WriteLine(transaction.Description); }

Slide 12

Slide 12 text

Since 2 dimensional arrays are represented as rows & columns and matrices are also represented as rows and columns, we can represent matrices as 2 dimensional arrays while programming. Consider the 3x3 matrix below: 2 9 4 0 7 8 3 5 1 It’s equivalent 2d array representation will be: @adoranwodo REPRESENTING MATRICES REAL LIFE USES OF ARRAYS var matrix = new int[3, 3] { // Row 0 { 2 , 9, 4 }, // Row 1 { 0 , 7, 8 }, // Row 2 { 3 , 5, 1 }, }

Slide 13

Slide 13 text

Generally, arrays are used for storing all sorts of data ranging from data from a server, to data in the applications memory and so on. Depending on what your apps logic is, you might need to store a list of things at some point and arrays are one of the most common data structures that exist for this scenario. This data can exist: ★ In your applications memory ★ On a backend database ★ In a cache somewhere ★ In a file on a computer @adoranwodo STORING DATA REAL LIFE USES OF ARRAYS

Slide 14

Slide 14 text

Linked Lists @adoranwodo

Slide 15

Slide 15 text

A linked list is a data structure whose order of elements is not by their physical placement in memory. Instead, each element has a reference to the next element. @adoranwodo Element 1 Element 2 Element 3 NULL

Slide 16

Slide 16 text

Each element or node in a linked list has these fields. ❖ Data field: This field contains the data that is contained in the node. The programmer can store whatever data they want here, based on what their logic is. ❖ Reference field: This field contains the reference to the next (or previous) node in the sequence depending on the type of linked list. @adoranwodo 45 NODE B NODE A Data Next Ref 10 NODE C NODE B Data Next Ref 200 NODE C Data Next Ref

Slide 17

Slide 17 text

Types of Linked Lists The differences in Linked Lists are based on the multiple types of references possible: ❖ Singly Linked Lists ❖ Doubly Linked Lists ❖ Circular Linked Lists @adoranwodo

Slide 18

Slide 18 text

In a Singly Linked List, you are only allowed to have a “Next” reference. What this means is that you have one reference field that points to the next element in the sequence. @adoranwodo 45 10 200 NULL 45 NODE B NODE A Data Next Ref 10 NODE C NODE B Data Next Ref 200 NODE C Data Next Ref

Slide 19

Slide 19 text

In a Doubly Linked List, you are allowed to have two (double) references. One is a next reference and the other, a previous reference. What this means is that you have two reference fields where one points to the next element in the sequence and the other points to the previous element @adoranwodo 45 NODE B NODE A Data Next Reference 10 NODE C NODE B 200 NODE C 45 10 200 NULL Previous Reference NODE A Data Next Reference Previous Reference Data Next Reference Previous Reference NODE B

Slide 20

Slide 20 text

In a Circular Linked List, you are allowed to have two (double) references. One is a next reference and the other, a previous reference. What this means is that you have two reference fields where one points to the next element in the sequence and the other points to the previous element @adoranwodo 45 NODE B NODE A Data Next Reference 10 NODE C NODE B 200 NODE C 45 10 200 Previous Reference NODE A Data Next Reference Previous Reference Data Next Reference Previous Reference NODE B NODE C NODE A

Slide 21

Slide 21 text

Creating A Music Playlist With Linked Lists @adoranwodo

Slide 22

Slide 22 text

@adoranwodo

Slide 23

Slide 23 text

@adoranwodo

Slide 24

Slide 24 text

@adoranwodo

Slide 25

Slide 25 text

@adoranwodo

Slide 26

Slide 26 text

@adoranwodo

Slide 27

Slide 27 text

@adoranwodo

Slide 28

Slide 28 text

@adoranwodo

Slide 29

Slide 29 text

Hash Tables @adoranwodo

Slide 30

Slide 30 text

Hash Table is a data structure which stores data in an associative manner. In a hash table, data is stored in an array format, where each data value has its own unique index value. Access of data becomes very fast if we know the index of the desired data. @adoranwodo

Slide 31

Slide 31 text

What is Hashing? Hashing is a technique to convert a range of key values into a range of indexes of an array. @adoranwodo

Slide 32

Slide 32 text

What do you do when you don’t know the answer to an interview question? @adoranwodo

Slide 33

Slide 33 text

What do you do when you don’t know the answer to an interview question? USE A HASHMAP @adoranwodo

Slide 34

Slide 34 text

Stacks @adoranwodo

Slide 35

Slide 35 text

@adoranwodo

Slide 36

Slide 36 text

@adoranwodo

Slide 37

Slide 37 text

@adoranwodo

Slide 38

Slide 38 text

@adoranwodo

Slide 39

Slide 39 text

@adoranwodo

Slide 40

Slide 40 text

Stacks in real applications: ❖ Text editors ❖ String manipulation ❖ Browsers @adoranwodo

Slide 41

Slide 41 text

Queues @adoranwodo

Slide 42

Slide 42 text

Graphs, Tries and more. Next class? @adoranwodo

Slide 43

Slide 43 text

Questions? @adoranwodo