1 of 18

Week 17

ACSL - Stacks / Queues

2 of 18

Announcement

  • Solutions for ACSL contest#2 are in #acsl-contests channel.

3 of 18

Homework

Level 1

Allen Wu

Lewis Huh

Mattias Kim

Ryan Tang

Jonathan Marx

Nathan Regan

Level 3

Katelyn Phung

Andy Luo

Michael Fine

Andy Blaha

Havish Singavarapu

Level 2

Ryan Chen

Hayden Jiang

Aanya Mathur

Daniel Choi

Jerry Wang

Lucas Xue

4 of 18

Data Structures

5 of 18

Bad programmers worry about the code. Good programmers worry about data structures and their relationships.

Linus Torvalds

6 of 18

Examples of data structures

  • Arrays / Lists
  • Map (a.k.a. Dictionary, Hash Table)
  • Linked List
  • Stacks
  • Queues
  • Trees (Binary Tree, Binary Search Tree, Trie, N-ary Tree, etc.)
  • Graphs
  • Heaps & Priority Queues

7 of 18

Stacks and Queues

8 of 18

Stack - LIFO (Last in - First Out)

Uses “PUSH” and “POP”

Push(element) will add element to

top of stack

Pop(X) will pop the top element from

the stack, and the element will be

stored as X in ACSL.

Commonly referred to as LIFO

9 of 18

Example Problem - Stack

Given an initially empty stack and the following sequence of operations, what would be the next POPPED element?

PUSH(O), PUSH(C), PUSH(E), POP(X), PUSH(A), PUSH(N), POP(X), POP(X), PUSH(S), PUSH(T), POP(X), PUSH(A), PUSH(T), PUSH(E), POP(X), POP( X)

10 of 18

Example Solution - Stack

Stack uses LIFO (Last in - First out), and is constructed as follows:

O, OC, OCE, OC, OCA, OCAN, OCA, OC, OCS, OCST, OCS, OCSA, OCSAT, OCSATE, OCSAT, OCSA. The next element popped is A.�

11 of 18

Queue - FIFO (First in - First out)

Also uses “PUSH” and “POP”

“Push” will add element to back of queue

“Pop” will pop the element at the front of

the queue, stored as X.

Referred to as FIFO, unlike stacks

12 of 18

Example Problem - Queue

Given an initially empty queue and the following sequence of operations, what would be the next POPPED element?

PUSH(O), PUSH(C), PUSH(E), POP(X), PUSH(A), PUSH(N), POP(X), POP(X), PUSH(H), PUSH(E), POP(X), PUSH(L), PUSH(L), PUSH(O), POP(X), POP(X)

13 of 18

Example Solution - Queue

Queue uses FIFO, and following FIFO rules, is constructed like this:

O, OC, OCE, CE, CEA, CEAN, EAN, AN, ANH, ANHE, NHE, NHEL, NHELL, NHELLO, HELLO, ELLO. The next item popped is E.

14 of 18

15 of 18

Kahoot

16 of 18

Tree

  • Binary Tree
    • Node
    • Parent node
    • Child node
    • Depth

17 of 18

ACSL Study materials

18 of 18

Before you go...

  • Graduation (Homework is required)
    • T-Shirts
    • Certificates
  • Please turn on your webcams during the breakout session
  • Virtual hangout hours: This Saturday from 10 am to 11 am via Zoom
    • Raise hands before joining. If no hands by 10 am on Saturday, it will be canceled.
    • Ask any questions related to club (Great opportunity to catch up!)
    • Hang out with club mates