Package Management
Package Arrangement

Keywords: Queue, Stack, Binary Tree (search, insert, delete, remove, balance)

Usage

See Problem Statement

Problem statements

  • L production lines
  • N packages
  • O Operations

Strategy

image

  • Production line
    • Binomial Max Heap
      • Doubly linked list
    • Deque
      • First-in-First out
      • Doubly Linked list ```julia struct int[] array int* next_array int* prev_array end ``` image
  • Peaking a production line
    • getFirst: O(1)
    • getLast: O(1)
    • getMax: O(1)
  • Operation
    • PopFirst: O(n)
    • PopLast: O(n)
    • PopMax: O(log n)
  • Merge Production line
    • Deque

Queue

Stack

Binary Tree Operation

What is a "balanced" binary tree?

Ref:

AVL Tree

Ref

Time complexity with AVL Tree

Operation Time
Search O(log n)
Insert O(log n)
Delete O(log n)
  • Advantage of using AVL Tree
    • Guarantee: O(log n) for binary search

Ref:

Idea

  • Merge 要求 log(n)

Hints

Heap Operations

Screen Shot 2021-05-08 at 12 03 07 PM Screen Shot 2021-05-08 at 12 03 30 PM Screen Shot 2021-05-08 at 12 03 41 PM Screen Shot 2021-05-08 at 12 03 52 PM Screen Shot 2021-05-08 at 12 04 14 PM

Free a binary tree

deallocate (node):
//do nothing if passed a non-existent node
if node is null
return
//now onto the recursion
deallocate(left node)
deallocate(right node)
free node

Ref: stackoverflow

Returning a void function

Ref: web

Function pointer

#include <stdio.h>
// A normal function with an int parameter
// and void return type
void fun(int a)
{
printf("Value of a is %d\n", a);
}
int main()
{
void (*fun_ptr)(int) = fun; // & removed
fun_ptr(10); // * removed
return 0;
}

Ref: GreekforGeek

Array of function pointers

int (*fun[3])(packData, int)= {PeekFirstPack, PeekLastPack, PeekMaxPack};
int PeekFirstPack(packData, int i)
Definition: list.c:152
int PeekLastPack(packData, int i)
Definition: list.c:173
Definition: list.h:60

What are Mutually Dependent Structures in C?

Leftist tree

Ref:

  1. https://tmt514.gitbooks.io/2016-09/content/tree-ds/leftist-tree.html
  2. http://sunmoon-template.blogspot.com/2014/12/leftist-tree.html
  3. https://www.humblec.com/c-implementation-leftist-tree/
  4. Tutorial: Leftist Tree

References

  1. Stack, Queue and Heap. [GitBook] 2.