Sorting Algorithms

  • Quick Sort
REPORT z_quick_sort_example.

TYPES: ty_value TYPE i,
       ty_data  TYPE TABLE OF ty_value WITH EMPTY KEY.

DATA: lt_data TYPE ty_data,
      lv_start TYPE i,
      lv_end   TYPE i.

* Sample data
lt_data = VALUE ty_data( ( 34 ) ( 7 ) ( 23 ) ( 32 ) ( 5 ) ( 62 ) ( 8 ) ( 13 ) ).

* Display original data
PERFORM display_data USING lt_data 'Original Data'.

* Quick Sort
lv_start = 1.
lv_end = LINES( lt_data ).
PERFORM quick_sort USING lt_data lv_start lv_end.

* Display sorted data
PERFORM display_data USING lt_data 'Sorted Data'.

*&---------------------------------------------------------------------*
*&      Form  QUICK_SORT
*&---------------------------------------------------------------------*
FORM quick_sort USING it_data TYPE ty_data
                        iv_start TYPE i
                        iv_end   TYPE i.

  DATA: lv_left  TYPE i,
        lv_right TYPE i,
        lv_temp  TYPE i,
        lv_pivot TYPE i.

  IF iv_start >= iv_end.
    RETURN.
  ENDIF.

  lv_left  = iv_start.
  lv_right = iv_end.
  lv_pivot = it_data[ iv_start ].

  WHILE lv_left <= lv_right.
    WHILE it_data[ lv_left ] < lv_pivot.
      lv_left = lv_left + 1.
    ENDWHILE.

    WHILE it_data[ lv_right ] > lv_pivot.
      lv_right = lv_right - 1.
    ENDWHILE.

    IF lv_left <= lv_right.
      lv_temp = it_data[ lv_left ].
      it_data[ lv_left ] = it_data[ lv_right ].
      it_data[ lv_right ] = lv_temp.

      lv_left = lv_left + 1.
      lv_right = lv_right - 1.
    ENDIF.
  ENDWHILE.

  PERFORM quick_sort USING it_data iv_start lv_right.
  PERFORM quick_sort USING it_data lv_left  iv_end.

ENDFORM.

*&---------------------------------------------------------------------*
*&      Form  DISPLAY_DATA
*&---------------------------------------------------------------------*
FORM display_data USING it_data TYPE ty_data
                         iv_title TYPE string.

  WRITE: / iv_title.
  LOOP AT it_data INTO DATA(lv_value).
    WRITE: / lv_value.
  ENDLOOP.
  WRITE: / ' '.
  
ENDFORM.


  • Merge Sort
  • Heap Sort

Searching Algorithms

  • Binary Search ✓
  • Depth-First Search (DFS) ✓
  • Breadth-First Search (BFS) ✓

Graph Algorithms

  • Dijkstra's Algorithm
  • Bellman-Ford Algorithm
  • Floyd-Warshall Algorithm

Dynamic Programming

  • Knapsack Problem
  • Longest Common Subsequence (LCS)
  • Coin Change Problem

Greedy Algorithms

  • Activity Selection Problem
  • Huffman Coding
  • Kruskal's and Prim's algorithms for Minimum Spanning Tree

Hashing

  • Implementation of Hash Maps
  • Collision Handling (Chaining and Open Addressing)

String Algorithms

  • KMP Algorithm for Pattern Matching
  • Rabin-Karp Algorithm
  • Trie Data Structure

Tree and Binary Tree Algorithms

  • Tree Traversals (Inorder, Preorder, Postorder)
  • Binary Search Tree operations (Insert, Delete, Search)
  • Lowest Common Ancestor (LCA)