Diese Präsentation wurde erfolgreich gemeldet.
Die SlideShare-Präsentation wird heruntergeladen. ×
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Nächste SlideShare
String matching algorithm
String matching algorithm
Wird geladen in …3
×

Hier ansehen

1 von 50 Anzeige

Weitere Verwandte Inhalte

Weitere von Emertxe Information Technologies Pvt Ltd (20)

Aktuellste (20)

Anzeige

09_nrps.pdf

  1. 1. Team Emertxe Strings and Storage Classes
  2. 2. Assignment 9
  3. 3. Assignment 9
  4. 4. Assignment 9 WAP to generate consecutive NRPS of length ‘n’ using ‘k’ distinct character
  5. 5. Assignment 9 WAP to generate consecutive NRPS of length ‘n’ using ‘k’ distinct character Input:
  6. 6. Assignment 9 WAP to generate consecutive NRPS of length ‘n’ using ‘k’ distinct character Input: Read Positive integers - number of characters ‘k’, length of the string ‘n’ and ‘k’ distinct characters.
  7. 7. Assignment 9 WAP to generate consecutive NRPS of length ‘n’ using ‘k’ distinct character Input: Read Positive integers - number of characters ‘k’, length of the string ‘n’ and ‘k’ distinct characters. Output:
  8. 8. Assignment 9 WAP to generate consecutive NRPS of length ‘n’ using ‘k’ distinct character Input: Read Positive integers - number of characters ‘k’, length of the string ‘n’ and ‘k’ distinct characters. Output: Print NRPS.
  9. 9. Assignment 9 What is NRPS?
  10. 10. Assignment 9 What is NRPS?  NRPS means Non-Repetitive Pattern String.
  11. 11. Assignment 9 What is NRPS?  NRPS means Non-Repetitive Pattern String.  Example: abcdabdc -> This string is formed using 4 distinct characters ‘a’, ‘b’, ‘c’ and ‘d’ of string length 8.  The pattern should not be repeated consecutively.
  12. 12. Assignment 9 How will you check the string is NRPS or not?
  13. 13. Assignment 9 How will you check the string is NRPS or not?  Example: abcdabdc -> This string is formed using 4 distinct characters ‘a’, ‘b’, ‘c’ and ‘d’ of string length 8.
  14. 14. Assignment 9 How will you check the string is NRPS or not?  Example: abcdabdc -> This string is formed using 4 distinct characters ‘a’, ‘b’, ‘c’ and ‘d’ of string length 8. a b c d a b d c 0 NRPS
  15. 15. Assignment 9 How will you check the string is NRPS or not?  Example: abcdabdc -> This string is formed using 4 distinct characters ‘a’, ‘b’, ‘c’ and ‘d’ of string length 8. a b c d a b d c 0 NRPS First pattern is formed using the characters a, b, c and d in order.
  16. 16. Assignment 9 How will you check the string is NRPS or not?  Example: abcdabdc -> This string is formed using 4 distinct characters ‘a’, ‘b’, ‘c’ and ‘d’ of string length 8. a b c d a b d c 0 NRPS Next pattern is formed by swapping some characters. The pattern should not be same as previous pattern.
  17. 17. Assignment 9 How will you check the string is NRPS or not?  Step 1: Make use of count variable. Initial value of count is 0. count = 0. a b c d a b d c 0 NRPS
  18. 18. Assignment 9 How will you check the string is NRPS or not?  Step 2: Start comparing the elements of first pattern and second pattern using their indices. a b c d a b d c 0 NRPS
  19. 19. Assignment 9 How will you check the string is NRPS or not?  Step 2: Start from ‘a’ from abcd and ‘a’ from abdc.  If, both are same, increment count by 1 a b c d a b d c 0 NRPS count = 1
  20. 20. Assignment 9 How will you check the string is NRPS or not?  Step 2: Then ‘b’ from abcd and ‘b’ from abdc.  If, both are same, increment count by 1 a b c d a b d c 0 NRPS count = 2
  21. 21. Assignment 9 How will you check the string is NRPS or not?  Step 2: Then ‘c’ from abcd and ‘d’ from abdc.  If, both are same, increment count by 1  If not, reset the count value to 0. a b c d a b d c 0 NRPS count = 0
  22. 22. Assignment 9 How will you check the string is NRPS or not?  Step 2: Then ‘d’ from abcd and ‘c’ from abdc.  If, both are same, increment count by 1  If not, reset the count value to 0. a b c d a b d c 0 NRPS count = 0
  23. 23. Assignment 9 How will you check the string is NRPS or not?  Step 3: Check the count value. • If the count value is 0, then the string is NRPS. • If the count value is other then 0, then the string is not NRPS. a b c d a b d c 0 NRPS count = 0
  24. 24. Assignment 9 How will you check the string is NRPS or not?  Step 3: Check the count value. • If the count value is 0, then the string is NRPS. • If the count value is other then 0, then the string is not NRPS. • Here, the count value is 0, so, abcdabdc is NRPS. a b c d a b d c 0 NRPS count = 0
  25. 25. Assignment 9 How to create a NRPS?
  26. 26. Assignment 9 How to create a NRPS?  Read how many distinct characters(k) are required to create NRPS from user. Assume ‘k’ = 3.  Read 3 distinct characters from user i.e., ‘a’, ‘b’ and ‘c’.  Read the length(n) of the string to be formed using ‘k’ distinct characters. n = 6.
  27. 27. Assignment 9 How to create a NRPS?  k = 3, n = 6 and characters are ‘a’, ‘b’ and ‘c’.  Step 1: Create the first pattern of characters in order. a b c NRPS
  28. 28. Assignment 9 How to create a NRPS?  k = 3, n = 6 and characters are ‘a’, ‘b’ and ‘c’.  Step2: Start creating the next pattern starting from index 1. a b c b NRPS
  29. 29. Assignment 9 How to create a NRPS?  k = 3, n = 6 and characters are ‘a’, ‘b’ and ‘c’.  Step2: Next index 2 can be copied to index 4. a b c b c NRPS
  30. 30. Assignment 9 How to create a NRPS?  k = 3, n = 6 and characters are ‘a’, ‘b’ and ‘c’.  Step2: When you reach end of the first pattern, start from the beginning again. a b c b c a NRPS
  31. 31. Assignment 9 How to create a NRPS?  k = 3, n = 6 and characters are ‘a’, ‘b’ and ‘c’. a b c b c a 0 NRPS
  32. 32. Assignment 9 How to create a NRPS?  Read how many distinct characters(k) are required to create NRPS from user. Assume ‘k’ = 3.  Read 3 distinct characters from user i.e., ‘a’, ‘b’ and ‘c’.  Read the length(n) of the string to be formed using ‘k’ distinct characters. n = 9.
  33. 33. Assignment 9 How to create a NRPS?  k = 3, n = 9 and characters are ‘a’, ‘b’ and ‘c’.  Step 1: Create the first pattern of characters in order. a b c NRPS
  34. 34. Assignment 9 How to create a NRPS?  k = 3, n = 9 and characters are ‘a’, ‘b’ and ‘c’.  Step2: Start creating the next pattern starting from index 1. NRPS a b c b
  35. 35. Assignment 9 How to create a NRPS?  k = 3, n = 9 and characters are ‘a’, ‘b’ and ‘c’.  Step2: Next index 2 can be copied to index 4. NRPS a b c b c
  36. 36. Assignment 9 How to create a NRPS?  k = 3, n = 9 and characters are ‘a’, ‘b’ and ‘c’.  Step2: When you reach end of the first pattern, start from the beginning again. NRPS a b c b c a
  37. 37. Assignment 9 How to create a NRPS?  k = 3, n = 9 and characters are ‘a’, ‘b’ and ‘c’.  Step1: Repeat the process to create next pattern till length ‘n’. NRPS a b c b c a c
  38. 38. Assignment 9 How to create a NRPS?  k = 3, n = 9 and characters are ‘a’, ‘b’ and ‘c’.  Step1: Repeat the process to create next pattern till length ‘n’. NRPS a b c b c a c a
  39. 39. Assignment 9 How to create a NRPS?  k = 3, n = 9 and characters are ‘a’, ‘b’ and ‘c’.  Step1: Repeat the process to create next pattern till length ‘n’. NRPS a b c b c a c a b
  40. 40. Assignment 9 How to create a NRPS?  k = 3, n = 8 and characters are ‘a’, ‘b’ and ‘c’. NRPS a b c b c a c a b 0
  41. 41. Assignment 9 Sample execution:-
  42. 42. Assignment 9 Sample execution:-
  43. 43. Assignment 9 Sample execution:-
  44. 44. Assignment 9 Pre-requisites:-
  45. 45. Assignment 9 Pre-requisites:- ⮚Strings
  46. 46. Assignment 9 Pre-requisites:- ⮚Strings ⮚Arrays
  47. 47. Assignment 9 Pre-requisites:- ⮚Strings ⮚Arrays ⮚Pointers
  48. 48. Assignment 9 Pre-requisites:- ⮚Strings ⮚Arrays ⮚Pointers Objective:-
  49. 49. Assignment 9 Pre-requisites:- ⮚Strings ⮚Arrays ⮚Pointers Objective:- To understand the concept of String manipulation
  50. 50. Team Emertxe Thank you

×