CT Wk 6: Linear Data Structures

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

What is a queue?

Queue is a data structure with FIFO (First In, First Out) or FCFS (First- Come-First-Served) property three operations: enqueue, dequeue, peek

Stack overflow

Can't use function call stack indefinitely because it is a recursion without any base case

What is the complexity of push/pull?

Depends on the code. if your push function adds new item to index 0, then you have to shift all items every time you add an item = O(n) otherwise its O(1) when push is O(1) then pop is O(n)

T/F: Both enqueue and dequeue can be made efficient and have low complexity

False. only one can be efficient because one of them have to shift all the elements to one side causing a O(n) complexity

Why do we use abstract data types?

It allows for functions to be used across all languages and systems, can easily switch. 1) Encapsulation: Abstract data types are usually for clients so they dont need to know the implementation 2) Localisation: Different implementations can be using the same program 3) Flexibility: Program does not change but implementation can, without affecting client

What are abstract data types?

Modeling data structures by what they do (operations), not how they do it (implementations)

What is a priority queue?

Same as a normal queue but does not follow FIFO. Each data element in a priority queue has a "priority" value: dequeue and peek will return the data element with the highest priority. priority based on what depends on the scenario

What is a stack?

Stack is a data structure with LIFO (Last In, First Out) property: The last item placed on the stack will be the first item removed. three operations: push, pop, peek

What are the main features and types of linear data structures?

Types: stack, queue, priority queue Features: only one data element is accessibly at any point of time don't need indices

What do enqueue, dequeue and peel operations do?

enqueue - Places a new data element to tail of the queue peek - Inspects the data element at the head of the queue without removing it dequeue - Removes the data element at the head of the queue

What is the complexity of enqueue, dequeue and peek?

enqueue adds item to the back so should be O(1) dequeue makes all items shift by 1, so O(n)

What does push, peek and pop operations do?

push - Places a new data element to the top of a stack peek - Inspects the data element on top of the stack without removing it (can only access one element) pop - Removes and retrieves the data element on top of the stack

How do you check if a list is a palindrome?

use pop and dequeue left should be equal to right

Applications of priority queue

✦ Personal to-do list. ✦ Patients' waiting list in a hospital emergency room. ✦ Special queues for express passes in a theme park. ✦ Scheduling computing jobs for your laptop's CPU.

What are the steps in using stacks to create a non recursive version of a recursion?

❖ Create a new stack. ❖ Push initial parameters onto a stack. ❖ Iterate till stack is empty: ‣ pop parameter from stack ‣ if base case: do not push any more parameter to the stack ‣ else (reduction step): push onto the stack the parameters that'd have been used in recursion note to push earlier function call later

What are some applications of stack?

❖Keyboard erase/backspace key ❖ Undo operation ❖ Recursion and backtracking (f1) calls f(2) which calls f(3). so f(3) is top of stack


Set pelajaran terkait

Chapter 6 Values, Ethics, and Advocacy

View Set

Chapter 11: Stress and Worker Well-Being (Quiz 4)

View Set

BUSN101 Ch.12 Dealing with Union and Employee-Management Issues

View Set

OMW Midterm (Protestant Reformation)

View Set