Skip to content

Commit

Permalink
chore: Year2013 skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
MMZK1526 committed Jan 3, 2025
1 parent fe5d625 commit a2fbed8
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 0 deletions.
2 changes: 2 additions & 0 deletions doc-jan-haskell.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ extra-source-files:
library
exposed-modules:
Test,
Year2013.Exam,
Year2014.Exam,
Year2015.Exam,
Year2016.Exam,
Expand Down Expand Up @@ -53,6 +54,7 @@ test-suite test
main-is: Spec.hs
other-modules:
Test,
Year2013.Exam,
Year2014.Exam,
Year2015.Exam,
Year2016.Exam,
Expand Down
132 changes: 132 additions & 0 deletions src/Year2013/Exam.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
module Year2013.Exam where

type BinHeap a = [BinTree a]

data BinTree a = Node a Int (BinHeap a)
deriving (Eq, Ord, Show)

--------------------------------------------------------------
-- PART I

key :: BinTree a -> a
key
= undefined

rank :: BinTree a -> Int
rank
= undefined

children :: BinTree a -> [BinTree a]
children
= undefined

combineTrees :: Ord a => BinTree a -> BinTree a -> BinTree a
combineTrees
= undefined

--------------------------------------------------------------
-- PART II

extractMin :: Ord a => BinHeap a -> a
extractMin
= undefined

mergeHeaps :: Ord a => BinHeap a -> BinHeap a -> BinHeap a
mergeHeaps
= undefined

insert :: Ord a => a -> BinHeap a -> BinHeap a
insert
= undefined

deleteMin :: Ord a => BinHeap a -> BinHeap a
deleteMin
= undefined

remove :: Eq a => a -> BinHeap a -> BinHeap a
remove
= undefined

removeMin :: Ord a => BinHeap a -> (BinTree a, BinHeap a)
removeMin
= undefined

binSort :: Ord a => [a] -> [a]
binSort
= undefined

--------------------------------------------------------------
-- PART III

toBinary :: BinHeap a -> [Int]
toBinary
= undefined

binarySum :: [Int] -> [Int] -> [Int]
binarySum
= undefined

------------------------------------------------------
-- Some sample trees...

t1, t2, t3, t4, t5, t6, t7, t8 :: BinTree Int
-- Note: t7 is the result of merging t5 and t6

-- t1 to t4 appear in Figure 1...
t1 = Node 4 0 []
t2 = Node 1 1 [Node 5 0 []]
t3 = Node 2 2 [Node 8 1 [Node 9 0 []],
Node 7 0 []]
t4 = Node 2 3 [Node 3 2 [Node 6 1 [Node 8 0 []],
Node 10 0 []],
Node 8 1 [Node 9 0 []],
Node 7 0 []]

-- t5 and t6 are on the left of Figure 2; t7 is on the
-- right
t5 = Node 4 2 [Node 6 1 [Node 8 0 []],
Node 10 0 []]
t6 = Node 2 2 [Node 8 1 [Node 9 0 []], Node 7 0 []]
t7 = Node 2 3 [Node 4 2 [Node 6 1 [Node 8 0 []], Node 10 0 []],
Node 8 1 [Node 9 0 []],
Node 7 0 []]

-- An additional tree...
t8 = Node 12 1 [Node 16 0 []]

------------------------------------------------------
-- Some sample heaps...

h1, h2, h3, h4, h5, h6, h7 :: BinHeap Int
-- Two arbitrary heaps for testing...
h1 = [t2, t7]
h2 = [Node 1 2 [Node 12 1 [Node 16 0 []],
Node 5 0 []],
Node 2 3 [Node 4 2 [Node 6 1 [Node 8 0 []],
Node 10 0 []],
Node 8 1 [Node 9 0 []],
Node 7 0 []]]

-- h3 is shown in Figure 3...
h3 = [t1, t2, t4]

-- Two additional heaps, used below. They are shown
-- in Figure 4(a)...

h4 = [t2, t5]
h5 = [t1, t8]

-- h6 is the result of merging h4 and h5, shown in Figure 4(b)...
h6 = [Node 4 0 [],
Node 1 3 [Node 4 2 [Node 6 1 [Node 8 0 []],
Node 10 0 []],
Node 12 1 [Node 16 0 []],
Node 5 0 []]]

-- h7 is shown in Figure 5...
h7 = [Node 4 3 [Node 4 2 [Node 12 1 [Node 16 0 []],
Node 5 0 []],
Node 6 1 [Node 8 0 []],
Node 10 0 []]]


0 comments on commit a2fbed8

Please sign in to comment.