0

I want to implement the Viterbi algorithm for decoding convolutional codes. the algorithm is available here

Would it be better to implement it using 2D arrays or using linked lists in C programming language.

I am a newbie in C and would appreciate any help regarding which method would be better with the specific reasons.

Passer By
  • 19,325
  • 6
  • 49
  • 96
Christy
  • 17
  • 4

1 Answers1

1

It's be better to implement it using 2D array since you have to access random index with a constant time complexity of O(1). You can't access random index in linked lists with a constant time complexity of O(1).

Eklavya
  • 17,618
  • 4
  • 28
  • 57
  • Wrong. You don’t need to access random indices in the Viterbi algorithm. You calculate step n+1 from step n in the trellis, then walk backwards in the end to find out the Viterbi path (most likely path). – Tamás Zahola Sep 07 '18 at 09:47
  • Yes you can calculate n+1 step from step n then how can you access index of Weight and PreviousState without iterate for linked list ? – Eklavya Sep 07 '18 at 09:53
  • Of course, each _step_ in the trellis should be represented as a fixed-length array, but the trellis itself can be a linked list of such arrays. Of course in practice you would need a very long list to offset the performance penalty of allocations and pointer-chasing, but theoretically a linked list is perfectly valid. – Tamás Zahola Sep 07 '18 at 09:58
  • @TamásZahola What all would be the specific advantages of linked lists? Sorry, I am not very proficient with programming that is why I am requesting a more detailed answer. – Christy Sep 07 '18 at 10:18
  • @mathamity Since you are new to C (or C++) I suggest you start with the simplest. Which is the array-version, IMHO. Maybe you could plug in the linked lists later. – joop Sep 07 '18 at 10:29
  • @mathamity: linked lists have O(1) insertion (discounting allocation cost!). Arrays either have fixed size, or can be reallocated on-demand in which case they can achieve O(1) insertion *amortized*. Linked lists are not cache-friendly due to pointer-chasing, while arrays are contiguous so they’re cache friendly. If you know your code length beforehand, then use an array. – Tamás Zahola Sep 07 '18 at 10:31